c# - 使用正确加载的列表对象时接收到 LINQ 表达式 x 无法翻译错误
问题描述
我有以下List
对象,它正确加载了数据库中的有效值:
List<AssessmentItem> assessmentItems =
_context.AssessmentItems
.Include(ai => ai.Assessment).ThenInclude(assess => assess.Evaluator)
.Where(ai => ai.IsActive &&
ai.Assessment.SubmissionId == submissionId &&
ai.Assessment.RubricId == rubricId)
.ToList();
然后我需要assessmentItems
在另一个 LINQ 语句中使用这个列表对象。我在下面提供了assessmentItems
使用的部分代码。
....
Description = ri.Description,
Abbreviation = ri.Abbreviation,
RubricId = ri.RubricId,
RubricItemCategoryId = ri.RubricItemCategoryId,
CurrentScores = assessmentItems
.Where(aitem => aitem.RubricItemId == ri.Id)
.Select(aitem => new AssessmentItemDTO
{
Id = aitem.Id,
EvaluatorName = aitem.Assessment.Evaluator.FirstName + " " + aitem.Assessment.Evaluator.LastName,
EvaluatorId = aitem.Assessment.EvaluatorId,
CurrentScore = aitem.CurrentScore
}).ToList(),
由于某种原因,我收到以下错误:
'aitem'
无法翻译LINQ 表达式。以可翻译的形式重写查询,或通过插入对“AsEnumerable”、“AsAsyncEnumerable”、“ToList”或“ToListAsync”的调用显式切换到客户端评估
我检查了 SO 中的其他相关帖子,但是我找不到适合我的案例的解决方案。我正在使用最新版本的 EF Core。有什么帮助吗?
解决方案
推荐阅读
- tree - 从 n-ary Tree 中找到最大和使得没有两个元素是相邻的
- google-cloud-platform - 列出 Google Cloud 上提供的所有机器类型
- c# - 如何在 SQL Server 2005 和 SQL Server 2019 之间使用 C# 监控应用程序
- android - 使用 Retrofit + Kotlin Flow 处理错误的优雅方式
- python - Mongoengine:使用 __not__contains 但使用列表而不是字符串进行查询
- javascript - D3.js Canvas Spectrogram - 白线和图像拉伸
- perl - 如何获取当前运行的 Perl 脚本的名称?
- python - Python请求无法下载文件
- python - 用于触摸屏的 PyAutoGUI
- php - 更新数据库列加一(列+1)时出错