最佳答案
给出:
一个名为 TABLE_1
的表,其中包含以下列:
ID
ColumnA
ColumnB
ColumnC
我有 SQL 查询,其中 TABLE_1
连接本身两次基于 ColumnA
,ColumnB
,ColumnC
。查询可能类似于下面这样:
Select t1.ID, t2.ID, t3.ID
From TABLE_1 t1
Left Join TABLE_1 t2 On
t1.ColumnA = t2.ColumnA
And t1.ColumnB = t2.ColumnB
And t1.ColumnC = t2.ColumnC
Left Join TABLE_1 t3 On
t2.ColumnA = t3.ColumnA
And t2.ColumnB = t3.ColumnB
And t2.ColumnC = t3.ColumnC
... and query continues on etc.
问题:
我需要在 LINQ 中重写这个查询。我已经尝试过了:
var query =
from t1 in myTABLE1List // List<TABLE_1>
join t2 in myTABLE1List
on t1.ColumnA equals t2.ColumnA
&& t1.ColumnB equals t2.ColumnA
// ... and at this point intellisense is making it very obvious
// I am doing something wrong :(
我如何在 LINQ 中写我的查询? 我做错了什么?