2012-02-02 65 views
0

我不知道怎麼翻譯與加入和子查詢linq..Following是我想翻譯..Please幫助如何翻譯SQL語句的LINQ

Select product.Name from product where Product.Id in(select ProductId from 
SaleDetail s join Sale s1 on s.SaleId=s1.Id where s.SaleId in(select Id from Sale where sale.CustomerId=17264)) 

回答

2

喜歡的東西sql語句sql語句這裏(db是linq數據上下文):

var result= (
     from p in db.Product 
     where 
      (
       from s in db.SaleDetail 
       join se in db.Sale 
        on s.SaleId equals se.Id 
       where 
        (
         from s2 in db.Sale 
         where s2.CustomerId==17264 
         select s2.Id 
        ).Contains(s.SaleId) 
       select s.ProductId 
      ).Contains(p.Id) 
     select new 
     { 
      p.Name 
     } 
    );