【发布时间】:2021-01-01 23:19:17
【问题描述】:
我有课
public class statisticsDaily
{
public string Date { get; set; }
public Nullable<float> Production { get; set; }
public Nullable<float> m_wind_speed { get; set; }
public Nullable<float> Availability { get; set; }
public string Comments { get; set; }
public string TurbineId { get; set; }
public string Countries { get; set; }
}
我需要在某个字段上应用聚合函数,并从我的班级中选择其余字段
var rslt = await (from d in db.statMonth.Include(f=>f.MasterData).Where(d=>d.m_turbine_id == IPAddress.Parse(id) && d.m_date >= frm)
group d by new { d.m_date.Month, d.m_date.Year} into g
select new statisticsDaily
{
Year = g.Key.Year// We can access Year now since we grouped by Year as well
Date = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(g.Key.Month),
Production = g.Sum(s => s.m_energy_prod),
m_wind_speed = g.Average(s => s.m_wind_speed),
Availability = g.Average(s => s.m_availability),
Comments=g.Select(s=>s.Comments).ToString(),
Countries=g.select(i=>i.Country).ToString()
}
).OrderBy(s=>s.Date).ToListAsync();
它给了我错误:
LINQ 表达式 'Select
【问题讨论】:
-
什么是“错误 500”?有没有试过调试代码,看看有没有异常?
-
那是怎么编译的呢?您的代码中有多个错误。
Year未在statisticsDaily上定义,您在分配后缺少,。Comments=g.Select(i=>s.Comments).ToString()使用两个不同的变量名 -
@derpirscher 已编辑,当它想运行 linq 时,它会跳过它
-
跳过它是什么意思。您是否尝试过调试那段特定的代码并检查是否抛出了异常?
-
@derpirscher 因错误而更新,通过 try and catch 得到它
标签: linq asp.net-core