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 还是很陌生,我需要帮助弄清楚如何将它变成左外连接,而不是内连接。
从上面的查询中,我希望从 Agencies 表中获取所有代理,然后如果不存在记录,则右侧的记录(EnterpriseID、CorrectedDate 等)可以为空,等等。
我相当确定我需要使用 SelectMany,但我可以使用一些指导将这些连接转换为 LEFT OUTER JOINS,所以我有一个所有机构的列表,然后他们可能的记录在右边。