我有以下SQL查詢: -如何實現一個左外連接的實體框架
select distinct * from dbo.Profiles profiles
left join ProfileSettings pSet on pSet.ProfileKey = profiles.ProfileKey
left join PlatformIdentities pId on pId.ProfileKey = profiles.Profilekey
我需要將其轉換爲LinqToEntities表達。我試過以下內容: -
from profiles in _dbContext.ProfileSet
let leftOuter = (from pSet in _dbContext.ProfileSettingSet
select new
{
pSet.isInternal
}).FirstOrDefault()
select new
{
profiles.ProfileKey,
Internal = leftOuter.isInternal,
profiles.FirstName,
profiles.LastName,
profiles.EmailAddress,
profiles.DateCreated,
profiles.LastLoggedIn,
};
上面的查詢工作正常,因爲我沒有考慮第三個表「PlatformIdentities」。單一的左外連接與我上面所做的一樣。我如何包含PlatformIdentities(第三張表)?我基本上想要將我在本文開頭指定的SQL查詢(這正是我所需要的)轉換爲LinqToEntities。
感謝
什麼是'profiles.ProfileSettings'和'profiles.PlatformIdentities'的基數? – 2010-03-31 12:41:15
這兩個表與他們的父表「Profiles」共享一對多關係。他們之間沒有任何基數。 – user206736 2010-03-31 17:04:21
恩,好吧,但是你只是想抓住許多(每個問題中的LINQ)的第一個記錄?你想要哪張唱片? – 2010-03-31 18:47:47