c# - Group by 语句无法翻译成 SQL
问题描述
EF Core 3.1 中是否有办法让如下所示的 group by 语句起作用?
.GroupBy(x => x.Id, (id, item) =>
new
{
Id = id,
LastDate = item.Max(z => z.Date)
})
Id 是 auniqueidentifier
并且 Date 是 adatetime2(7)
目前无法将其转换为 SQL 并出现错误
The LINQ expression 'DbSet<Delivery>
.GroupBy(
source: p => p.Id,
keySelector: p => p,
elementSelector: (x, y) => new {
Id = x,
LastDate = y
.Max(z => z.Date)
})' could not be translated. Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly by inserting a call to either AsEnumerable(), AsAsyncEnumerable(), ToList(), or ToListAsync().
解决方案
推荐阅读
- raspberry-pi - 如何通过 I2C 在 Raspberry pi 和 PIC 设备 (PIC16F18325) 之间进行通信
- c# - .NET Core 使用 Azure B2C 身份验证,登录后查找 @User.Identity.UserID 等用户属性
- java - Java 函数变量冲突
- python - ValueError:无法将输入数组从形状(15,15)广播到形状(15)
- ios - 如何在 WebRTC/IOS 上使用麦克风和背景音频(其他应用程序)进行流式传输?
- reactjs - 当主视图导航到登录视图时,如何触发登录的useEffect?
- wordpress - Wordpress 元框不保存和更新
- python - 无法在 Python 中打印 Trie 中的节点
- java - 仅更改所选列时不调用 valueChanged 方法
- elasticsearch - 将 Elasticsearch 索引中的文档替换为字段条件