【发布时间】:2022-01-18 12:49:58
【问题描述】:
我有一个来自下面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)
我知道在客户端执行它会更容易,但是否可以在查询本身中执行它?
【问题讨论】:
-
这能回答你的问题吗? LINQ group by in Entity Framework Core 3.1
-
其实这个服务器端的 GropBy 没有任何意义,因为你无论如何都要检索所有记录。
标签: c# linq entity-framework-core