What is an alternative of the following SQL in Linq to entities ? I am creating a LINQ query in Asp.Net MVC 3 with, EF 4.1:
SELECT Sum(AB开发者_如何学JAVAS([Installment])) AS SumOfPayments FROM tblSchoolAccount
This should work:
decimal SumOfPayments = db.tblSchoolAccounts.Sum(p => Math.Abs(p.Installment));
EDIT
If you REALLY want a query expression, this should work, but I think most developers would say the above is much clearer:
decimal SumOfPayments = (from p in db.tblSchoolAccounts
select Math.Abs(p.Installment)).Sum();
精彩评论