I have the following problem I’m not sure how to address.
I need to paginate two groups of items (ex Cars and Motorcycles). I need a single list sorted alphabetically, which when clicked is directed to a information page for the item. This is shown in groups of 10 with a back/next button.
My actual classes have very different sets of properties. I don’t want to have a single class for both cars and motorcycles.
Both items have an Id, Name, and Description property, but then the remaining properties are unique (whether it’s a Car or Motorcycle item).
What is the best way to group the two lists, sort alphabetically, and then pick the desired items (such as items 11-20 from the merged list)? Right now I am converting all items to a DisplayItem class by doing the following (which works) but is not ideal for large groups of items.
IEnumerable<DisplayItem> entities = cars.Select(b => new DisplayItem(b)).Union(motorcycles.Select(a => new DisplayItem(a))).Skip(10).Take(10);
What would be the correct way to do this?
Thanks!
You could create an interface that both classes implement that contains the sortable property: