“选择不输入" Linq to Entities中的子句 [英] "Select NOT IN" clause in Linq to Entities

查看:56
本文介绍了“选择不输入" Linq to Entities中的子句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用Linq to Entities中的"NOT IN(select XXX ...)"子句?
我发现的所有问题都与对象列表(IN(1,2,3))有关,但我想使用以下语法生成查询:

Is there a way to use the "NOT IN (select XXX...)" clause in Linq to Entities?
All the questions I found were regarding a list of objects (IN (1,2,3)) but I want to generate a query with the following syntax:

select * from table1 where field1 not in (select subfield from subtable)  

请注意,这是对实体的Linq,而不是对SQL的Linq ...

Be aware that this is Linq to Entities and not Linq to Sql...

有可能吗?

谢谢!

推荐答案

像这样:

from c in db.Customers
where !db.Products.Any(p => p.ProductID == c.ProductID)
select c;

这篇关于“选择不输入" Linq to Entities中的子句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆