基本上,我想做与这里相同的事情:https://stackoverflow.com/a/16274992/4138686,但是在EF Core 3.1.3中使用此答案会给我
System.InvalidOperationException:LINQ表达式'(GroupByShaperExpression: 键选择器:(价格), ElementSelector:(EntityShaperExpression: 实体类型:RetailerRate ValueBufferExpression: (ProjectionBindingExpression:空投影成员) IsNullable:错误 ) ) .OrderByDescending(r => r.CreatedAt)'无法翻译。以一种可以翻译的形式重写查询,或者通过插入对AsEnumerable(),AsAsyncEnumerable(),ToList()或ToListAsync()的调用来显式切换到客户端评估。有关更多信息,请参见https://go.microsoft.com/fwlink/?linkid=2101038。
代码如下:
await _db.RetailerRates
.GroupBy(r => r.Price)
.Select(g => g.OrderByDescending(r => r.CreatedAt).First())
.ToListAsync();
是否有一种方法可以根据日期从EF Core 3.1中的每个组中检索第一个元素?