0

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?

abramlimpin
  • 5,027
  • 11
  • 58
  • 97
  • 1
    I see you have a lot or reputations and certainly know that you have to show the error message . Only after this people can help you. – Serge Nov 14 '20 at 17:20
  • try the updated answer at this question: https://stackoverflow.com/questions/64834181/how-to-use-linq-or-lambda-with-iqueryable-to-groupby-and-get-the-first-last-reco/64837257#64837257 – Ahmed Abd Elmoniem Nov 22 '20 at 13:10

0 Answers0