There are a bunch of examples of how to make a quasi-left join in Linq here (this, also this, and even this). They all point to joining a handful of parent tables into an "outer" table, then selecting from that table using DefaultIfEmpty()
. Sounds easy enough, so I created this snippet in LinqPad:
dim foo = (
from c in context.Contacts
join p in context.Plants on c.PlantID equals p.PlantID into outer
from o in outer.DefaultIfEmpty()
where p.PlantCode = 2
select c.ContactName, p.PlantName
)
The equivalent SQL statement would be:
SELECT c.ContactName, p.PlantName
FROM Contacts c
LEFT JOIN Plants p ON c.PlantID = p.PlantID
WHERE p.PlantCode = 2
Looks like it should work, but LinqPad keeps stopping on the join...into
line with this error: ')' expected.
Am I doing something wrong? Or is LinqPad losing its mind?