I have created a query that allows group messages based on the reference number and chose each group's latest record.
var list = _context.Messages.Include(m => m.SenderId).Include(m => m.ReceiverId)
.Where(m => m.Status != MessageStatus.Archived)
.OrderByDescending(m => m.DateAdded)
.GroupBy(m => m.Reference)
.Select(g => g.OrderByDescending(m => m.DateAdded).FirstOrDefault()).ToList();
Can someone suggest how to convert this to EF Core?