private void AddPostExecuteTransformerForCount()
        {
            // Count results have to be summed. No null case to take into account.
            var elementType   = Model.ResultTypeOverride;
            var inputListType = typeof(IEnumerable <>).MakeGenericType(elementType);
            var inputList     = Expression.Parameter(inputListType, "inputList");
            // Sum has no suitable generic overload, throw in Sum on int, then the code using it
            // will check and adjust it if it is long instead of int (GetAggregateMethodCall does that).
            var aggregateCall = GetAggregateMethodCall(ReflectionCache.EnumerableMethods.SumOnInt, inputListType, elementType, inputList);

            _hqlTree.AddPostExecuteTransformer(Expression.Lambda(aggregateCall, inputList));
        }
Example #2
0
        public void Process(AggregateResultOperator resultOperator, QueryModelVisitor queryModelVisitor, IntermediateHqlTree tree)
        {
            var inputExpr       = ((StreamedSequenceInfo)queryModelVisitor.PreviousEvaluationType).ItemExpression;
            var inputType       = inputExpr.Type;
            var paramExpr       = Expression.Parameter(inputType, "item");
            var accumulatorFunc = Expression.Lambda(
                ReplacingExpressionVisitor.Replace(inputExpr, paramExpr, resultOperator.Func.Body),
                resultOperator.Func.Parameters[0],
                paramExpr);

            // NH-3850: changed from list transformer (working on IEnumerable<object>) to post execute
            // transformer (working on IEnumerable<inputType>) for globally aggregating polymorphic results
            // instead of aggregating results for each class separately and yielding only the first.
            // If the aggregation relies on ordering, final result will still be wrong due to
            // polymorphic results being union-ed without re-ordering. (This is a limitation of all polymorphic
            // queries, this is not specific to LINQ provider.)
            var inputList             = Expression.Parameter(typeof(IEnumerable <>).MakeGenericType(inputType), "inputList");
            var aggregate             = ReflectionCache.EnumerableMethods.AggregateDefinition.MakeGenericMethod(inputType);
            MethodCallExpression call = Expression.Call(
                aggregate,
                inputList,
                accumulatorFunc
                );

            tree.AddPostExecuteTransformer(Expression.Lambda(call, inputList));
            // There is no more a list transformer yielding an IList<resultType>, but this aggregate case
            // have inputType = resultType, so no further action is required.
        }
        protected static void AddClientSideEval(MethodInfo target, QueryModelVisitor queryModelVisitor, IntermediateHqlTree tree)
        {
            target = target.MakeGenericMethod(queryModelVisitor.CurrentEvaluationType.DataType);

            var parameter = Expression.Parameter(queryModelVisitor.PreviousEvaluationType.DataType, null);

            var lambda = Expression.Lambda(
                Expression.Call(
                    target,
                    parameter),
                parameter);

            tree.AddPostExecuteTransformer(lambda);
        }
Example #4
0
        protected static void AddClientSideEval(MethodInfo target, QueryModelVisitor queryModelVisitor, IntermediateHqlTree tree)
        {
            target = target.MakeGenericMethod(queryModelVisitor.CurrentEvaluationType.DataType);

            var parameter = Expression.Parameter(queryModelVisitor.PreviousEvaluationType.DataType, null);

            var lambda = Expression.Lambda(
                Expression.Call(
                    target,
                    parameter),
                parameter);

            tree.AddPostExecuteTransformer(lambda);
        }
		protected static void AddClientSideEval(MethodInfo target, QueryModelVisitor queryModelVisitor, IntermediateHqlTree tree)
		{
			var type = queryModelVisitor.Model.SelectClause.Selector.Type;
			target = target.MakeGenericMethod(type);

			var parameter = Expression.Parameter(typeof(IQueryable<>).MakeGenericType(type), null);

			var lambda = Expression.Lambda(
				Expression.Call(
					target,
					parameter),
				parameter);

			tree.AddPostExecuteTransformer(lambda);
		}
        protected static void AddClientSideEval(MethodInfo target, QueryModelVisitor queryModelVisitor, IntermediateHqlTree tree)
        {
            var type = queryModelVisitor.Model.ResultTypeOverride ?? queryModelVisitor.Model.SelectClause.Selector.Type;

            target = target.MakeGenericMethod(type);

            var parameter = Expression.Parameter(typeof(IQueryable <>).MakeGenericType(type), null);

            var lambda = Expression.Lambda(
                Expression.Call(
                    target,
                    parameter),
                parameter);

            tree.AddPostExecuteTransformer(lambda);
        }
Example #7
0
        public void Process(AnyResultOperator anyOperator, QueryModelVisitor queryModelVisitor, IntermediateHqlTree tree)
        {
            if (tree.IsRoot)
            {
                tree.AddTakeClause(tree.TreeBuilder.Constant(1));

                Expression <Func <IEnumerable <object>, bool> > x = l => l.Any();
                tree.AddListTransformer(x);

                // NH-3850: Queries with polymorphism yields many results which must be combined.
                Expression <Func <IEnumerable <bool>, bool> > px = l => l.Any(r => r);
                tree.AddPostExecuteTransformer(px);
            }
            else
            {
                tree.SetRoot(tree.TreeBuilder.Exists((HqlQuery)tree.Root));
            }
        }
Example #8
0
        public void Process(AllResultOperator resultOperator, QueryModelVisitor queryModelVisitor, IntermediateHqlTree tree)
        {
            tree.AddWhereClause(tree.TreeBuilder.BooleanNot(
                                    HqlGeneratorExpressionVisitor.Visit(resultOperator.Predicate, queryModelVisitor.VisitorParameters).
                                    ToBooleanExpression()));

            if (tree.IsRoot)
            {
                tree.AddTakeClause(tree.TreeBuilder.Constant(1));

                Expression <Func <IEnumerable <object>, bool> > x = l => !l.Any();
                tree.AddListTransformer(x);

                // NH-3850: Queries with polymorphism yields many results which must be combined.
                Expression <Func <IEnumerable <bool>, bool> > px = l => l.All(r => r);
                tree.AddPostExecuteTransformer(px);
            }
            else
            {
                tree.SetRoot(tree.TreeBuilder.BooleanNot(tree.TreeBuilder.Exists((HqlQuery)tree.Root)));
            }
        }