开发者

Sum(ABS(col)) in LInq

开发者 https://www.devze.com 2023-02-21 20:44 出处:网络
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:

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();   
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号