How to select only the records with the highest date in LINQ

前端 未结 5 1147
一向
一向 2020-11-28 03:15

I have a table, \'lasttraces\', with the following fields.

Id, AccountId, Version, DownloadNo, Date

The data looks like this:



        
5条回答
  •  悲&欢浪女
    2020-11-28 03:46

    If you want the whole record,here is a lambda way:

    var q = _context
                 .lasttraces
                 .GroupBy(s => s.AccountId)
                 .Select(s => s.OrderByDescending(x => x.Date).FirstOrDefault());
    

提交回复
热议问题