我寧願把它簡化以下列方式
(from at in address_types
join a in address
on at.addresstype equals a.addresstype into tt
from ar in tt.DefaultIfEmpty()
where (ar != null && ar.addressid == 24)
select new
{
at.Description,
ar.Address1,
ar.Address2,
ar.City
})
爲什麼我們不需要這種檢查的理由「(JA == NULL) 「是因爲我們已經在這一行限制了我們的設置」(ar!= null & & ar.addressid == 24)「。
同時這個查詢的工作原理,我的POV是,在SQL查詢中,LEFT JOIN也是冗餘的。 http://msdn.microsoft:你會不會因爲你的條件「a.addressid = 24」,所以SQL可以改寫到INNER JOIN和LINQ查詢以及對
(from at in address_types
join a in address
on at.addresstype equals a.addresstype
where at.addressid == 24
select new
{
at.Description,
a.Address1,
a.Address2,
a.City
})
從MSDN一些想法得到空行。 com/en-us/library/bb397895.aspx – 2012-07-13 08:45:56