src/Shared/EntityFramework.SqlServer/SqlGen/Sql8ExpressionRewriter.cs
// <summary>
// Helper method for
// <see
//     cref="TransformIntersectOrExcept(DbExpression, DbExpression, DbExpressionKind, System.Collections.Generic.IList{System.Data.Entity.Core.Common.CommandTrees.DbPropertyExpression}, string)" />
// Creates a
// <see cref="DbProjectExpression" />
// over the given inputBinding that projects out the given flattenedProperties.
// and updates the flattenedProperties to be over the newly created project.
// </summary>
// <returns>
// An <see cref="DbExpressionBinding" /> over the newly created <see cref="DbProjectExpression" />
// </returns>
Helper method for

Creates a

over the given inputBinding that projects out the given flattenedProperties.
and updates the flattenedProperties to be over the newly created project.
Helper method for Creates a over the given inputBinding that projects out the given flattenedProperties . and updates the flattenedProperties to be over the newly created project .
private static DbExpressionBinding CapWithProject(DbExpressionBinding inputBinding, IList<DbPropertyExpression> flattenedProperties)
        {
            var projectColumns = new List<KeyValuePair<string, DbExpression>>(flattenedProperties.Count);
            var columnNames = new Dictionary<string, int>(flattenedProperties.Count);
            foreach (var pe in flattenedProperties)
            {
                var name = pe.Property.Name;
                int i;
                if (columnNames.TryGetValue(name, out i))
                {
                    string newName;
                    do
                    {
                        ++i;
                        newName = name + i.ToString(CultureInfo.InvariantCulture);
                    }
                    while (columnNames.ContainsKey(newName));
                    columnNames[name] = i;
                    name = newName;
                }
                columnNames[name] = 0;
                projectColumns.Add(new KeyValuePair<string, DbExpression>(name, pe));
            }
            DbExpression rowExpr = DbExpressionBuilder.NewRow(projectColumns);
            var projectExpression = inputBinding.Project(rowExpr);
            var resultBinding = projectExpression.Bind();
            flattenedProperties.Clear();
            var rowExprType = (RowType)rowExpr.ResultType.EdmType;
            foreach (var column in projectColumns)
            {
                var prop = rowExprType.Properties[column.Key];
                flattenedProperties.Add(resultBinding.Variable.Property(prop));
            }
            return resultBinding;
        }
private static DbExpressionBinding CapWithProject ( DbExpressionBinding inputBinding , IList < DbPropertyExpression > flattenedProperties ) { var projectColumns = new List < KeyValuePair < string , DbExpression > > ( flattenedProperties . Count ) ; var columnNames = new Dictionary < string , int > ( flattenedProperties . Count ) ; foreach ( var pe in flattenedProperties ) { var name = pe . Property . Name ; int i ; if ( columnNames . TryGetValue ( name , out i ) ) { string newName ; do { ++ i ; newName = name + i . ToString ( CultureInfo . InvariantCulture ) ; } while ( columnNames . ContainsKey ( newName ) ) ; columnNames [ name ] = i ; name = newName ; } columnNames [ name ] = 0 ; projectColumns . Add ( new KeyValuePair < string , DbExpression > ( name , pe ) ) ; } DbExpression rowExpr = DbExpressionBuilder . NewRow ( projectColumns ) ; var projectExpression = inputBinding . Project ( rowExpr ) ; var resultBinding = projectExpression . Bind ( ) ; flattenedProperties . Clear ( ) ; var rowExprType = ( RowType ) rowExpr . ResultType . EdmType ; foreach ( var column in projectColumns ) { var prop = rowExprType . Properties [ column . Key ] ; flattenedProperties . Add ( resultBinding . Variable . Property ( prop ) ) ; } return resultBinding ; }
Helper method for
Helper method for
//List of all the columnNames used in the projection. //There may be conflicting property names, thus we may need to rename. // Add this column name to list of known names so that there are no subsequent // collisions //Build the project //Create the new inputBinding //Create the list of flattenedProperties over the new project
An  over the newly created
An over the newly created
inputBinding
DbExpressionBinding
flattenedProperties
IList<DbPropertyExpression>