如何在linq连接中添加|| (OR)条件
本文关键字:OR 条件 添加 linq 连接 | 更新日期: 2023-09-27 18:14:06
如何将下面的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中实现这一点的正确方法。
对您的意思做一些假设,我建议将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)