Hello I would like to create a generic Expression Tree that returns a list contains result.
public static class Extension{
public static List<T> WhereIn<T, T1>(IQueryable<T> query, IEnumerable<T1> keys, Expression<Func<T, T1>> param)
{
}
}
The problem is that I would also like to create something like this:
var result = Extension.WhereIn(customers.AsQueryable(), stringList, c => c.Number.ToString());
so far this would work for a static property name:
public static Expression<Func<T, bool>> FilterByCode<T, T1>(List<T1> codes, string propName)
{
var methodInfo = typeof(List<T1>).GetMethod("Contains",
new Type[] { typeof(T1) });
var list = Expression.Constant(codes);
var param = Expression.Parameter(typeof(T), "j");
var value = Expression.Property(param, propName);
var body = Expression.Call(list, methodInfo, value);
// j => codes.Contains(j.Code)
return Expression.Lambda<Func<T, bool>>(body, param);
}