简体   繁体   English

如何在以下LINQ to SQL Query中编写“Where”子句?

[英]How can I write the “Where” clause in the following LINQ to SQL Query?

I'm working on the following LINQ query: 我正在处理以下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();
    }
}

You can see that I'm passing in an IEnumerable rules. 你可以看到我传入了IEnumerable规则。 Each AuditRule object that I pass in has a property called "ID". 我传入的每个AuditRule对象都有一个名为“ID”的属性。

What would my where clause look like for this query if I want to say, only return the records where the table column AuditRuleEnterprise.AuditID matches any one of the ID's in my rules "ID" property (the objects I've passed into the method)? 如果我想说的话,我的where子句对于这个查询会是什么样子,只返回表列AuditRuleEnterprise.AuditID匹配我的规则“ID”属性中的任何一个ID的记录(我传递给方法的对象) )?

Try: 尝试:

.Where(rules.Select(r => r.ID).Contains(arr.AuditRuleEnterpriseID.AuditID))

or, in query syntax 或者,在查询语法中

where rules.Select(r => r.ID).Contains(arr.AuditRuleEnterpriseID.AuditID)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM