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));
        }
Exemple #2
0
        public static MethodCallExpression Select(this Expression source, Func <ParameterExpression, Expression> selector)
        {
            var itemType     = source.Type.GetEnumerableItemType();
            var selectorExpr = ExpressionEx.Func(itemType.AsParameter(), selector);
            var res          = source.CallEnumerable("Select", new[] { itemType, selectorExpr.ReturnType }, selectorExpr);

            return(res);
        }
        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())));
        }
        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())));
        }
Exemple #5
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);
        }
        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())));
        }