如何在实体框架中表示以下LEFT JOIN
?
SELECT * FROM a
LEFT JOIN b ON
(a.UserId = b.Field1 AND b.Field2 = SOME_VARIABLE)
OR (a.UserId = b.Field2 AND b.Field1 = SOME_VARIABLE)
对于AND
我知道我可以使用复杂的匿名类型和EQUALS
,但我无法弄清楚如何处理OR
?
答案 0 :(得分:2)
var query = from a in context.aTable
select new {
A = a,
B = (from b in context.bTable
where (a.UserId == b.Field1 && b.Field2 == SOME_VARIABLE) ||
(a.UserId == b.Field2 && b.Field1 == SOME_VARIABLE)
select b
).DefaultIfEmpty()
}
您可以根据需要忽略DefaultIfEmpty
。