InvalidOperationException: LINQ表达式的GroupByShaperExpression:
fileMovementRepository.GetAll() .Where(fm => repository.GetAll().Select(f => f.Id).Contains(fm.FileId) && fm.TransferredById == userId) .Include(f => f.User).Include(f => f.File).ThenInclude(f => f.Category) .OrderByDescending(f => f.MovedOn) .GroupBy(f => f.FileId) .Select(f=>f.First()) .ToList();
InvalidOperationException: LINQ表达式的GroupByShaperExpression:
fileMovementRepository.GetAll()
.Where(fm => repository.GetAll().Select(f => f.Id).Contains(fm.FileId) && fm.TransferredById == userId)
.Include(f => f.User).Include(f => f.File).ThenInclude(f => f.Category)
.OrderByDescending(f => f.MovedOn)
.GroupBy(f => f.FileId)
.Select(f=>f.First())
.ToList();
在运行时显示以下错误
处理请求时发生未处理的异常。InvalidOperationException: LINQ表达式'GroupByShaperExpression: KeySelector: f.FileId,ElementSelector:EntityShaperExpression: EntityType: FileMovement ValueBufferExpression: ProjectionBindingExpression: EmptyProjectionMember IsNullable: False
无法翻译‘.First()’。以可翻译的形式重写查询,或者通过插入对“AsEnumerable”、“AsAsyncEnumerable”、“ToList”或“ToListAsync”的调用显式切换到客户端计算。有关详细信息,请参阅https://go.microsoft.com/fwlink/?linkid=2101038。Microsoft.EntityFrameworkCore.Query.RelationalSqlTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
InvalidOperationException:未能转换LINQ表达式'GroupByShaperExpression: KeySelector: f.FileId,ElementSelector:EntityShaperExpression: EntityType: FileMovement ValueBufferExpression: ProjectionBindingExpression: EmptyProjectionMember IsNullable: False .First()‘。以可翻译的形式重写查询,或者通过插入对“AsEnumerable”、“AsAsyncEnumerable”、“ToList”或“ToListAsync”的调用显式切换到客户端计算。有关详细信息,请参阅https://go.microsoft.com/fwlink/?linkid=2101038。
在GroupBy
之前使用ToList()
,它将按预期工作。
fileMovementRepository.GetAll() .Where(fm => repository.GetAll().Select(f => f.Id).Contains(fm.FileId) && fm.TransferredById == userId) .Include(f => f.User).Include(f => f.File).ThenInclude(f => f.Category) .OrderByDescending(f => f.MovedOn) .ToList() .GroupBy(f => f.FileId) .Select(f=>f.First()) .ToList();
转 https://cloud.tencent.com/developer/ask/sof/1142225/answer/1594419
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)
2021-07-21 vscode格式化html标签属性不换行(vetur插件)
2021-07-21 VSCode 使用Vetur对vue文件进行格式化
2021-07-21 信息搜集一些总结
2021-07-21 程序员腰突经历分享(中)
2021-07-21 Vue权限路由实现总结
2021-07-21 c++中的静态成员
2021-07-21 Spring 的循环依赖问题