I have the following
IList<Project> projects = (from update in dbContext.TicketUpdates
where update.TicketUpdatesEmployeeID == Profile.EmployeeID
orderby update.TicketUpdatesEndDate descending
select update.Ticket.Project).Distinct().ToList();
I understand that Distinct() doesn’t guarantee order, but I can’t reorder it afterwards because the projection loses the field I”m using to order. How can I work around this?
I think your best bet is to post process to preserve ordering:
Or you could abuse
GroupBy:By using
GroupByacrossuu.Ticket.Projecteach update will be grouped by their associated project. If you have 10 projects and 30 updates spread amongst them, you’ll have 10 groups–one per project–in the output of that stage. Next, we order the groups by their newest end date which preserves the descending order you were looking for. Finally, we select the key from eachIGroupingwhich is the project.