public Expression GetGroupJoin(GroupJoinContext context) { // Convert outer condition. // var outerParam = Expression.Parameter(context._outerKeyLambda.Body.Type, "o"); var outerKey = context._outerKeyLambda.GetBody(context.Lambda.Parameters[0]); outerKey = context.Builder.BuildExpression(context, outerKey, false); // Convert inner condition. // var parameters = context.Builder.CurrentSqlParameters .Select((p,i) => new { p, i }) .ToDictionary(_ => _.p.Expression, _ => _.i); var paramArray = Expression.Parameter(typeof(object[]), "ps"); var innerKey = context._innerKeyLambda.Body.Transform(e => { int idx; if (parameters.TryGetValue(e, out idx)) { return Expression.Convert( Expression.ArrayIndex(paramArray, Expression.Constant(idx)), e.Type); } return e; }); // Item reader. // var expr = Expression.Call( null, MemberHelper.MethodOf(() => Queryable.Where(null, (Expression<Func<TElement,bool>>)null)), context._innerExpression, Expression.Lambda<Func<TElement,bool>>( ExpressionBuilder.Equal(context.Builder.MappingSchema, innerKey, outerParam), new[] { context._innerKeyLambda.Parameters[0] })); var lambda = Expression.Lambda<Func<IDataContext,TKey,object[],IQueryable<TElement>>>( Expression.Convert(expr, typeof(IQueryable<TElement>)), Expression.Parameter(typeof(IDataContext), "ctx"), outerParam, paramArray); var itemReader = CompiledQuery.Compile(lambda); return Expression.Call( null, MemberHelper.MethodOf(() => GetGrouping(null, null, default(TKey), null)), new[] { ExpressionBuilder.QueryRunnerParam, Expression.Constant(context.Builder.CurrentSqlParameters), outerKey, Expression.Constant(itemReader), }); }
public Expression GetGroupJoinCall(GroupJoinContext context) { var expr = Expression.Call( null, MemberHelper.MethodOf(() => Queryable.Where(null, (Expression <Func <T, bool> >)null)), context._innerExpression, Expression.Lambda <Func <T, bool> >( Expression.Equal( context._innerKeyLambda.Body.Unwrap(), context._outerKeyLambda.GetBody(context.Lambda.Parameters[0])), new[] { context._innerKeyLambda.Parameters[0] })); return(expr); }
public Expression GetGroupJoin(GroupJoinContext context) { // Convert outer condition. // var outerParam = Expression.Parameter(context.OuterKeyLambda.Body.Type, "o"); var outerKey = context.OuterKeyLambda.GetBody(context.Lambda.Parameters[0]); outerKey = context.Builder.BuildExpression(context, outerKey, false); // Convert inner condition. // var parameters = context.Builder.ParametersContext.CurrentSqlParameters .Select((p, i) => new { p, i }) .ToDictionary(_ => _.p.Expression, _ => _.i); var paramArray = Expression.Parameter(typeof(object[]), "ps"); var innerKey = context.InnerKeyLambda.Body.Transform( (parameters, paramArray),
/// <summary> /// Returns a Slinq that enumerates a group join of the lookup with the specified Slinq using the specified selectors. /// When the enumeration is complete, the lookup and any values it contains are added to the disposal queue. /// </summary> public Slinq <U, GroupJoinContext <U, K, T, T2, C2, P> > GroupJoinAndDispose <U, T2, C2, P>(Slinq <T2, C2> outer, Func <T2, P, K> outerSelector, Func <T2, Slinq <T, LinkedContext <T> >, P, U> resultSelector, P parameter) { return(GroupJoinContext <U, K, T, T2, C2, P> .GroupJoin(this, outer, outerSelector, resultSelector, parameter, true)); }
/// <summary> /// Returns a Slinq that enumerates a group join of the lookup with the specified Slinq using the specified selectors. /// Ownership of the lookup and any values it contains is retained by the caller. /// </summary> public Slinq <U, GroupJoinContext <U, K, T, T2, C2> > GroupJoinAndKeep <U, T2, C2>(Slinq <T2, C2> outer, Func <T2, K> outerSelector, Func <T2, Slinq <T, LinkedContext <T> >, U> resultSelector) { return(GroupJoinContext <U, K, T, T2, C2> .GroupJoin(this, outer, outerSelector, resultSelector, false)); }
public Expression GetGroupJoin(GroupJoinContext context) { // Convert outer condition. // var outerParam = Expression.Parameter(context._outerKeyLambda.Body.Type, "o"); var outerKey = context._outerKeyLambda.Body.Convert( e => e == context._outerKeyLambda.Parameters[0] ? context.Lambda.Parameters[0] : e); outerKey = context.Builder.BuildExpression(context, outerKey); // Convert inner condition. // var parameters = context.Builder.CurrentSqlParameters .Select((p, i) => new { p, i }) .ToDictionary(_ => _.p.Expression, _ => _.i); var paramArray = Expression.Parameter(typeof(object[]), "ps"); var innerKey = context._innerKeyLambda.Body.Convert(e => { int idx; if (parameters.TryGetValue(e, out idx)) { return (Expression.Convert( Expression.ArrayIndex(paramArray, Expression.Constant(idx)), e.Type)); } return(e); }); // Item reader. // // ReSharper disable AssignNullToNotNullAttribute var expr = Expression.Call( null, ReflectionHelper.Expressor <object> .MethodExpressor(_ => Queryable.Where(null, (Expression <Func <TElement, bool> >)null)), context._innerExpression, Expression.Lambda <Func <TElement, bool> >( Expression.Equal(innerKey, outerParam), new[] { context._innerKeyLambda.Parameters[0] })); // ReSharper restore AssignNullToNotNullAttribute var lambda = Expression.Lambda <Func <IDataContext, TKey, object[], IQueryable <TElement> > >( Expression.Convert(expr, typeof(IQueryable <TElement>)), Expression.Parameter(typeof(IDataContext), "ctx"), outerParam, paramArray); var itemReader = CompiledQuery.Compile(lambda); return(Expression.Call( null, ReflectionHelper.Expressor <object> .MethodExpressor(_ => GetGrouping(null, null, default(TKey), null)), new[] { ExpressionBuilder.ContextParam, Expression.Constant(context.Builder.CurrentSqlParameters), outerKey, Expression.Constant(itemReader), })); }
/// <summary> /// Returns a Slinq that enumerates a group join of the lookup with the specified Slinq using the specified selectors. /// /// When the enumeration is complete, the lookup and any values it contains are added to the disposal queue. /// </summary> public Slinq <U, GroupJoinContext <U, K, T, T2, C2> > GroupJoinAndDispose <U, T2, C2>(Slinq <T2, C2> outer, DelegateFunc <T2, K> outerSelector, DelegateFunc <T2, Slinq <T, LinkedContext <T> >, U> resultSelector) { return(GroupJoinContext <U, K, T, T2, C2> .GroupJoin(this, outer, outerSelector, resultSelector, true)); }
/// <summary> /// Returns a Slinq that enumerates a group join of the lookup with the specified Slinq using the specified selectors. /// /// Ownership of the lookup and any values it contains is retained by the caller. /// </summary> public Slinq <U, GroupJoinContext <U, K, T, T2, C2, P> > GroupJoinAndKeep <U, T2, C2, P>(Slinq <T2, C2> outer, DelegateFunc <T2, P, K> outerSelector, DelegateFunc <T2, Slinq <T, LinkedContext <T> >, P, U> resultSelector, P parameter) { return(GroupJoinContext <U, K, T, T2, C2, P> .GroupJoin(this, outer, outerSelector, resultSelector, parameter, false)); }