我有一个视图,我存储未按时返回的书籍的滞纳金,这是我在控制器操作中的方式:
[HttpPost()]
public ActionResult DisplayTotalBalance(string id)
{
DataContext db = new DataContext();
var totalLateFee = (from p in db.vwCustomer.Where(a => a.CustomerId == id)
group p by p.LateFee into g
select g.Key).FirstOrDefault();
return Json(new { totalLateFee });
}
在我存储滞纳金的vwCustomer中,客户可能会列出许多滞纳金。对于例如
CustomerId LateFee
J101 5.0
P202 6.0
J101 2.0
P203 5.0
J101 5.0
如何为J101汇总所有LateFee并返回控制器操作?
答案 0 :(得分:3)
(from p in db.vwCustomer.Where(a => a.CustomerId == id) select p.LateFee).sum();