我有一个大问题.
我有一个linq查询,它只是看起来像这样:
from xx in table
where xx.uid.ToString().Contains(string[])
select xx
Run Code Online (Sandbox Code Playgroud)
string[]数组的值将是(1,45,20,10等...)
为默认.Contains的.Contains(string).
我需要它来代替: .Contains(string[])...
编辑:一位用户建议为其编写扩展类string[].我想知道如何,但任何人都愿意指出我正确的方向?
编辑: uid也是一个数字.这就是它被转换为字符串的原因.
帮助任何人?
将动态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)