【发布时间】:2020-02-19 17:23:31
【问题描述】:
大家好,又来了
好的,快点,我有一个表格,可以在交易日期旁边存储交易。 正在编写一份报告以检索过去 6 个月内每个月的所有交易总额。
目前我正在使用它来检索一个数组,该数组包含当前月份的最后六个月。
//this guy gets the date of each month till the last 6 month
DateTime[] lastSixMonths = Enumerable.Range(0, 6).Select(i => DateTime.Now.AddMonths(-i)).ToArray();
//here am loopin through each month and calling a service passing the month in loop as parameters
foreach (var month in lastSixMonths)
{
var transAmountforthemonthinLoop = await _transactionsRepository.GetTransactionsAmountSumWithinAMonth(month);
months.Add(month);
monthSum.Add(transAmountforthemonthinLoop);
}
//this is the service i am calling above
public async Task<double> GetTransactionsAmountSumWithinAMonth(DateTime month)
{
var monthString = month.ToString("MM/yyyy");
var trans = await _context.Transactions.Where(c => c.DateCreated.Equals(month) && c.ResponseCode == "00").Select(c => c.Amount).ToListAsync();
var sum = trans.Sum();
return sum;
}
this isnt working as expected
例如,我想要的是。
if the first element in loop is say 2020/02/19
i want to go to my transactions table and sum all the transactions that has 2020/02 ie february as its months. and a responseCode of 00 which is successfl payment
Please any assistance will be appreciated.
``
this
【问题讨论】:
-
Transactions表中DateCreated的格式是什么?它只是 MM/yyyy 格式还是其他格式?你能发布示例数据吗?
标签: c# .net linq asp.net-core