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); }
private Expression ExecuteProjection(DbProjectionExpression projection, bool okayToDefer, bool isTopLevel) { projection = this.Parameterize(projection) as DbProjectionExpression; if (this.scope != null) { projection = OuterParameterizer.Parameterize(this.scope.Alias, projection) as DbProjectionExpression; } var commandText = this.linguist.Format(projection.Select); var namedValues = DbNamedValueGatherer.Gather(projection.Select); 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[]; return(this.ExecuteProjection(projection, okayToDefer, command, values, isTopLevel)); }
protected virtual Expression BuildExecuteCommand(DbCommandExpression command) { var expression = this.Parameterize(command); var commandText = this.linguist.Format(expression); var namedValues = DbNamedValueGatherer.Gather(expression); var qc = 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 projection = ProjectionFinder.FindProjection(expression); if (projection != null) { return(this.ExecuteProjection(projection, false, qc, values, isTopLevel: true)); } var plan = Expression.Call ( this.executor, nameof(QueryExecutor.ExecuteCommand), null, Expression.Constant(qc), Expression.NewArrayInit(typeof(object), values) ); return(plan); }