EFIngresProvider/SqlGen/SqlGenerator.cs
/// <summary>
/// Translate a command tree to a SQL string.
///
/// The input tree could be translated to either a SQL SELECT statement
/// or a SELECT expression.  This choice is made based on the return type
/// of the expression
/// CollectionType => select statement
/// non collection type => select expression
/// </summary>
/// <param name="tree"></param>
/// <returns>The string representing the SQL to be executed.</returns>
Translate a command tree to a SQL string.

The input tree could be translated to either a SQL SELECT statement
or a SELECT expression.  This choice is made based on the return type
of the expression
CollectionType => select statement
non collection type => select expression
Translate a command tree to a SQL string . The input tree could be translated to either a SQL SELECT statement or a SELECT expression . This choice is made based on the return type of the expression CollectionType = > select statement non collection type = > select expression
private string GenerateSql(DbQueryCommandTree tree)
        {
            DbExpression targetExpression = tree.Query;
            selectStatementStack = new Stack<SqlSelectStatement>();
            isParentAJoinStack = new Stack<bool>();
            allExtentNames = new Dictionary<string, int>(StringComparer.OrdinalIgnoreCase);
            allColumnNames = new Dictionary<string, int>(StringComparer.OrdinalIgnoreCase);
            ISqlFragment result;
            if (MetadataHelpers.IsCollectionType(targetExpression.ResultType))
            {
                SqlSelectStatement sqlStatement = VisitExpressionEnsureSqlStatement(targetExpression);
                Debug.Assert(sqlStatement != null, "The outer most sql statment is null");
                sqlStatement.IsTopMost = true;
                result = sqlStatement;
            }
            else
            {
                SqlBuilder sqlBuilder = new SqlBuilder();
                sqlBuilder.Append("SELECT ");
                sqlBuilder.Append(targetExpression.Accept(this));
                result = sqlBuilder;
            }
            if (isVarRefSingle)
            {
                throw new NotSupportedException();
            }
            Debug.Assert(selectStatementStack.Count == 0);
            Debug.Assert(isParentAJoinStack.Count == 0);
            return WriteSql(result);
        }
private string GenerateSql ( DbQueryCommandTree tree ) { DbExpression targetExpression = tree . Query ; selectStatementStack = new Stack < SqlSelectStatement > ( ) ; isParentAJoinStack = new Stack < bool > ( ) ; allExtentNames = new Dictionary < string , int > ( StringComparer . OrdinalIgnoreCase ) ; allColumnNames = new Dictionary < string , int > ( StringComparer . OrdinalIgnoreCase ) ; ISqlFragment result ; if ( MetadataHelpers . IsCollectionType ( targetExpression . ResultType ) ) { SqlSelectStatement sqlStatement = VisitExpressionEnsureSqlStatement ( targetExpression ) ; Debug . Assert ( sqlStatement != null , " " ) ; sqlStatement . IsTopMost = true ; result = sqlStatement ; } else { SqlBuilder sqlBuilder = new SqlBuilder ( ) ; sqlBuilder . Append ( " " ) ; sqlBuilder . Append ( targetExpression . Accept ( this ) ) ; result = sqlBuilder ; } if ( isVarRefSingle ) { throw new NotSupportedException ( ) ; } Debug . Assert ( selectStatementStack . Count == 0 ) ; Debug . Assert ( isParentAJoinStack . Count == 0 ) ; return WriteSql ( result ) ; }
Translate a command tree to a SQL string.
Translate a command tree to a SQL string .
// Literals will not be converted to parameters. // A DbVariableReferenceExpression has to be a child of DbPropertyExpression or MethodExpression // Check that the parameter stacks are not leaking.
The string representing the SQL to be executed.
The string representing the SQL to be executed .
tree
DbQueryCommandTree
None