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

How to transfer list as a parameter to query in Entity Framework?`

Please help solve my problem.

I want get all strings with required id. I have a 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);
Comments