我正在处理以下LINQ查询:
public void GetAuditRuleAgencyRecords(IEnumerable<Entities.AuditRule> rules)
{
using (LinqModelDataContext db = new LinqModelDataContext())
{
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
select new
{
AgencyID = ag.Agency_Id,
AgencyName = ag.Agency_Name,
AuditRuleEnterpriseID = arr.AuditRuleEnterpriseID,
CorrectedDate = arr.CorrectedDate,
NbrDaysToCorrect = arr.NbrDaysToCorrect,
}).ToList();
}
}
你可以看到我传入IEnumerable规则。我传入的每个AuditRule对象都有一个名为“ID”的属性。
如果我想说的话,我的where子句对于这个查询会是什么样子,只返回表列AuditRuleEnterprise.AuditID与我的规则“ID”属性中的任何一个ID匹配的记录(我通过的对象)进入方法)?
答案 0 :(得分:4)
尝试:
.Where(rules.Select(r => r.ID).Contains(arr.AuditRuleEnterpriseID.AuditID))
或者,在查询语法
中where rules.Select(r => r.ID).Contains(arr.AuditRuleEnterpriseID.AuditID)