protected virtual Expression BuildExecuteBatch(BatchExpression batch) { Expression expression = this.Parameterize(batch.Operation.Body); string commandText = this.linguist.Format(expression); ReadOnlyCollection <NamedValueExpression> onlys = NamedValueGatherer.Gather(expression); QueryCommand command = new QueryCommand(commandText, from v in onlys select new QueryParameter(v.Name, v.Type, v.QueryType)); Expression[] initializers = (from v in onlys select Expression.Convert(this.Visit(v.Value), typeof(object))).ToArray <UnaryExpression>(); Expression expression2 = Expression.Call(typeof(Enumerable), "Select", new Type[] { batch.Operation.Parameters[1].Type, typeof(object[]) }, new Expression[] { batch.Input, Expression.Lambda(Expression.NewArrayInit(typeof(object), initializers), new ParameterExpression[] { batch.Operation.Parameters[1] }) }); ProjectionExpression expression4 = ProjectionFinder.FindProjection(expression); if (expression4 != null) { Scope scope = this.scope; ParameterExpression fieldReader = Expression.Parameter(typeof(FieldReader), "r" + this.nReaders++); this.scope = new Scope(this.scope, fieldReader, expression4.Select.Alias, expression4.Select.Columns); LambdaExpression expression6 = Expression.Lambda(this.Visit(expression4.Projector), new ParameterExpression[] { fieldReader }); this.scope = scope; MappingEntity entity = EntityFinder.Find(expression4.Projector); command = new QueryCommand(command.CommandText, command.Parameters); return(Expression.Call(this.executor, "ExecuteBatch", new Type[] { expression6.Body.Type }, new Expression[] { Expression.Constant(command), expression2, expression6, Expression.Constant(entity, typeof(MappingEntity)), batch.BatchSize, batch.Stream })); } return(Expression.Call(this.executor, "ExecuteBatch", (Type[])null, new Expression[] { Expression.Constant(command), expression2, batch.BatchSize, batch.Stream })); }
private Expression ExecuteProjection(ProjectionExpression projection, bool okayToDefer, QueryCommand command, Expression[] values) { okayToDefer &= (this.receivingMember != null) && this.policy.IsDeferLoaded(this.receivingMember); Scope scope = this.scope; ParameterExpression fieldReader = Expression.Parameter(typeof(FieldReader), "r" + this.nReaders++); this.scope = new Scope(this.scope, fieldReader, projection.Select.Alias, projection.Select.Columns); LambdaExpression expression2 = Expression.Lambda(this.Visit(projection.Projector), new ParameterExpression[] { fieldReader }); this.scope = scope; MappingEntity entity = EntityFinder.Find(projection.Projector); string methodName = okayToDefer ? "ExecuteDeferred" : "Execute"; Expression replaceWith = Expression.Call(this.executor, methodName, new Type[] { expression2.Body.Type }, new Expression[] { Expression.Constant(command), expression2, Expression.Constant(entity, typeof(MappingEntity)), Expression.NewArrayInit(typeof(object), values) }); if (projection.Aggregator != null) { replaceWith = DbExpressionReplacer.Replace(projection.Aggregator.Body, projection.Aggregator.Parameters[0], replaceWith); } return(replaceWith); }
public abstract IEnumerable <T> ExecuteDeferred <T>(QueryCommand query, Func <FieldReader, T> fnProjector, MappingEntity entity, object[] paramValues);
public abstract int ExecuteCommand(QueryCommand query, object[] paramValues);
public abstract IEnumerable <T> ExecuteBatch <T>(QueryCommand query, IEnumerable <object[]> paramSets, Func <FieldReader, T> fnProjector, MappingEntity entity, int batchSize, bool stream);
public abstract IEnumerable <int> ExecuteBatch(QueryCommand query, IEnumerable <object[]> paramSets, int batchSize, bool stream);