将动态WHERE子句组装到LINQ语句的最佳方法是什么?
我在表单上有几十个复选框,并将它们传递回:Dictionary <string,List <string >>(Dictionary <fieldName,List <values >>)到我的LINQ查询.
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;
}
Run Code Online (Sandbox Code Playgroud)