2012-04-04 85 views
1

我嘗試做以下查詢Linq中LINQ到SQL轉換爲SQL語法

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轉換爲SQL語法。

如何將左連接與內連接組合?

問候,

回答

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} 
+0

就像一個魅力。 – 2012-04-04 13:21:47