extend Where for IQueryable

后端 未结 1 1947
不知归路
不知归路 2021-01-26 13:16

I need to extend the Where method for IQueryable to something like this:

.WhereEx(\"SomeProperty\", \"==\", \"value\")

I d

相关标签:
1条回答
  • 2021-01-26 14:14

    I did another post with a simplified question. the link is Here

        public static IQueryable<T> WhereEx<T>(this IQueryable<T> q, string Field, string Operator, string Value)
        {
            var param = Expression.Parameter(typeof(T), "p");
            var prop = Expression.Property(param, Field);
    
            var val = Expression.Constant(Value);
            var body = Expression.Equal(prop, val);
    
            var exp = Expression.Lambda<Func<T, bool>>(body, param);
    
            return System.Linq.Queryable.Where(q, exp);
        }
    
    0 讨论(0)
提交回复
热议问题