Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        protected virtual Expression BuildExecuteCommand(CommandExpression command)
        {
            // parameterize query
            Expression expression = Parameterize(command);

            string commandText = linguist.Format(expression);
            ReadOnlyCollection <NamedValueExpression> namedValues = NamedValueGatherer.Gather(expression);
            var qc = 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();

            ProjectionExpression projection = ProjectionFinder.FindProjection(expression);

            if (projection != null)
            {
                return(ExecuteProjection(projection, false, qc, values));
            }

            Expression plan = Expression.Call(executor, "ExecuteCommand", null, Expression.Constant(qc), Expression.NewArrayInit(typeof(object), values));

            return(plan);
        }
Ejemplo n.º 3
0
        private Expression ExecuteProjection(ProjectionExpression projection, bool okayToDefer, QueryCommand command, Expression[] values)
        {
            okayToDefer &= (receivingMember != null && policy.IsDeferLoaded(receivingMember));

            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);

            string methExecute = okayToDefer ? "ExecuteDeferred" : "Execute";

            // call low-level execute directly on supplied DbQueryProvider
            Expression result = Expression.Call(executor, methExecute, new[] { projector.Body.Type }, Expression.Constant(command), projector, Expression.Constant(entity, typeof(EntryMapping)),
                                                Expression.NewArrayInit(typeof(object), values));

            if (projection.Aggregator != null)
            {
                // apply aggregator
                result = DbExpressionReplacer.Replace(projection.Aggregator.Body, projection.Aggregator.Parameters[0], result);
            }
            return(result);
        }
Ejemplo n.º 4
0
 public abstract int ExecuteCommand(QueryCommand query, object[] paramValues);
Ejemplo n.º 5
0
 public abstract IEnumerable <T> ExecuteDeferred <T>(QueryCommand query, Func <FieldReader, T> fnProjector, EntryMapping entity, object[] paramValues);
Ejemplo n.º 6
0
 public abstract IEnumerable <T> ExecuteBatch <T>(QueryCommand query, IEnumerable <object[]> paramSets, Func <FieldReader, T> fnProjector, EntryMapping entity, int batchSize, bool stream);
Ejemplo n.º 7
0
 public abstract IEnumerable <int> ExecuteBatch(QueryCommand query, IEnumerable <object[]> paramSets, int batchSize, bool stream);