我希望能够获得过去 12 个月的销售额,按月分组。这是我到目前为止所拥有的:
类定义:
public DateTime DateSold { get; set; }
public int Month { get; set; }
public int USDNumberItemsSold { get; set; }
public int GBPNumberItemsSold { get; set; }
public int EURNumberItemsSold { get; set; }
public int TotalNumberItemsSold { get { return USDNumberItemsSold + GBPNumberItemsSold + EURNumberItemsSold; } }
public decimal USDRevenueTotal { get; set; }
public decimal GBPRevenueTotal { get; set; }
public decimal EURRevenueTotal { get; set; }
public decimal OverallEarnings { get { return USDRevenueTotal + GBPRevenueTotal + EURRevenueTotal; } }
我的 Linq 查询如下:
List<MonthlySales> monthlySales = (from sale in Sales
orderby sale.DateSold descending
group sale by sale.DateSold.Month into ds
select new MonthlySales
{
DateSold = ds.Key,
USDNumberItemsSold = ds.Where(it => it.USDCut.HasValue).Where(it => it.USDCut != 0).Count(),
GBPNumberItemsSold = ds.Where(it => it.GBPrCut.HasValue).Where(it => it.GBPCut != 0).Count(),
EURNumberItemsSold = ds.Where(it => it.EURCut.HasValue).Where(it => it.EURCut != 0).Count(),
USDRevenueTotal = PerformCurrencyConversion(ds.Sum(it => it.USDCut.HasValue ? it.USDCut.Value : 0), 0M, 0M, reportRequest.BaseCurrency, endDate),
GBPRevenueTotal = PerformCurrencyConversion(0M, ds.Sum(it => it.GBPCut.HasValue ? it.GBPCut.Value : 0), 0M, reportRequest.BaseCurrency, endDate),
EURRevenueTotal = PerformCurrencyConversion(0M, 0M, ds.Sum(it => it.EURCut.HasValue ? it.EURCut.Value : 0), reportRequest.BaseCurrency, endDate),
}).Take(12).ToList();
我收到以下错误:
无法将类型“int”隐式转换为“System.DateTime”
因为显然 DateTime.Now.Month 是一个整数。
我尝试使用以下内容:
Month = ds.Key
其中“月份”是一个整数。这没关系,但出于显示目的,我没有年份或类似的东西。
任何人都可以提供任何建议吗?
谢谢。