12
请帮我开始使用LINQ和GROUP和SUM进行查询。用GROUP和SUM进行LINQ查询
// Query the database
IEnumerable<BestSeller> best_sellers = from bs in (db.MYDATABASE).Take(25)
where bs.COMPANY == "MY COMPANY"
group bs by bs.PRODCODE into g
orderby g.Sum(g.MQTY)
select new BestSeller()
{
product_code = ,
product_description = ,
total_quantity =
};
我想:
- 通过bs.PRODCODE由总和为每个BS
- 定购
- 集团所有结果取前25名的项目从db.MYDATABASE。 PRODCODE
- 公司是“我的公司”
- 然后将数据输入到我的
BestSeller()
对象
我很困惑,因为只要我将group
添加到混合中,我的bs
变量就变得无用了。
这条线真的有效吗? 'product_description = g.Key.DESCRIPTION' –
应该是'g.Key'(对于product_code)和'g.First()。我想这是product_description的描述。 –
请问为什么'g.Sum()'函数中使用'x'? – Luke