gpt4 book ai didi

c# - group by 操作包含无法翻译的表达式

转载 作者:太空宇宙 更新时间:2023-11-03 21:57:59 24 4
gpt4 key购买 nike

它编译正常但是当我尝试遍历 LINQ 查询的结果时我遇到了这样的异常 The group by operation contains an expression that cannot be translated查询是

var query0 = from c in dc.Prices
where Convert.ToDateTime(c.data).CompareTo(left) >= 0
&& Convert.ToDateTime(c.data).CompareTo(right) <= 0
&& c.idsticker.Equals(x)
group c by new { ((DateTime)c.data).Year, ((DateTime)c.data).Month }
into groupMonthAvg
select new
{
years = groupMonthAvg.Key.Year,
months = groupMonthAvg.Key.Month,
prices = groupMonthAvg.Average(i => i.value)
};

group by 函数中哪个表达式是错误的?

最佳答案

试试这个:

var query0 = from c in dc.Prices
let date = Convert.ToDateTime(c.data)
where date.CompareTo(left) >= 0 && date.CompareTo(right) <= 0 && c.idsticker.Equals(x)
group c by new { date.Year, date.Month } into groupMonthAvg
select new
{
years = groupMonthAvg.Key.Year,
months = groupMonthAvg.Key.Month,
prices = groupMonthAvg.Average(i => i.value)
};

关于c# - group by 操作包含无法翻译的表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11423008/

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