【发布时间】:2012-08-28 09:36:54
【问题描述】:
请帮助我了解如何使用带有 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 =
};
我希望:
- 从 db.MYDATABASE 中获取前 25 项
- 按 bs.PRODCODE 对所有结果进行分组
- 按每个 bs.PRODCODE 的总和排序
- 公司在哪里是“MY COMPANY”
- 然后将数据通过管道传输到我的
BestSeller()对象中
我很困惑,因为只要我将 group 添加到组合中,我的 bs 变量就会变得无用。
【问题讨论】: