Linq to sql 链接中的多个where子句以或分隔

Linq to sql 链接中的多个where子句以或分隔,linq-to-sql,Linq To Sql,我有以下情况: 用户可以在搜索过程中从以下任一选项中进行选择: 0 1-3 4-6 7-9 10-12 十二,+ 假设他们选择了0,4-6和12+ SQL where语句应该是: Where (total_count = 0 OR (total_count >= 4 AND total_count <= 6) OR total_count > 12) 其中(总计数=0 或(总计数>=4和总计数12) 现在,为了获得这些值,我正在遍历一个复选框列表集合,因此尝试: que

我有以下情况:

用户可以在搜索过程中从以下任一选项中进行选择:

  • 0
  • 1-3
  • 4-6
  • 7-9
  • 10-12
  • 十二,+
假设他们选择了0,4-6和12+

SQL where语句应该是:

Where (total_count = 0
OR (total_count >= 4 AND total_count <= 6)
OR total_count > 12)
其中(总计数=0
或(总计数>=4和总计数12)
现在,为了获得这些值,我正在遍历一个复选框列表集合,因此尝试:

query = query.Where(tc => tc.total_count >= 4 && tc.total_count <= 6);

query=query.Where(tc=>tc.total\u count>=4&&tc.total\u count我看不出添加“OR”有什么问题。“Where”子句需要的只是一个谓词(返回true或false的内容)。或者我没有抓住要点

对于您的SQL示例,等效的是

    query.Where(tc=> tc.total_count == 0 || (tc.total_count >= 4 && tc.total_count <= 6) || tc.total_count > 12)
query.Where(tc=>tc.total_count==0 | |(tc.total_count>=4&&tc.total_count 12)

我看不出添加“OR”有什么问题,所有“WHERE”子句需要的都是谓词(返回true或false的内容)。或者我错过了要点。我发现问题的解决方案是,我从复选框中获取了值,所以它会发生变化。我偶然发现了解决问题的方法