我正在关注 Scott Gu 的文章来创建动态 LINQ http://weblogs.asp.net/scottgu/archive/2008/01/07/dynamic-linq-part-1-using-the-linq-dynamic-query-library .aspx
他举了一个例子:
Expression<Func<Customer, bool>> e1 =
DynamicExpression.ParseLambda<Customer, bool>("City = \"London\"");
Expression<Func<Customer, bool>> e2 =
DynamicExpression.ParseLambda<Customer, bool>("Orders.Count >= 10");
IQueryable<Customer> query =
db.Customers.Where("@0(it) and @1(it)", e1, e2);
这在我的情况下很好用。但是,我有未知数量的 where 子句,这是在运行时决定的。
谁能告诉我如何创建一个通用的 Where 子句,例如
Where("@0(it) and @1(it) and... @n(it)", e1, e2, ... en);
谢谢