【发布时间】:2022-01-07 06:40:40
【问题描述】:
我有一个 LINQ to Entities 查询用于对数据进行分组并同时添加一些聚合,除了中值计算之外它可以工作。中值是按排好序的列除以 2 计算的(从列中获取中间值)。这是我的例子:
private void button2_Click(object sender, EventArgs e)
{
var query = from t in _database.jon_export
orderby t.businessEmployeeCount
group t by t.county.ToString() into g
where g.Count() > 0
select new
{
County = g.Key,
CountValue = g.Count(),
BusinessEmployeeCount = g.Count(),
BusinessEmployeeAverageValue = g.Average(x => x.businessEmployeeCount),
//Median value from businessEmployeeCount column
BusinessRevenueAverageValue = g.Average(x => x.businessRevenue),
BusinessTurnover=g.Average(x => x.businessTurnover),
BooiqEconomicWellBeing=g.Average(x=>x.booiqEconomicWellBeing)
};
this.dataGridView1.DataSource = query.ToList();
}
【问题讨论】:
标签: c# entity-framework linq grouping