System.InvalidOperationException:无法翻译给定的 'GroupBy' 模式

System.InvalidOperationException : Unable to translate the given 'GroupBy' pattern

我从下面的 group by 子句中得到一个 System.InvalidOperationException。我不确定为什么并且已经调试了一段时间但没有运气。非常感谢您。

var performances = await GeneralModelRepository.GetQueryable<Performance>()
                .Where(x => !x.IsDeleted &&
                    x.ActualDateTime.Date >= now.Date && x.ActualDateTime.Date <= now.AddDays(6).Date)
                .GroupBy(x => x.MovieId)
                .AsNoTracking().ToListAsync();

堆栈跟踪:

Message: 
System.InvalidOperationException : Unable to translate the given 'GroupBy' pattern. Call 'AsEnumerable' before 'GroupBy' to evaluate it client-side.

Stack Trace: 
ShaperProcessingExpressionVisitor.VisitExtension(Expression extensionExpression)
Expression.Accept(ExpressionVisitor visitor)
ExpressionVisitor.Visit(Expression node)
ShaperProcessingExpressionVisitor.ProcessShaper(Expression shaperExpression, RelationalCommandCache& relationalCommandCache, LambdaExpression& relatedDataLoaders)
RelationalShapedQueryCompilingExpressionVisitor.VisitShapedQuery(ShapedQueryExpression shapedQueryExpression)
ShapedQueryCompilingExpressionVisitor.VisitExtension(Expression extensionExpression)
Expression.Accept(ExpressionVisitor visitor)
ExpressionVisitor.Visit(Expression node)
QueryCompilationContext.CreateQueryExecutor[TResult](Expression query)
Database.CompileQuery[TResult](Expression query, Boolean async)

我知道在客户端进行会更容易,但是否可以在查询本身中进行?

只需在 AsNoTracking() 之后添加 Select 语句,如下所示。

var performances = await GeneralModelRepository.GetQueryable<Performance>()
                    .Where(x => !x.IsDeleted &&
                        x.ActualDateTime.Date >= now.Date && x.ActualDateTime.Date <= now.AddDays(6).Date)
                    .GroupBy(x => x.MovieId)
                    .AsNoTracking().Select(x=>x.FirstOrDefault()).ToListAsync();