public override void VisitQueryModel (QueryModel queryModel)
{
var constantCollection = GetConstantCollectionValue (queryModel);
if (constantCollection != null)
{
// If the query is a constant collection, transform it to a trivial SqlStatement with only a select projection. In the SQL generation, this
// will become something like (1, 2, 3, 4) - used primarily for IN expressions.
// In this specific case, the select projection is not named because such a list of values cannot be named in SQL.
SqlStatementBuilder.SelectProjection = Expression.Constant (constantCollection);
SqlStatementBuilder.DataInfo = queryModel.SelectClause.GetOutputDataInfo ();
VisitResultOperators (queryModel.ResultOperators, queryModel);
}
else
{
base.VisitQueryModel (queryModel);
}
// Always name the select projection - null indicates the default name that will later be removed if the inner expression already has a name.
// The name is required to be able to access the result from the executed SQL afterwards. The resolution stage will consolidate names around
// NewExpressions, entities, more than one name, etc.
SqlStatementBuilder.SelectProjection = new NamedExpression (null, SqlStatementBuilder.SelectProjection);
// We get the DataInfo incrementally when we handle the SelectClause and ResultOperators, so we need to manually adjust the data type if
// required. (We can't simply call queryModel.GetOutputDataInfo() because some of the result operator handlers might have changed the
// SqlStatementBuilder.DataInfo.)
if (queryModel.ResultTypeOverride != null)
SqlStatementBuilder.DataInfo = SqlStatementBuilder.DataInfo.AdjustDataType (queryModel.ResultTypeOverride);
}