0

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

marc_s
  • 704,970
  • 168
  • 1,303
  • 1,425

2 Answers2

1

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);
octavioccl
  • 37,218
  • 8
  • 83
  • 98
1

Try

db.Sites.Where(c => list.Contains(c.Id)).Select(c => c.Name).ToArray();

This should return all the names as an array with matching Ids in the list.

Anil Goel
  • 261
  • 1
  • 8