开发者

C# Expressions.How to get Sum (Amount) for last month?

I hava a Transaction datatable with "Amount" field.

I wan开发者_如何转开发t to get Sum (Amount) for 7 days

How can I do it in C# expression?

Thank you


I assume your transaction table is called 'Transaction' and have a 'Date' field;

DateTime lastWeek = DateTime.Now.Subtract(new TimeSpan(7,0,0,0));
var amountSumLastWeek = (from t in Transaction
                        where t.Date >= lastWeek
                        select t.Amount).Sum();

EDIT: Of course const in C# means compile time constant and TimeSpan does not have optional parameters, so I have update the code

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜