来自SQL的LINQ To DataSet

时间:2014-05-22 00:32:53

标签: c# sql linq linq-to-dataset

我无法将SQL Join语句转换为LINQ to DataSet。另外,请考虑LINQ语句中将有其他表将Header表连接到。以下是我的加入声明 - 感谢任何帮助。

FROM Header
LEFT JOIN Address
ON Header.Customer = Address.Customer
AND Header.Company = Address.Company
AND ((Header.ShipTo = 'TEMP' AND Header.DocNum = Address.ShipTo) 
    OR Header.ShipTo <> 'TEMP' AND Header.ShipTo = Address.ShipTo)

1 个答案:

答案 0 :(得分:0)

在Linq中进行联接使用Equals()方法。使用多列时,您必须创建一个结构相同的匿名类型进行比较。

from h in db.header
join a in db.address
on new { 
         cust = h.Customer, 
         comp = h.Company 
       } 
equals new 
       { 
         cust = a.Customer, 
         comp = a.Company 
       }
where ((h.ShipTo == "TEMP" && h.DocNum == a.ShipTo) 
        || h.ShipTo != "TEMP" && h.ShipTo == a.ShipTo)
select h;