System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.NormalizeSetSource C# (CSharp) Method

NormalizeSetSource() private method

private NormalizeSetSource ( DbExpression input ) : DbExpression
input DbExpression
return DbExpression
        private DbExpression NormalizeSetSource(DbExpression input)
        {
            DebugCheck.NotNull(input);

            // If input looks like "select x from (...) as x", rewrite it as "(...)".
            // If input has span information attached to to it then leave it as is, otherwise 
            // span info will be lost.
            Span span;
            if (input.ExpressionKind == DbExpressionKind.Project
                && !TryGetSpan(input, out span))
            {
                var project = (DbProjectExpression)input;
                if (project.Projection
                    == project.Input.Variable)
                {
                    input = project.Input.Expression;
                }
            }

            // determine if the lambda input is an IGrouping or EntityCollection that needs to be unwrapped
            InitializerMetadata initializerMetadata;
            if (InitializerMetadata.TryGetInitializerMetadata(input.ResultType, out initializerMetadata))
            {
                if (initializerMetadata.Kind
                    == InitializerMetadataKind.Grouping)
                {
                    // for group by, redirect the binding to the group (rather than the property)
                    input = input.Property(GroupColumnName);
                }
                else if (initializerMetadata.Kind
                         == InitializerMetadataKind.EntityCollection)
                {
                    // for entity collection, redirect the binding to the children
                    input = input.Property(EntityCollectionElementsColumnName);
                }
            }
            return input;
        }