Пример #1
0
        public static IQueryable GroupJoin(this IQueryable outer, IQueryable inner, Func <ParameterExpression, Expression> outerKeySelector, Func <ParameterExpression, Expression> innerKeySelector, Func <ParameterExpression, ParameterExpression, Expression> resultSelector)
        {
            var touter = outer.ElementType;
            var tinner = inner.ElementType;

            var outerKeySelectorExpr = ExpressionEx.Func(touter.AsParameter(), outerKeySelector);
            var innerKeySelectorExpr = ExpressionEx.Func(tinner.AsParameter(), innerKeySelector);
            var resultSelectorExpr   = ExpressionEx.Func(touter.AsParameter(), tinner.AsEnumerableType().AsParameter(), resultSelector);

            var tkey = outerKeySelectorExpr.ReturnType;

            return(outer.Transform(outer.CallQueryable("GroupJoin", new Type[] { touter, tinner, tkey, resultSelectorExpr.ReturnType }, inner.Expression, outerKeySelectorExpr.Quote(), innerKeySelectorExpr.Quote(), resultSelectorExpr.Quote())));
        }
Пример #2
0
        public static IQueryable GroupJoin(this IQueryable outer, IQueryable inner, LambdaExpression outerKeySelector, LambdaExpression innerKeySelector)
        {
            var touter = outer.ElementType;
            var tinner = inner.ElementType;
            var tkey   = outerKeySelector.ReturnType;

            var resultSelectorExpression = ExpressionEx.Func(
                touter.AsParameter(),
                typeof(IEnumerable <>).MakeGenericType(tinner).AsParameter(),
                (element, joinedElements) => GenericGroupJoinItem.CreateNewExpression(element, joinedElements)
                );

            return(outer.Transform(outer.CallQueryable("GroupJoin", new Type[] { touter, tinner, tkey, resultSelectorExpression.ReturnType }, inner.Expression, outerKeySelector.Quote(), innerKeySelector.Quote(), resultSelectorExpression.Quote())));
        }
Пример #3
0
        //public static MethodCallExpression Call(this LambdaExpression func, params Expression[] arguments)
        //{
        //    return Expression.Call(
        //        typeof(LinqExt.Linq.Extensions),
        //        "Invoke",
        //        func.Type.GetGenericArguments(),
        //        new[] { func }.Concat(arguments.EmptyIfNull()).ToArray()
        //    );
        //}

        public static MethodCallExpression OrderBy(this Expression source, Func <ParameterExpression, Expression> keySelector, bool firstKey = true, bool descending = false)
        {
            var methodName = firstKey ? "OrderBy" : "ThenBy";

            if (descending)
            {
                methodName += "Descending";
            }

            var itemType        = source.Type.GetEnumerableItemType();
            var keySelectorExpr = ExpressionEx.Func(itemType.AsParameter(), keySelector);
            var res             = source.CallEnumerable(methodName, new[] { itemType, keySelectorExpr.ReturnType }, keySelectorExpr);

            return(res);
        }
Пример #4
0
        public static IQueryable Join(this IQueryable outer, IQueryable inner, LambdaExpression outerKeySelectorExpr, LambdaExpression innerKeySelectorExpr, Func <ParameterExpression, ParameterExpression, Expression> resultSelector = null)
        {
            var touter = outer.ElementType;
            var tinner = inner.ElementType;

            var tkey = outerKeySelectorExpr.ReturnType;

            if (resultSelector == null)
            {
                resultSelector = (left, right) => GenericJoinItem.CreateNewExpression(left, right);
            }

            var resultSelectorExpr = ExpressionEx.Func(touter.AsParameter(), tinner.AsParameter(), resultSelector);

            return(outer.Transform(outer.CallQueryable("Join", new Type[] { touter, tinner, tkey, resultSelectorExpr.ReturnType }, inner.Expression, outerKeySelectorExpr.Quote(), innerKeySelectorExpr.Quote(), resultSelectorExpr.Quote())));
        }
Пример #5
0
        public static IQueryable Join(this IQueryable outer, IQueryable inner, Func <ParameterExpression, Expression> outerKeySelector, Func <ParameterExpression, Expression> innerKeySelector, Func <ParameterExpression, ParameterExpression, Expression> resultSelector = null)
        {
            var touter = outer.ElementType;
            var tinner = inner.ElementType;

            return(outer.Join(inner, ExpressionEx.Func(touter.AsParameter(), outerKeySelector), ExpressionEx.Func(tinner.AsParameter(), innerKeySelector), resultSelector));
        }
Пример #6
0
        public static IQueryable Where(this IQueryable items, Func <ParameterExpression, Expression> predicate)
        {
            var res = items.Transform(items.CallQueryable("Where", Expression.Quote(ExpressionEx.Predicate(items.ElementType, predicate))));

            return(res);
        }