如何添加|| (或)linq join的条件

时间:2016-10-19 21:02:23

标签: c# linq

如何将以下SQL查询转换为C#.net

的LINQ查询
Select t1.id,t2.Name
From table1 t1
INNER JOIN table t2
ON ((t1.column3 is null and t1.id = t2.id)
    OR( t.Column3 is NOT NULL and t1.column3 = t3.Column3))
Join tblXYZ  xyz on t1.column4 = xys.columnn2

我在linq查询中首次设置比较后无法添加或条件,请在linq中建议正确的方法。

1 个答案:

答案 0 :(得分:0)

对你的意思作出一些假设,我建议将OR提升到一个联盟:

(from t1 in table1
 join t2 in table2 on t1.Column3 equals t2.Column3
 join xyz in tblXYZ on t1.Column4 equals xyz.column2
 where t1.Column3 != null).Union(
 from t1 in table1
 join t2 in table2 on t1.id == t2.id
 join xyz in tblXYZ on t1.Column4 equals xyz.column2
 where t1.Column3 == null)