我需要转换此查询:
SELECT *
FROM Table1 AS t1
left join Table2 t2
on t1.Column1 = t2.Column1
left join Table2 t2
on t1.Column2 = t2.Column2 and t2.Column3 = 1
到LinqToSQL和Lambda。
我一直在寻找对LINQ中SQL连接的一个很好的解释,但是在找到任何明确说明如何利用LINQ来实现SQL中提供的不同连接的任何事情上都没有多少运气。
有人可以解释如何在SQL中利用不同的SQL连接。
答案 0 :(得分:1)
尝试这样的事情:
AlternativeLearningPlanYears
.GroupJoin
(
Leas,
x => x.DistrictLeaId,
y => y.LeaId,
(x,y) => new {x,y}
)
.GroupJoin
(
Leas,
x => new {x.PrivateInstitutionId,1},
y => new {y.PrivateInstitutionId,IsPrivateInstitution},
(x,y) => new {x,y}
)
.Where
(
z => z.x.SchoolYear == 23
&& z.x.Granted == 1
&& z.x.PrivateInstitutionId == null
&& z.x.DistrictName == null
)
我没有你的架构所以可能会有一些错误,所以发布它们我们会解决它们。