开发者

Sum(ABS(col)) in LInq

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜