【发布时间】:2010-10-25 07:22:04
【问题描述】:
将动态 WHERE 子句组合到 LINQ 语句的最佳方法是什么?
我在一个表单上有几十个复选框,并将它们作为: Dictionary
public IOrderedQueryable<ProductDetail> GetProductList(string productGroupName, string productTypeName, Dictionary<string,List<string>> filterDictionary)
{
var q = from c in db.ProductDetail
where c.ProductGroupName == productGroupName && c.ProductTypeName == productTypeName
// insert dynamic filter here
orderby c.ProductTypeName
select c;
return q;
}
【问题讨论】:
-
我有同样的问题 (stackoverflow.com/questions/798553/user-defined-filter-for-linq),@tvanfosson 告诉我有关 Dynamic Linq (code.msdn.microsoft.com/csharpsamples)。
标签: c# linq dynamic where-clause