Dot*_*row 2 linq linq-to-entities entity-framework-4
Linq中实体的以下SQL的替代方法是什么?我正在使用EF 4.1在Asp.Net MVC 3中创建LINQ查询:
SELECT Sum(ABS([Installment])) AS SumOfPayments FROM tblSchoolAccount
Run Code Online (Sandbox Code Playgroud)
这应该工作:
decimal SumOfPayments = db.tblSchoolAccounts.Sum(p => Math.Abs(p.Installment));
Run Code Online (Sandbox Code Playgroud)
编辑
如果你真的想要一个查询表达式,这应该可行,但我想大多数开发人员会说上面的内容更清晰:
decimal SumOfPayments = (from p in db.tblSchoolAccounts
select Math.Abs(p.Installment)).Sum();
Run Code Online (Sandbox Code Playgroud)