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
精彩评论