-1

I have an entity like the following :

class Serial {
    public int Id { get; set; }
    public string No { get; set; }
}

what I have to get is a list of serials by a list of serial ids, but continuously I get the error :

 Unable to create a constant value of type ProjectName.Models.Serial. Only primitive types or enumeration types are supported.

this is what I've written so far :

List<Serial> serials = _ctx.Serials.Where(s => sList.Any(ss => ss.Id == s.Id)).ToList();

and

List<Serial> serials = _ctx.Serials.Where(s => sList.Select(ss => ss.Id).Contains(s.Id)).ToList();
Hooman L
  • 151
  • 2
  • 8

1 Answers1

0

It should be as simple as this

var ids =  List<int> { 324,54,234,645};

Var serialized = _ctx.Serials.Where(s => ids.Contains(s.Id)).ToList();

Enumerable.Contains Method (IEnumerable, TSource)

Determines whether a sequence contains a specified element by using the default equality comparer.

TheGeneral
  • 79,002
  • 9
  • 103
  • 141