简体   繁体   English

Linq 到 SQL 翻译成 SQL 语法

[英]Linq to SQL translation to SQL syntax

I'm trying to do the following query in Linq我正在尝试在 Linq 中执行以下查询

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

It works as expected in proper SQL syntax, but i'm having a hard time translating it to the corresponding Linq to SQL syntax.它在正确的 SQL 语法中按预期工作,但我很难将其转换为相应的 Linq 到 SQL 语法。

How do i combine left join with an inner join?我如何将左连接与内部连接结合起来?

Regards,问候,

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}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM