示例#1
0
            internal static IEnumerable <ColumnExpression> Gather(Expression expression)
            {
                var gatherer = new ColumnGatherer();

                gatherer.Visit(expression);
                return(gatherer.columns.Values);
            }
示例#2
0
        protected virtual Expression BuildExecuteBatch(BatchExpression batch)
        {
            // parameterize query
            Expression operation = this.Parameterize(batch.Operation.Body);

            string       commandText = this.mapping.Language.Format(operation);
            var          namedValues = NamedValueGatherer.Gather(operation);
            QueryCommand command     = new QueryCommand(commandText, namedValues.Select(v => new QueryParameter(v.Name, v.Type, v.DbType)), null);

            Expression[] values = namedValues.Select(v => Expression.Convert(this.Visit(v.Value), typeof(object))).ToArray();

            Expression paramSets = Expression.Call(typeof(Enumerable), "Select", new Type[] { batch.Operation.Parameters[1].Type, typeof(object[]) },
                                                   batch.Input,
                                                   Expression.Lambda(Expression.NewArrayInit(typeof(object), values), new[] { batch.Operation.Parameters[1] })
                                                   );

            Expression plan = null;

            DbProjectionExpression projection = ProjectionFinder.FindProjection(operation);

            if (projection != null)
            {
                var saveScope = this.scope;
                ParameterExpression reader = Expression.Parameter(typeof(IDataReader), "r" + nReaders++);
                this.scope = new Scope(this.scope, reader, projection.Select.Alias, projection.Select.Columns);
                LambdaExpression projector = Expression.Lambda(this.Visit(projection.Projector), reader);
                this.scope = saveScope;

                var columns = ColumnGatherer.Gather(projection.Projector);
                command = new QueryCommand(command.CommandText, command.Parameters, columns);

                plan = Expression.Call(this.provider, "ExecuteBatch", new Type[] { projector.Body.Type },
                                       Expression.Constant(command),
                                       paramSets,
                                       projector,
                                       batch.Size,
                                       batch.Stream
                                       );
            }
            else
            {
                plan = Expression.Call(this.provider, "ExecuteBatch", null,
                                       Expression.Constant(command),
                                       paramSets,
                                       batch.Size,
                                       batch.Stream
                                       );
            }

            return(plan);
        }
示例#3
0
        protected override Expression VisitMarker(MarkerExpression expression)
        {
            var target          = expression.Target;
            var processedTarget = Visit(target);

            if (expression.MarkerType != MarkerType.None && (expression.MarkerType & MarkerType.Default) == MarkerType.None)
            {
                if (itemMaterializationContextParameter == null)
                {
                    return(processedTarget);
                }
                var columns        = ColumnGatherer.GetColumns(target, ColumnExtractionModes.Distinct | ColumnExtractionModes.Ordered).ToArray();
                var sequenceCheck  = Expression.Call(MaterializationHelper.IsNullMethodInfo, tupleParameter, Expression.Constant(columns));
                var throwException = Expression.Convert(Expression.Call(MaterializationHelper.ThrowEmptySequenceExceptionMethodInfo), target.Type);
                return(Expression.Condition(sequenceCheck, throwException, processedTarget));
            }
            return(processedTarget);
        }
 public List <Pair <int, Expression> > GetColumnsAndExpressions(ColumnExtractionModes columnExtractionModes)
 {
     return(ColumnGatherer.GetColumnsAndExpressions(Item, columnExtractionModes));
 }
 public List <int> GetColumns(ColumnExtractionModes columnExtractionModes)
 {
     return(ColumnGatherer.GetColumns(Item, columnExtractionModes));
 }
 public List <int> GetColumns(ColumnExtractionModes columnExtractionModes) =>
 ColumnGatherer.GetColumns(Item, columnExtractionModes);
示例#7
0
 internal static IEnumerable<ColumnExpression> Gather(Expression expression)
 {
     var gatherer = new ColumnGatherer();
     gatherer.Visit(expression);
     return gatherer.columns.Values;
 }