EFIngresProvider/SqlGen/SqlGenerator/SqlGeneratorCommonVisitors.cs
/// <summary>
/// This is called from <see cref="GenerateSql(DbQueryCommandTree)"/> and nodes which require a
/// select statement as an argument e.g. <see cref="Visit(DbIsEmptyExpression)"/>,
/// <see cref="Visit(DbUnionAllExpression)"/>.
///
/// SqlGenerator needs its child to have a proper alias if the child is
/// just an extent or a join.
///
/// The normal relational nodes result in complete valid SQL statements.
/// For the rest, we need to treat them as there was a dummy
/// <code>
/// -- originally {expression}
/// -- change that to
/// SELECT *
/// FROM {expression} as c
/// </code>
/// 
/// DbLimitExpression needs to start the statement but not add the default columns
/// </summary>
/// <param name="e"></param>
/// <param name="addDefaultColumns"></param>
/// <returns></returns>
This is called from  and nodes which require a
select statement as an argument e.g.

SqlGenerator needs its child to have a proper alias if the child is
just an extent or a join.

The normal relational nodes result in complete valid SQL statements.
For the rest, we need to treat them as there was a dummy

originally {expression}
change that to
SELECT
FROM {expression} as c
This is called from and nodes which require a select statement as an argument e . g . SqlGenerator needs its child to have a proper alias if the child is just an extent or a join . The normal relational nodes result in complete valid SQL statements . For the rest we need to treat them as there was a dummy originally { expression } change that to SELECT FROM { expression } as c
private SqlSelectStatement VisitExpressionEnsureSqlStatement(DbExpression e, bool addDefaultColumns)
        {
            Debug.Assert(MetadataHelpers.IsCollectionType(e.ResultType.EdmType));
            SqlSelectStatement result;
            switch (e.ExpressionKind)
            {
                case DbExpressionKind.Project:
                case DbExpressionKind.Filter:
                case DbExpressionKind.GroupBy:
                case DbExpressionKind.Sort:
                    result = e.Accept(this) as SqlSelectStatement;
                    break;
                default:
                    string inputVarName = "c";  
                    symbolTable.EnterScope();
                    TypeUsage type = null;
                    switch (e.ExpressionKind)
                    {
                        case DbExpressionKind.Scan:
                        case DbExpressionKind.CrossJoin:
                        case DbExpressionKind.FullOuterJoin:
                        case DbExpressionKind.InnerJoin:
                        case DbExpressionKind.LeftOuterJoin:
                        case DbExpressionKind.CrossApply:
                        case DbExpressionKind.OuterApply:
                            type = MetadataHelpers.GetElementTypeUsage(e.ResultType);
                            break;
                        default:
                            Debug.Assert(MetadataHelpers.IsCollectionType(e.ResultType.EdmType));
                            type = MetadataHelpers.GetEdmType<CollectionType>(e.ResultType).TypeUsage;
                            break;
                    }
                    Symbol fromSymbol;
                    result = VisitInputExpression(e, inputVarName, type, out fromSymbol);
                    AddFromSymbol(result, inputVarName, fromSymbol);
                    symbolTable.ExitScope();
                    break;
            }
            if (addDefaultColumns && result.Select.IsEmpty)
            {
                AddDefaultColumns(result);
            }
            return result;
        }
private SqlSelectStatement VisitExpressionEnsureSqlStatement ( DbExpression e , bool addDefaultColumns ) { Debug . Assert ( MetadataHelpers . IsCollectionType ( e . ResultType . EdmType ) ) ; SqlSelectStatement result ; switch ( e . ExpressionKind ) { case DbExpressionKind . Project : case DbExpressionKind . Filter : case DbExpressionKind . GroupBy : case DbExpressionKind . Sort : result = e . Accept ( this ) as SqlSelectStatement ; break ; default : string inputVarName = " " ; symbolTable . EnterScope ( ) ; TypeUsage type = null ; switch ( e . ExpressionKind ) { case DbExpressionKind . Scan : case DbExpressionKind . CrossJoin : case DbExpressionKind . FullOuterJoin : case DbExpressionKind . InnerJoin : case DbExpressionKind . LeftOuterJoin : case DbExpressionKind . CrossApply : case DbExpressionKind . OuterApply : type = MetadataHelpers . GetElementTypeUsage ( e . ResultType ) ; break ; default : Debug . Assert ( MetadataHelpers . IsCollectionType ( e . ResultType . EdmType ) ) ; type = MetadataHelpers . GetEdmType < CollectionType > ( e . ResultType ) . TypeUsage ; break ; } Symbol fromSymbol ; result = VisitInputExpression ( e , inputVarName , type , out fromSymbol ) ; AddFromSymbol ( result , inputVarName , fromSymbol ) ; symbolTable . ExitScope ( ) ; break ; } if ( addDefaultColumns && result . Select . IsEmpty ) { AddDefaultColumns ( result ) ; } return result ; }
This is called from  and nodes which require a
select statement as an argument e.g.
This is called from and nodes which require a select statement as an argument e . g .
// any name will do - this is my random choice. // It used to be type = e.ResultType. 
None
e
DbExpression
None
addDefaultColumns
bool
None