相关疑难解决方法(0)

LINQ中的动态WHERE子句

将动态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)

c# linq dynamic where-clause

54
推荐指数
6
解决办法
11万
查看次数

标签 统计

c# ×1

dynamic ×1

linq ×1

where-clause ×1