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) } ;