noobprogrammer noobprogrammer - 1 year ago 96
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]


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


Answer Source

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);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download