问题描述
我上课
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
解决方法
这是我最能解决您的查询的问题。
var rslt =
(
await
(
from d in db.statMonth.Include(f => f.MasterData)
where d.m_turbine_id == IPAddress.Parse(id)
where d.m_date >= frm
group d by new { d.m_date.Month,d.m_date.Year } into g
orderby g.Key.Month
select new
{
Year = g.Key.Year,Date = 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).ToArray(),Countries = g.Select(i => i.Country).ToArray(),}
)
.ToListAsync()
)
.Select(g => new statisticsDaily
{
Year = g.Year
Date = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(g.Date),Production = g.Production,m_wind_speed = g.m_wind_speed,Availability = g.Availability,Comments = String.Join(",",g.Comments),Countries = String.Join(",g.Countries),})
.ToList();
您可以检查一下现在遇到什么错误吗?