Group By

select sum(summoney) 总额,supplierid from purchase where PurchaseDate>getdate()-300 and supplierid=3
and status<>'未处理' group by supplierid 
 //采购单查询
            var purchaseQuery = _efUnitOfWork.Repository().Table.Where(p =>
                      p.BranchId == branchId && p.PurchaseDate > start && p.PurchaseDate < end && p.SupplierId > 0 && p.Status != "未处理");
            if (supplierId > 0)
            {
                purchaseQuery = purchaseQuery.Where(p => p.SupplierId == supplierId);
            }
            var recoder = (from p in purchaseQuery
                           group new { p.SupplierId, p.SupplierName, p.SumMoney } by new { p.SupplierId, p.SupplierName } into g
                           select (new ReceiveAndPayRecoder
                           {
                               SupplierId = g.Key.SupplierId,
                               SupplierName = g.Key.SupplierName,
                               SumMoney = g.Sum(e => e.SumMoney)
                           })).ToList();

 

你可能感兴趣的:(MVC,C#,代码整洁之道)