我有以下 Linq 查询:
List<MonthlySales> monthlySales = (from sale in Sales
group sale by new { sale.DateSold.Month, sale.Product.Shop } into ds
select new MonthlyTitleSales
{
Shop = ds.Select(it => it.Product.Shop).FirstOrDefault(),
Month = ds.Select(it => it.DateSold.Month).FirstOrDefault(),
Year = ds.Select(it => it.DateSold.Year).FirstOrDefault(),
USDNumberItemsSold = ds.Where(it => it.USDCut.HasValue).Where(it => it.USDCut != 0).Count(),
GBPNumberItemsSold = ds.Where(it => it.GBPCut.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, Currency, endDate),
GBPRevenueTotal = PerformCurrencyConversion(0M, ds.Sum(it => it.GBPCut.HasValue ? it.GBPCut.Value : 0), 0M, Currency, endDate),
EURRevenueTotal = PerformCurrencyConversion(0M, 0M, ds.Sum(it => it.EURCut.HasValue ? it.EURCut.Value : 0), Currency, endDate),
}).OrderBy(it => it.DateSold.Month).ToList();
此查询为我提供了一个列表,其中每个列表项中包含以下元素:Shop、Month、Year、Revenue Made
我最终需要做的是计算所有商店每个月的收入中位数,因此我需要以允许我这样做的方式准备好数据。
我认为一种方法可能是按月将此列表分成小列表,但我怀疑这是最有效的解决方案。
有人对此有任何想法吗?
面向需要查看的任何人的每月销售课程:
public class MonthlySales
{
public int Month { get; set; }
public int Year { get; set; }
public Shop Shop { 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; } }
}