コード例 #1
0
        protected virtual Expression Parameterize(Expression expression)
        {
            if (_variableMap.Count > 0)
            {
                expression = VariableSubstitutor.Substitute(_variableMap, expression);
            }

            return(Parameterizer.Parameterize(expression));
        }
コード例 #2
0
        private Expression ExecuteProjection(ProjectionExpression projection, bool okayToDefer)
        {
            okayToDefer &= (receivingMember != null && policy.IsDeferLoaded(receivingMember));

            // parameterize query
            projection = (ProjectionExpression)Parameterizer.Parameterize(projection);

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

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

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

            scope = saveScope;

            string commandText = policy.Mapping.Language.Format(projection.Source);
            ReadOnlyCollection <NamedValueExpression> namedValues = NamedValueGatherer.Gather(projection.Source);

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

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

            if (okayToDefer)
            {
            }

            // call low-level execute directly on supplied DbQueryProvider
            Expression result = Expression.Call(provider, methExecute, new[] { projector.Body.Type },
                                                Expression.New(
                                                    typeof(QueryCommand <>).MakeGenericType(projector.Body.Type).
                                                    GetConstructors()[0],
                                                    Expression.Constant(commandText),
                                                    Expression.Constant(names),
                                                    projector
                                                    ),
                                                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
ファイル: QueryCache.cs プロジェクト: shumtn/skynet-cloud
        private LambdaExpression Parameterize(Expression query, out object[] arguments)
        {
            IQueryProvider provider = this.FindProvider(query);

            if (provider == null)
            {
                throw new ArgumentException(Res.ArgumentQuery);
            }

            var ep = provider as IDbContext;

            // turn all relatively constant expression into actual constants
            Func <Expression, bool> fnCanBeEvaluated = e => ep != null?ExpressionHelper.CanBeEvaluatedLocally(e) : true;

            var body = PartialEvaluator.Eval(query, fnCanBeEvaluated);

            // convert all constants into parameters
            List <ParameterExpression> parameters;
            List <object> values;

            body = Parameterizer.Parameterize(body, out parameters, out values);

            // make sure the body will return a value typed as 'object'.
            if (body.Type != typeof(object))
            {
                body = Expression.Convert(body, typeof(object));
            }

            // make a lambda expression with these parameters
            arguments = values.ToArray();
            if (arguments.Length < 5)
            {
                return(Expression.Lambda(body, parameters.ToArray()));
            }
            else
            {
                // too many parameters, use an object array instead.
                arguments = new object[] { arguments };
                return(ExplicitToObjectArray.Rewrite(body, parameters));
            }
        }
コード例 #4
0
 /// <summary>
 /// Determine which sub-expressions must be parameters
 /// </summary>
 /// <param name="expression"></param>
 /// <returns></returns>
 public virtual Expression Parameterize(Expression expression)
 {
     return(Parameterizer.Parameterize(this.Language, expression));
 }
コード例 #5
0
 /// <summary>
 /// Determine which sub-expressions must be parameters
 /// </summary>
 /// <param name="expression"></param>
 /// <returns></returns>
 public virtual Expression Parameterize(Expression expression)
 {
     return(Parameterizer.Parameterize(expression));
 }