1

如何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)

对于ANDs,我知道我可以使用复杂的匿名类型,EQUALS但我不知道如何处理ORs?

4

1 回答 1

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您可以根据需要忽略。

于 2013-10-27T20:16:49.293 回答