gpt4 book ai didi

c# - Linq to SQL 转换为 SQL 语法

转载 作者:太空宇宙 更新时间:2023-11-03 18:13:55 25 4
gpt4 key购买 nike

我正在尝试在 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 语法。

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

问候,

最佳答案

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}

关于c# - Linq to SQL 转换为 SQL 语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10010541/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com