在Linq中转换SQL子查询

时间:2013-06-13 12:56:26

标签: sql linq

如何在linq中转换子查询?我的疑问是:

select *
from Product 
where ID in 
(
   select distinct(sku.ProductId) 
   from SiteProducts sp
   inner join ProductSKU sku on sp.ProductId = sku.Id
   where sp.siteid = 2
)

1 个答案:

答案 0 :(得分:2)

from p in db.Product
where (from sp in db.SiteProducts
       join sku in db.ProductSKU on sp.ProductId equals sku.Id
       where sp.siteid == 2
       select sku.ProductId).Distinct().Contains(p.ID)
select p