1

我正在尝试在 Linq 中执行以下查询

SELECT *
FROM Table1 T1
INNER JOIN Table2 T2
ON T1.ID = T2.AnotherID
LEFT OUTER JOIN Table3 T3
on T1.ID = T3.AnotherID

它以正确的 SQL 语法按预期工作,但我很难将其转换为相应的 Linq to SQL 语法。

如何将左连接与内连接结合起来?

问候,

4

1 回答 1

8
var results = from t1 in Table1
   from t2 in Table2
   where t1.ID = t2.AnotherID
   join t3 in Table3 on t1.ID equals t3.AnotherID into joined
   from j in joined.DefaultIfEmpty()
   select new {t1, t2, t3 = j}
于 2012-04-04T12:02:06.097 回答