示例#1
0
        /// <summary>
        /// Executes the projection.
        /// </summary>
        /// <param name="projection">The projection.</param>
        /// <param name="okayToDefer">if set to <c>true</c> [okay to defer].</param>
        /// <returns></returns>
        private Expression ExecuteProjection(ProjectionExpression projection, bool okayToDefer)
        {
            // parameterize query
            projection = (ProjectionExpression)this.Parameterize(projection);

            if (this.scope != null)
            {
                // also convert references to outer alias to named values!  these become SQL parameters too
                projection = (ProjectionExpression)OuterParameterizer.Parameterize(this.scope.Alias, projection);
            }

            FixColumnNames(projection);

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

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

            return(this.ExecuteProjection(projection, okayToDefer, command, values));
        }
示例#2
0
        /// <summary>
        /// Executes the projection.
        /// </summary>
        /// <param name="projection">The projection.</param>
        /// <param name="okayToDefer">if set to <c>true</c> [okay to defer].</param>
        /// <param name="command">The command.</param>
        /// <param name="values">The values.</param>
        /// <returns></returns>
        private Expression ExecuteProjection(ProjectionExpression projection, bool okayToDefer, QueryCommand command, Expression[] values)
        {
            okayToDefer &= (this.receivingMember != null && this.policy.IsDeferLoaded(this.receivingMember));

            var saveScope = this.scope;
            ParameterExpression reader = Expression.Parameter(typeof(FieldReader), "r" + nReaders++);

            this.scope = new Scope(this.scope, reader, projection.Select.Alias, projection.Select.Columns);
            LambdaExpression projector = Expression.Lambda(this.Visit(projection.Projector), reader);

            this.scope = saveScope;

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

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

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

            if (projection.Aggregator != null)
            {
                // apply aggregator
                result = DbExpressionReplacer.Replace(projection.Aggregator.Body, projection.Aggregator.Parameters[0], result);
            }
            return(result);
        }
示例#3
0
 /// <summary>
 /// Executes the command.
 /// </summary>
 /// <param name="query">The query.</param>
 /// <param name="paramValues">The param values.</param>
 /// <returns></returns>
 public abstract int ExecuteCommand(QueryCommand query, object[] paramValues);
示例#4
0
 /// <summary>
 /// Executes the specified command.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="command">The command.</param>
 /// <param name="fnProjector">The fn projector.</param>
 /// <param name="entity">The entity.</param>
 /// <param name="paramValues">The param values.</param>
 /// <returns></returns>
 public abstract IEnumerable <T> Execute <T>(QueryCommand command, Func <FieldReader, T> fnProjector, MappingEntity entity, object[] paramValues);