I have two columns as Date
and PersonInCharge
, I want to sort the list by descending by date then return the list of ONLY person's name without duplicates. I used Distinct()
to filter the final name list but I don't know why the list order is always alphabetical instead of descending date.
Here is my code so far:
IList<string> model.StaffNames = await _context.FarmDiary
.Select(f => new { f.PersonInCharge, f.Date })
.OrderByDescending(x => x.Date)
.Select(x => x.PersonInCharge)
.Distinct()
.ToListAsync();