I'm trying to convert an SQL query
to Linq
containing several left outer joins, but I'm encountering an odd situation.
The relevant part of my SQL is:
SELECT * FROM dbo.SessionDetails as sd
left outer join dbo.VoipDetails as vd on vd.SessionIdTime = sd.SessionIdTime and vd.SessionIdSeq = sd.SessionIdSeq
left outer join dbo.Gateways as fgw on vd.FromGatewayId = fgw.GatewayId
My Linq query so far is:
var query = from sd in dbo.SessionDetails
join vd in dbo.VoipDetails on new { sd.SessionIdTime, sd.SessionIdSeq } equals new { vd.SessionIdTime, vd.SessionIdSeq } into sdvd
from v in sdvd.DefaultIfEmpty()
join fgw in dbo.Gateways on vd.FromGatewayId equals fgw.GatewayId into sdgw
from g in sdvd.DefaultIfEmpty()
select sd;
I'm getting an error mark on vd.FromGatewayId
telling me that The name 'vd' is not in scope on the left side of 'equals'. Consider swapping the expressions on either side of 'equals'.
However, if I do swap sides with gw.GatewayId
then I get the same error message for both vd
and gw
.
Can someone suggest the correct syntax here?
Please bear in mind I have several more left-joins to add after I get the basic syntax down.