Linq Contains an array of arrays of enums
I want to return a list of tickets that are currently in one of the given statuses. There an array of TicketState enumeration (with values โโOpen, InProgress and Finished).
public IEnumerable<Ticket> ReadTickets(TicketState[] states)
{
return ctx.Tickets.Where(t => states.Contains(t.State)).AsEnumerable();
}
When validating the method, the following exception is thrown:
Cannot compare items of type 'Project.BL.Domain.Ticketing.TicketState []'. Only primitive types, enumeration types, and entity types are supported.
I tried to create a list from an array and use a byte array instead, but I keep getting exceptions.
Does anyone know how I can fix this?
+3
source to share
1 answer
Are you looking for Enumerable.Any ?
return ctx.Tickets.Where(t => states.Any(s => t.State == s)).AsEnumerable();
+3
source to share