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

linq表达式的转换,谢谢
//var query = from q in
// (
// from p in bookcontext.book
// group p by new { p.author} into g
// select g)
// select new { q.Key, total = q.Sum(x => x.price) };

我想按照作者来分组,分别计算每个作者写书的价格的总和


请问上述linq表达式如何用下面的方式来写

var query = bookcontext.book.GroupBy(x => x.author) //接下来该如何写,谢谢


------解决方案--------------------
var query = from p in bookcontext.book 
group p by p.author into g 
select new { g.Key, total = g.Sum(p => p.price) };
------解决方案--------------------
楼主所的是不是这个啊
 var result= books.GroupBy(b=>b.Author).Select(p=>new {Key=p.Key,Total=p.Sum(pp=>pp.Price)});
------解决方案--------------------
探讨
楼主所的是不是这个啊
var result= books.GroupBy(b=>b.Author).Select(p=>new {Key=p.Key,Total=p.Sum(pp=>pp.Price)});

相关资料更多>