Reputation:
How can I represent the following LEFT JOIN
in Entity Framework?
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)
For AND
s I know I can use complex anonymous types and EQUALS
but I can't figure out how to handle OR
s?
Upvotes: 1
Views: 330
Reputation: 10486
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()
}
You can ignore DefaultIfEmpty
depending on your need.
Upvotes: 2