gpt4 book ai didi

c# - 实体核心 2.0.3 异常 : must be reducible node

转载 作者:行者123 更新时间:2023-12-05 04:04:35 27 4
gpt4 key购买 nike

我正在尝试将以下 sql 查询转换为 EF

SQL查询

Select  Sum([KiloWatt]) as 'Sum',
Min([KiloWatt]) as 'Min',
Max([KiloWatt]) as 'Max',
Sum([KiloWatt])/COUNT([KiloWatt]) as 'Average',
CONVERT(date, [DateTime])
from OneHourElectricitys
where [DateTime] < SYSDATETIME()
group by CONVERT(date, [DateTime])

EF代码

var analytics = await _analyticsRepository.Query().Where(x => x.DateTime.Subtract(DateTime.Today).Days < 0)
.GroupBy(x => x.DateTime.Date)
.Select(x => new
{ DateTime = x.Key,
Max = x.Max(y => y.KiloWatt),
Min = x.Min(y => y.KiloWatt),
Avg = x.Sum(y => y.KiloWatt)/ x.Count(),
Sum = x.Sum(y => y.KiloWatt)
})
.ToListAsync();

堆栈跟踪:-

System.ArgumentException: must be reducible node at System.Linq.Expressions.Expression.ReduceAndCheck() at System.Linq.Expressions.Expression.ReduceExtensions()

我做错了吗?

-- 更新--

以下 2 个 EF 查询运行良好,但组合它们会出现错误。

var analytics = await _analyticsRepository.Query().Where(x => x.DateTime.Subtract(DateTime.Today).Days < 0)

var analytics = await _analyticsRepository.Query().GroupBy(x => x.DateTime.Date)
.Select(x => new
{ DateTime = x.Key,
Max = x.Max(y => y.KiloWatt),
Min = x.Min(y => y.KiloWatt),
Avg = x.Sum(y => y.KiloWatt)/ x.Count(),
Sum = x.Sum(y => y.KiloWatt)
})
.ToListAsync();

最佳答案

如 Ivan Stoev 所述,此问题的正确解决方案是升级到 EF Core 2.1.3

关于c# - 实体核心 2.0.3 异常 : must be reducible node,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52464855/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com