我需要將此SQL格式化爲LINQ2SQL查詢。我有第二次加入的問題(左)。我不想使用嵌套查詢,所以我編寫了SQL的工作。先謝謝你。將sql左連接轉換爲不帶嵌套查詢的linq2sql代碼
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
我應該怎麼改?
**將**想要更正的linq-to-sql代碼帶給**上的非嵌套查詢結果**。 – AgentFire 2013-02-11 15:30:40
@AgentFire - 已更新。 – Cemsha 2013-02-11 15:41:42