如何编写LINQ查询来实现这一点

如何编写LINQ查询来实现这一点,linq,linq-to-sql,iqueryable,Linq,Linq To Sql,Iqueryable,天真的方法是将调用链接到Where方法,但这样只能实现和行为 看看约瑟夫·阿尔巴哈里的课。它允许使用OR运算符构建动态Linq查询我们使用动态Linq库来准确完成您要做的事情(在此处找到:) 您可以使用以下内容: foreach(var i in items) { // Where the object "i" has 2 properties // 1) i.Operator (values of which can be AND or OR) // 2) i.SomeID (va

天真的方法是将调用链接到
Where
方法,但这样只能实现和行为


看看约瑟夫·阿尔巴哈里的课。它允许使用OR运算符构建动态Linq查询

我们使用动态Linq库来准确完成您要做的事情(在此处找到:)

您可以使用以下内容:

foreach(var i in items)
{
  // Where the object "i" has 2 properties
  // 1) i.Operator (values of which can be AND or OR)
  // 2) i.SomeID (values of which can be 1 .. 10)

  // I need to build the LINQ query with "ands" and "ors" based on the i's in this foreach
}

where“Your where子句”是包含动态生成的where子句的字符串。

如何判断每个AND和OR的范围?你只想把它们链接起来(这可能是错误的逻辑)
foreach(var i in items)
{
  // Where the object "i" has 2 properties
  // 1) i.Operator (values of which can be AND or OR)
  // 2) i.SomeID (values of which can be 1 .. 10)

  // I need to build the LINQ query with "ands" and "ors" based on the i's in this foreach
}
var finalResults = results.Where("Your where clause");