日期:2014-05-20  浏览次数:20724 次

求一个linq语句怎么写
原表:
login Goods Price Qty Bos Date

meimei 铜 2.12 2 B 2012-12-03
meimei 铜 2.12 5 S 2012-12-03
meimei 铜 2.14 2 S 2012-12-03
meimei 铝 4.63 2 B 2012-12-03
meimei 铝 4.62 2 B 2012-12-03
gege 金 432 6 S 2012-12-03

结果:

login Goods TotalPrice TotalQty BQty SQty Date

meimei 铜 6.38 9 2 7 2012-12-03
meimei 铝 9.25 4 4 0 2012-12-03
gege 金 432 6 0 6 2012-12-03

求高效的linq语句,请大虾帮忙
------最佳解决方案--------------------
失误,用错了函数:
1:如下

                var result = from u in entity.table
                             group u by new { u.login, u.Goods, u.Date } into temp
                             select new
                             {
                                 login = temp.Key.login,
                                 Goods = temp.Key.Goods,
                                 TotalPrice = temp.Sum(c => c.Price),
                                 TotalQty = temp.Sum(c => c.Qty),
                                 BQty = temp.Where(c => c.Key == "B").Sum(c => c.Qty),
                                 SQty = temp.Where(c => c.Key == "S").Sum(c => c.Qty),
                                 Date = temp.FirstOrDefault().Date
                             };



2:如下

                using (NorthwindEntities entity = new NorthwindEntities())
                {
                    var result = from u in entity.table
                                 group u by new { u.login, u.Goods, u.Date } into temp