noobprogrammer noobprogrammer - 3 months ago 11
ASP.NET (C#) Question

how to transfer list as a parameter to query entity framework

Please help solve my problem.

I want get all strings with required id.

I have List with id.

Example = [1,2,3,4,5]

Query:

db.Sites.Where(c => c.Id == /*{get list this}*/).Select(c => c.Name).FirstOrDefault()


Thanks

Answer

Use Contains extension method:

var list=new List<int>{1,2,3,4,5};
var query= db.Sites.Where(c => list.Contains( c.Id)).Select(c => c.Name);