LINQ to Entities does not recognize the method 'Boolean Contains(Int32)' method

c#, entity-framework, linq

Solution

It is not possible to use `Contains` in your EF version, because support for `Contains` was added in EF 4. Either upgrade your EF version (then your code will work without any problems), or use something like manual expression building:

var query = context.studentTable.Where(
    BuildContainsExpression<Student, int>(s => s.StudentID, studentIDs));

Problem

The below exception flown LINQ to Entities does not recognize the method 'Boolean Contains(Int32)' method, and this method cannot be translated into a store expression. while trying to execute the below query ``` List<int> studentIDs = Common.getFilterStudents(); var query = from a in studentTable where studentIDs.Contains(a.StudentID) select a; ``` How can I filter the query using the studentIDs list?

Original source

Related problems