使用Entity Framework Core 2.2,我有以下查询:
l[j]=3
这样查询在本地进行评估,并且我得到消息:
var user = await context.Users.AsNoTracking()
.Include(x => x.Lessons).ThenInclude(x => x.LessonLevel)
.FirstOrDefaultAsync(x => x.Id == userId);
var lessons = context.Lessons.AsNoTracking();
.Where(x => x.LessonLevelId < user.Lessons.Max(y => y.LessonLevelId));
如何使该查询在服务器上评估?
更新
基于DavigG的答案,我使用以下方法进行工作:
The LINQ expression 'Max()' could not be translated and will be evaluated locally.'
我知道以下内容在本地评估,但不应该在服务器上评估?
var maxLessonLevelId = user.Lessons.Max(y => y.LessonLevelId););
var lessons = context.Lessons.AsNoTracking();
.Where(x => x.LessonLevelId < maxLessonLevelId);
是否可以使用在服务器上评估的子查询?
答案 0 :(得分:2)
获取最大值作为单独的查询,例如:
var maxLessonLevelId = user.Lessons.Max(y => y.LessonLevelId);
然后您就可以像这样上课:
var lessons = context.Lessons.AsNoTracking()
.Where(x => x.LessonLevelId < maxLessonLevelId);