以前一直觉得linq to sql生成类似where id not in (1,3,5)或where id not in (select id from ...)这样的条件不是很方便,每次我都是把条件ID事先取到一个数组里,然后用 !Arr.Contains(c.Id)这样处理,今天突然发现这样好傻,其实可以完全直接用linq写成一句,贴个示例在这里,以后备查

from a in TableA where !(from b in TableB Where ... select b.Id).Contains(a.Id)

最终翻译出来的语句并非跟not in 完全一样的,而是用not exists(...),不过效果完全相同,能达到要求就行了

 

 

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-11-03
  • 2022-12-23
  • 2022-03-04
  • 2022-12-23
  • 2021-09-26
  • 2022-12-23
猜你喜欢
  • 2021-11-11
  • 2022-12-23
  • 2022-12-23
  • 2021-12-22
  • 2022-12-23
  • 2022-12-23
  • 2022-01-10
相关资源
相似解决方案