var auditAgencyRecords = (from ag in db.Agencies
join ara in db.AuditRuleAccounts on ag.Agency_Id equals ara.AgencyID
join arr in db.AuditRuleResults on ara.AuditRuleAccountID equals arr.AuditRuleAccountID
join are in db.AuditRuleEnterprises on arr.AuditRuleEnterpriseID equals are.AuditRuleEnterpriseID
where (rules.Select(r => r.EnterpriseID).Contains(arr.AuditRuleEnterpriseID))
select new
{
AgencyID = ag.Agency_Id,
AgencyName = ag.Agency_Name,
AuditRuleEnterpriseID = arr.AuditRuleEnterpriseID,
AuditRuleEnterpriseName = are.OverrideDisplayName,
CorrectedDate = arr.CorrectedDate,
NbrDaysToCorrect = arr.NbrDaysToCorrect,
});
所以,我對LINQ to SQL仍然很陌生,我需要幫助弄清楚如何將它變成左外連接,而不是內連接。如何將這些LINQ連接轉換爲左外連接?
從上面的查詢來看,我希望Agencies表中有所有代理,然後右邊的記錄(EnterpriseID,CorrectedDate等)可以爲空,如果沒有記錄存在。
我很確定我需要使用SelectMany,但我可以使用一些指導將這些連接轉換爲左外連接,所以我列出了所有代理然後右邊的可能記錄。
這是什麼?......組加入as ... equals ...到xs = group ...`語法中?我以前沒見過這樣的組,我似乎無法找到任何文檔。 – 2014-08-07 19:43:54