I need to format this SQL into LINQ2SQL query. I have problem with second join (left). I don't want to use nested queries so I wrote SQL which works. Thank you in advance.
select * from
Accounts a
inner join
Addresses ea on a.GUID = ea.UID
left join
Addresses ea2 on a.GUID = ea2.GUID and AddressTypeID = 2
where
ba.AccountID = 100 and
ea.AddressTypeID = 1
My linq2SQL code is:
var data =
from account in dc.Accounts
join primaryAddress in dc.Addresses on account.GUID equals
primaryAddress.GUID
join secondaryAddress in dc.Addresses on account.GUID equals
secondaryAddress.GUID
into leftSecondaryAddress
from secondaryAddress in
leftSecondaryAddress.Where(
x =>
x.AddressTypeID == 2).DefaultIfEmpty()
where
brokerAccount.AccountID == 100 &&
primaryAddress.AddressTypeID == 1
What should I change?