我想要一个新的查询显示前10名(如果有10个CostCenters),添加字符串出现的数量并创建一个新的CostCenter列表(当它像这样分组时)。
var xxx = (from t in _list_Costs
group t by new { t.Date.Year, t.Date.Month }
into g
select new
{
Year = g.Select(o => o.Date.Year).First(),
Month = g.Select(n => n.Date.Month).First(),
Costs = g.Sum(n => (Decimal)n.Amount),
CostCenter = g.Select(n => n.CostCenter)
}).ToList();
结果应该是:
Year: Month: CostCenter: Quantity:
2015 1 Bananas 5
2015 1 Apples 3
2015 2 Bananas 12
2015 2 Apples 6
2015 2 Lizzards 2
答案 0 :(得分:0)
如果我理解正确,您需要orderby
和take
CostCenter = g.Select(n => n.CostCenter).OrderBy(n => n.SomeField).Take(10)