I have three types that derive from the same base class: BaseEvent.
I display all three types together in a datagrid in my frontend. Need to maintain each items knowledge of what type it is so that I can cast it to the appropriate type when handling it in the front end.
I had it working by converting each set to a list, but I'd like to return IQueryable instead so that it can be more efficiently filtered.
Код: Выделить всё
public override IQueryable GetAllItems()
{
var freestyleEvents = _context.Set()
.Include(ev => ev.Venue)
.Include(ev => ev.EventImage)
.Include(ev => ev.BookingOption)
.Include(ev => ev.Business)
.Include(ev => ev.Tickets!).ThenInclude(ticket => ticket.TicketOption);
var workshopEvents = _context.Set()
.Include(ev => ev.Venue)
.Include(ev => ev.EventImage)
.Include(ev => ev.BookingOption)
.Include(ev => ev.Business)
.Include(ev => ev.Tickets!).ThenInclude(ticket => ticket.TicketOption);
var classNightEvents = _context.Set()
.Include(ev => ev.Venue)
.Include(ev => ev.EventImage)
.Include(ev => ev.BookingOption)
.Include(ev => ev.Business)
.Include(ev => ev.Tickets!).ThenInclude(ticket => ticket.TicketOption);
return freestyleEvents.OfType().Concat(workshopEvents.OfType()).Concat(classNightEvents.OfType());
}
Код: Выделить всё
Expression of type 'System.Linq.IQueryable`1[BaseEvent.Model.Freestyle]' cannot be used for parameter of type 'System.Linq.IQueryable`1[BaseEvent.Model.Workshop]' of method 'System.Linq.IQueryable`1[BaseEvent.Model.Workshop] Concat[Workshop](System.Linq.IQueryable`1[BaseEvent.Model.Workshop], System.Collections.Generic.IEnumerable`1[BaseEvent.Model.Workshop])'
Источник: https://stackoverflow.com/questions/781 ... ived-types