Exemplo n.º 1
0
        protected virtual Expression VisitBatch(DbBatchExpression batch)
        {
            var operation = this.Visit(batch.Operation) as LambdaExpression;
            var batchSize = this.Visit(batch.BatchSize);
            var stream    = this.Visit(batch.Stream);

            return(this.UpdateBatch(batch, batch.Input, operation, batchSize, stream));
        }
Exemplo n.º 2
0
        protected virtual Expression BuildExecuteBatch(DbBatchExpression batch)
        {
            var operation   = this.Parameterize(batch.Operation.Body);
            var commandText = this.linguist.Format(operation);
            var namedValues = DbNamedValueGatherer.Gather(operation);
            var command     = new QueryCommand(commandText, namedValues.Select(v => new QueryParameter(v.Name, v.Type, v.QueryType)));
            var values      = namedValues.Select(v => Expression.Convert(this.Visit(v.Value), typeof(object))).ToArray() as Expression[];

            var paramSets = Expression.Call
                            (
                typeof(Enumerable), nameof(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] })
                            );

            var plan       = null as Expression;
            var projection = ProjectionFinder.FindProjection(operation);

            if (projection != null)
            {
                var saveScope = this.scope;
                var reader    = Expression.Parameter(typeof(FieldReader), "r" + nReaders++);

                this.scope = new Scope(this.scope, reader, projection.Select.Alias, projection.Select.Columns);

                var projector = Expression.Lambda(this.Visit(projection.Projector), reader);

                this.scope = saveScope;

                var entity = EntityFinder.Find(projection.Projector);

                command = new QueryCommand(command.CommandText, command.Parameters);

                plan = Expression.Call
                       (
                    this.executor, nameof(QueryExecutor.ExecuteBatch), new Type[] { projector.Body.Type },
                    Expression.Constant(command),
                    paramSets,
                    projector,
                    Expression.Constant(entity, typeof(MappingEntity)),
                    batch.BatchSize,
                    batch.Stream
                       );
            }
            else
            {
                plan = Expression.Call
                       (
                    this.executor, nameof(QueryExecutor.ExecuteBatch), null,
                    Expression.Constant(command),
                    paramSets,
                    batch.BatchSize,
                    batch.Stream
                       );
            }

            return(plan);
        }
Exemplo n.º 3
0
        protected DbBatchExpression UpdateBatch(DbBatchExpression batch, Expression input, LambdaExpression operation, Expression batchSize, Expression stream)
        {
            if (input != batch.Input || operation != batch.Operation || batchSize != batch.BatchSize || stream != batch.Stream)
            {
                return(new DbBatchExpression(input, operation, batchSize, stream));
            }

            return(batch);
        }
 protected virtual bool CompareBatch(DbBatchExpression x, DbBatchExpression y)
 {
     return
         (
         this.Compare(x.Input, y.Input) &&
         this.Compare(x.Operation, y.Operation) &&
         this.Compare(x.BatchSize, y.BatchSize) &&
         this.Compare(x.Stream, y.Stream)
         );
 }
Exemplo n.º 5
0
        protected override Expression VisitBatch(DbBatchExpression batch)
        {
            if (this.linguist.Language.AllowsMultipleCommands || !IsMultipleCommands(batch.Operation.Body as DbCommandExpression))
            {
                return(this.BuildExecuteBatch(batch));
            }

            var source = this.Visit(batch.Input);
            var op     = this.Visit(batch.Operation.Body);
            var fn     = Expression.Lambda(op, batch.Operation.Parameters[1]);

            return(Expression.Call(typeof(DbExecutionBuilder), nameof(DbExecutionBuilder.Batch), new Type[] { TypeHelper.GetElementType(source.Type), batch.Operation.Body.Type }, source, fn, batch.Stream));
        }
Exemplo n.º 6
0
        protected virtual Expression VisitBatch(DbBatchExpression batch)
        {
            this.Write("Batch(");
            this.WriteLine(Indentation.Inner);
            this.Visit(batch.Input);
            this.Write(",");
            this.WriteLine(Indentation.Same);
            this.Visit(batch.Operation);
            this.Write(",");
            this.WriteLine(Indentation.Same);
            this.Visit(batch.BatchSize);
            this.Write(", ");
            this.Visit(batch.Stream);
            this.WriteLine(Indentation.Outer);
            this.Write(")");

            return(batch);
        }