我有这条线一直运行到我启用 RelationalEventId.QueryClientEvaluationWarning。
在这里,让我们说我想做的是根据他们的最新订单日期对结果(客户)进行排序。
.OrderByDescending(x=>x.orders.Max(y=>y.CreateDate))
在我如下配置上下文后,我意识到 Max() 没有转换为 TSql。
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
base.OnConfiguring(optionsBuilder);
optionsBuilder.ConfigureWarnings(warning =>
{
warning.Throw(RelationalEventId.QueryClientEvaluationWarning);
});
}
错误:
InvalidOperationException: Error generated for warning 'Microsoft.EntityFrameworkCore.Query.QueryClientEvaluationWarning: The LINQ expression 'Max()' could not be translated and will be evaluated locally.
我假设在本地计算最大值不利于获得更好的性能。有没有办法计算 SQL Server 上的最大值?