Sameera Athukorala
Sameera Athukorala

Reputation: 1

Filter query results by a list of values

 questionnairs = from q in dbContext.AuditQuestionnaires
                                   .Include("Company")
                                where q.Company != null && q.Company.RecordID == companyId
                                select q;

im getting some result set using this query, i have set of ids in a integer list, in the questionnaires result set; there is a id called "recordId", basically I need to take records which resultSet's record id only if exist in my integer list,

i was trying to do something like this but it failed

     for (int x = 0; x < RecordIds.Count; x++)

                    {
                        var id = RecordIds[x];
                        questionnairesList = from q in dbContext.AuditQuestionnaires
                                   .Include("Company")
                                        where q.Company != null && q.Company.RecordID == companyId && q.RecordID == id
                                        select q;

                       


                    }

Upvotes: 0

Views: 74

Answers (1)

Reza Esmaeli
Reza Esmaeli

Reputation: 170

you can use Contains

questionnairs = from q in dbContext.AuditQuestionnaires
                 .Include("Company")
                  where q.Company != null &&
                        q.Company.RecordID == companyId &&
                        RecordIds.Contains(q.RecordID) 
                  select q;

Upvotes: 2

Related Questions