【发布时间】:2021-02-15 18:08:59
【问题描述】:
我有一个 linq 查询:
var reports = await dbContex.ShoppingListPatientReports
.Where(report => patientIds.Contains(report.PatientId))
.GroupBy(report => new { report.PatientId, RecentDate = DbFunctions.TruncateTime(report.DateCreated) })
.OrderByDescending(g => g.Key)
.ToListAsync();
它返回按复合键(PatientId、RecentDate)降序排序的组。 键:
10004, 2021-02-03
10004, 2021-01-01
10004, 2021-02-02
10002, 2021-01-05
10002, 2021-01-06
我能否以某种方式只获取具有最大键的组(PatientId、RecentDate) 即最近日期的组(在本例中,结果应该是两个组):
10004, 2021-02-03
10002, 2021-01-06
【问题讨论】:
标签: c# entity-framework linq