Esempio n. 1
0
        public static void EvaluateLocals(DynamicLinqCommand command)
        {
            var locals = command.Locals;

            if (locals.Count == 0)
            {
                command.ParamValues = _emptyArray;
                return;
            }
            // evaluate external parameters - they come from OperationContext
            var extValues = _emptyArray;

            if (command.ExternalParameters != null && command.ExternalParameters.Length > 0)
            {
                var ctx = command.Session.Context;
                extValues = new object[command.ExternalParameters.Length];
                for (int i = 0; i < extValues.Length; i++)
                {
                    extValues[i] = LinqExpressionHelper.EvaluateContextParameterExpression(command.Session, command.ExternalParameters[i]);
                } //for i
            }     //if

            // evaluate locals
            command.ParamValues = new object[locals.Count];
            for (int i = 0; i < locals.Count; i++)
            {
                var local = locals[i];
                command.ParamValues[i] = ExpressionHelper.Evaluate(locals[i], command.ExternalParameters, extValues);
            }
        } //method
Esempio n. 2
0
        private ValueKind AnalyzeMember(MemberExpression node)
        {
            // check if it is subquery stored in local variable; if yes, retrieve the value and convert to constant
            IQueryable subQuery;

            if (LinqExpressionHelper.CheckSubQueryInLocalVariable(node, out subQuery))
            {
                AnalyzeNode(subQuery.Expression); // we need to visit it as well, to process sub-query nodes
                return(ValueKind.Db);
            }

            if (node.Type.IsSubclassOf(typeof(LinqLiteralBase)))
            {
                return(ValueKind.Constant);
            }
            if (node.Type == typeof(SequenceDefinition))
            {
                return(ValueKind.Constant);
            }

            //regular member access node
            var exprValueKind = this.AnalyzeNode(node.Expression);

            AddCacheKey(node.Member.Name);
            if (node.Member.IsStaticMember())
            {
                return(ValueKind.Local);
            }
            else
            {
                return(exprValueKind); //same as mexp.Expression's valueKind
            }
        }
Esempio n. 3
0
        //Detect and retrieve sub-query in local variable
        protected override Expression VisitMember(MemberExpression node)
        {
            IQueryable subQuery;

            if (LinqExpressionHelper.CheckSubQueryInLocalVariable(node, out subQuery))
            {
                var newExpr = Visit(subQuery.Expression);
                return(newExpr);
            }
            return(base.VisitMember(node));
        }
Esempio n. 4
0
 private void AnalyzeCommand(DynamicLinqCommand command)
 {
     _command         = command;
     _model           = command.Session.Context.App.Model;
     _cacheKeyBuilder = new SqlCacheKeyBuilder("Linq", command.Kind.ToString(), command.Operation.ToString());
     try {
         AnalyzeNode(_command.QueryExpression);
         //copy some values to command
         command.SqlCacheKey = _cacheKeyBuilder.Key;
         command.EntityTypes = _entityTypes;
         command.LockType    = _lockType;
         command.Includes    = _includes;
         command.Options    |= _options;
         command.Locals.AddRange(_locals);
         command.ExternalParameters = _externalParams?.ToArray();
         if (command.Locals.Count > 0)
         {
             LinqExpressionHelper.EvaluateLocals(command);
         }
     } catch (Exception ex) {
         ex.Data["LinqExperssion"] = _command.QueryExpression + string.Empty;
         throw;
     }
 }