概述
var data7 = (
from s in data_f2
join d1 in data_co on s.FORECASTTIME equals d1.FORECASTTIME
join d2 in data_NO2 on s.FORECASTTIME equals d2.FORECASTTIME
join d3 in data_SO2 on s.FORECASTTIME equals d3.FORECASTTIME
join d4 in data_O3 on s.FORECASTTIME equals d4.FORECASTTIME
join d5 in data_O38H on s.FORECASTTIME equals d5.FORECASTTIME
join d6 in data_PM10 on s.FORECASTTIME equals d6.FORECASTTIME
join d7 in data_PM25 on s.FORECASTTIME equals d7.FORECASTTIME
select new
{
REGIONCODE = s.REGIONCODE,
MONITORTIME = s.MONITORTIME,
FORECASTTIME = s.FORECASTTIME,
//REGIONNAME = s.REGIONNAME,
CO = (decimal)d1.CO,
NO2 = (short)d2.NO2,
SO2 = (short)d3.SO2,
O3 = (short)d4.O3,
O38H = (short)d5.O38H,
PM10 = (short)d6.PM10,
PM25 = (short)d7.PM25
}).OrderBy(a => a.FORECASTTIME).ToList();
其他信息: 无法创建“匿名类型”类型的常量值。此上下文仅支持基元类型或枚举类型。
从网上查的解决方法是“把查询调整下位置”(d1的当中还有一个实体,不是基元类型。)
如果这里是一个join的话,这个方法可行,改成: from s in data_co
join d1 in data_f2 on s.FORECASTTIME equals d1.FORECASTTIME
但现在有多个join连接,就不好办了
从头到尾捊了一遍,data_f2后添加.OrderBy(t => t.FORECASTTIME).ToList()解决了。但具体原理不明
var data_f2 = (
from s in avgStation
join d in data_f1 on s.STATIONCODE equals d.STATIONCODE
select new
{
REGIONCODE = s.REGIONCODE,
MONITORTIME = d.MONITORTIME,
FORECASTTIME = d.FORECASTTIME,
CO = (decimal)d.CO,
NO2 = (short)d.NO2,
O3 = (short)d.O3,
O38H = (short)d.O38H,
PM10 = (short)d.PM10,
PM25 = (short)d.PM25,
SO2 = (short)d.SO2
}
).GroupBy(t => new { t.REGIONCODE, t.MONITORTIME, t.FORECASTTIME }).Select(s => new
{
s.Key.REGIONCODE,
s.Key.MONITORTIME,
s.Key.FORECASTTIME,
CO = s.Average(x => x.CO),
NO2 = s.Average(x => x.NO2),
O3 = s.Average(x => x.O3),
O38H = s.Average(x => x.O38H),
PM10 = s.Average(x => x.PM10),
PM25 = s.Average(x => x.PM25),
SO2 = s.Average(x => x.SO2)
});
最后
以上就是朴素中心为你收集整理的linq无法创建“匿名类型”类型的常量值;此上下文仅支持基元类型或枚举类型的全部内容,希望文章能够帮你解决linq无法创建“匿名类型”类型的常量值;此上下文仅支持基元类型或枚举类型所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复