我需要将此 SQL 格式化为 LINQ2SQL 查询。我在第二次加入时遇到问题(左)。我不想使用嵌套查询,所以我编写了有效的 SQL。先感谢您。
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
我的 linq2SQL 代码是:
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
我应该改变什么?