加入收藏 | 设为首页 | 会员中心 | 我要投稿 莱芜站长网 (https://www.0634zz.com/)- 云连接、建站、智能边缘云、设备管理、大数据!
当前位置: 首页 > 数据库 > MsSql > 正文

sql-server C 什么是LINQ相当于SQL的“IN”关键字

发布时间:2023-12-15 00:55:07 所属栏目:MsSql 来源:DaWei
导读: 我怎样才能在
linq中编写下面的sql查询


select * from Product where ProductTypePartyID IN
(
select Id from ProductTypeParty where PartyId = 34
)

解决方法

除了语法

我怎样才能在 linq中编写下面的sql查询 select * from Product where ProductTypePartyID IN ( select Id from ProductTypeParty where PartyId = 34 ) 解决方法 除了语法变化之外,您可以用几乎相同的方式编写它. from p in ctx.Product where (from ptp in ctx.ProductTypeParty where ptp.PartyId == 34 select ptp.Id).Contains(p.ProductTypePartyID) select p

我更喜欢使用存在量词,但是:

from p in ctx.Product where (from ptp in ctx.ProductTypeParty where ptp.PartyId == 34 && ptp.Id == p.ProductTypePartyID).Any() select p

我希望这个表单将解析为生成的SQL中的EXISTS(SELECT * …).

如果性能有很大差异,您需要对两者进行分析.

(编辑:莱芜站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章