예제 #1
0
 protected BatchExpression UpdateBatch(BatchExpression batch, Expression input, LambdaExpression operation, Expression batchSize, Expression stream)
 {
     if (input != batch.Input || operation != batch.Operation || batchSize != batch.BatchSize || stream != batch.Stream)
     {
         return(new BatchExpression(input, operation, batchSize, stream));
     }
     return(batch);
 }
예제 #2
0
        protected virtual Expression VisitBatch(BatchExpression batch)
        {
            var        operation = (LambdaExpression)Visit(batch.Operation);
            Expression batchSize = Visit(batch.BatchSize);
            Expression stream    = Visit(batch.Stream);

            return(UpdateBatch(batch, batch.Input, operation, batchSize, stream));
        }
예제 #3
0
 protected override Expression VisitBatch(BatchExpression batch)
 {
     if (linguist.Language.AllowsMultipleCommands || !IsMultipleCommands(batch.Operation.Body as CommandExpression))
     {
         return(BuildExecuteBatch(batch));
     }
     else
     {
         Expression       source = Visit(batch.Input);
         Expression       op     = Visit(batch.Operation.Body);
         LambdaExpression fn     = Expression.Lambda(op, batch.Operation.Parameters[1]);
         return(Expression.Call(GetType(), "Batch", new[] { TypeHelper.GetElementType(source.Type), batch.Operation.Body.Type }, source, fn, batch.Stream));
     }
 }
예제 #4
0
 protected virtual Expression VisitBatch(BatchExpression batch)
 {
     Write("Batch(");
     WriteLine(Indentation.Inner);
     Visit(batch.Input);
     Write(",");
     WriteLine(Indentation.Same);
     Visit(batch.Operation);
     Write(",");
     WriteLine(Indentation.Same);
     Visit(batch.BatchSize);
     Write(", ");
     Visit(batch.Stream);
     WriteLine(Indentation.Outer);
     Write(")");
     return(batch);
 }
예제 #5
0
        protected virtual Expression BuildExecuteBatch(BatchExpression batch)
        {
            // parameterize query
            Expression operation = Parameterize(batch.Operation.Body);

            string commandText = linguist.Format(operation);
            ReadOnlyCollection <NamedValueExpression> namedValues = NamedValueGatherer.Gather(operation);
            var command = new QueryCommand(commandText, namedValues.Select(v => new QueryParameter(v.Name, v.Type, v.QueryType)));

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

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

            Expression plan = null;

            ProjectionExpression projection = ProjectionFinder.FindProjection(operation);

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

                EntryMapping entity = EntityFinder.Find(projection.Projector);
                command = new QueryCommand(command.CommandText, command.Parameters);

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

            return(plan);
        }
예제 #6
0
 protected virtual bool CompareBatch(BatchExpression x, BatchExpression y)
 {
     return(Compare(x.Input, y.Input) && Compare(x.Operation, y.Operation) && Compare(x.BatchSize, y.BatchSize) && Compare(x.Stream, y.Stream));
 }