How can I join conditionally in LINQ queries?

Posted by Steve Crane on Stack Overflow See other posts from Stack Overflow or by Steve Crane
Published on 2010-04-07T10:20:11Z Indexed on 2010/04/07 10:23 UTC
Read the original article Hit count: 207

Filed under:
|
|

If I have two tables; Drivers keyed by DriverId and Trips with foreign keys DriverId and CoDriverId, and I want to find all trips where a driver was either the driver or co-driver I could code this in Transact-SQL as

select d.DriverId, t.TripId 
from Trips t inner join Drivers d 
on t.DriverId = d.DriverId or t.CoDriverId = d.DriverId

How could this be coded as a LINQ query?

© Stack Overflow or respective owner

Related posts about LINQ

Related posts about join