2012-02-02 66 views
0

HI這裏是我的LINQ到SQL代碼返回產品名稱的列表,從表Product..But我也想從表sale..Please幫助返回多個coloumns

var result = (from p in db.Products 
           where 
            (
             from s in db.SaleDetails 
             join se in db.Sales 
              on s.SaleId equals se.Id 
             where 
              (
               from s2 in db.Sales 
               where s2.CustomerId == customerId 
               select s2.Id 
              ).Contains(s.SaleId) 
             select s.ProductId 
            ).Contains(p.Id) 
            select p.Name 
          ).ToList(); 
選擇SellDateTime coloumn從兩個不同勢表

回答

0

類似這樣的:

var result = (from p in db.Products 
        join s in db.SaleDetails 
         on p.Id equals s.ProductId 
        join se in db.Sales 
         on s.SaleId equals se.Id 
        where se.CustomerId==customerId 
        select new 
        { 
         p.Name, 
         se.SellDateTime 
        } 
       ).ToList();