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


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


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