【发布时间】:2010-10-05 07:38:33
【问题描述】:
在两列上连接表格很容易
from t1 in table1
join t2 in table2
on new { KEY1 = t1.TB1Key1, KEY2 = t1.TB1Key2 }
equals new { KEY1 = t2.TB2Key1, KEY2 = t2.TB2Key2 }
select new { t1 , t2}
但是如果我想要一个 OR 条件怎么办? SQL 将如下所示:
select * from table1 t1
inner join table2 t2
on t1.TB1Key1 = t2.TB2Key1 OR t1.TB1Key2= t2.TB2Key2
但在 EF 中找不到方法,
在我的情况下 t2.TB1Key 应该等于 t1.TB1Key1 或 t1.TB1Key2 如果 t1.TB1Key1 为空
就这样解决了:
from t1 in table1
join t2 in table2
on new { KEY = t1.TB1Key1 ?? t1.TB1Key2 }
equals new { KEY = t2.TB2Key}
select new { t1 , t2}
但仍然想知道是否可以在连接条件中使用 OR
【问题讨论】:
标签: linq join entity-framework-4