linq 多表分组查询统计

var q1 = from orderitem in q2
                     join pd in _iProductDetailContract.Entities on orderitem.ProductDetailId equals pd.Id
                     join pm in ProductMainContract.Entities on pd.ProductMainId equals pm.Id
                     join user in UserContract.Entities on pm.BuyerId equals user.Id
                     into orderItemBuyer
                     from user in orderItemBuyer.DefaultIfEmpty()
                     group new { orderitem.Price, orderitem.Num }
                     by new { orderitem.ProductDetailId, orderitem.Name, orderitem.Size, orderitem.Price, pm.AliasName, BuyerName = user.Name }
                     into g
                     orderby g.Sum(p => p.Num) descending
                     select new
                     {
                         ProductDetailId = g.Key.ProductDetailId,
                         Name = g.Key.Name,
                         Size = g.Key.Size,
                         AliasName = g.Key.AliasName,
                         BuyerName = g.Key.BuyerName,
                         Num = g.Sum(p => p.Num),
                         Price = g.Key.Price,
                         TotlePrice = g.Sum(p => p.Num * p.Price)
                     }
                     ;

 

posted @ 2016-06-09 00:16  shiningrise  阅读(2147)  评论(0编辑  收藏  举报
// 侧边栏目录 // https://blog-static.cnblogs.com/files/douzujun/marvin.nav.my1502.css