1

次のラムダを式ツリーにどのように変換しますか?

source.Join(lookup, s => s.Id, l => l.Id, (s,l) => l)

resultSelector(s、l)=>lを除いてすべてカバーしていると思います。

これが私のコードです..ありがとう!

public static IQueryable<TLookup> GetLookupSource<T, TLookup, TKey>(this IQueryable<T> source, IQueryable<TLookup> lookup{
   ParameterExpression s = Expression.Parameter(source.ElementType, "s");
   Expression<Func<T, TKey>> outerKeySelector = Expression.Lambda<Func<T, TKey>>(Expression.PropertyOrField(s, "Id"), s);

   ParameterExpression l = Expression.Parameter(lookup.ElementType, "l");
   Expression<Func<TLookup, TKey>> innerKeySelector = Expression.Lambda<Func<TLookup, TKey>>(Expression.PropertyOrField(l, "Id"), l);

   Expression<Func<T, TLookup, IQueryable<TLookup>>> resultSelector = null;//<---How to compose this

   MethodInfo joinMethod = typeof(Queryable).GetMethods(BindingFlags.Static | BindingFlags.Public).Where(m => m.Name == "Join" && m.GetParameters().Length == 5).First();
   var genericJoinMethod = joinMethod.MakeGenericMethod(typeof(T), typeof(TLookup), typeof(TKey), typeof(IQueryable<TLookup>));
   var result = genericJoinMethod.Invoke(source, new object[] { source, lookup, outerKeySelector, innerKeySelector, resultSelector });
   return (IQueryable<TLookup>)result;
}
4

1 に答える 1

5

私はこれがそれをするべきだと思います:

var resultSelector = Expression.Lambda<Func<T, TLookup, TLookup>>(l, s, l);
于 2012-04-06T00:24:18.920 に答える