public async Task <DonationMatrix> GetDonationMatrixAsync(Expression <Func <Donation, bool> > predicate, PriorityScope scope, CancellationToken cancellationToken = default) { var results = await Donations .AsNoTracking() .Where(d => d.RemovalId == null) .Where(predicate) .Select(d => new { d.DonatedAt.Year, d.DonatedAt.Month, d.CharacterId, d.CopperAmount }) .GroupBy(d => new { d.Year, d.Month, d.CharacterId }) .Select(g => new MonthDonations { CharacterId = g.Key.CharacterId, Donated = g.Sum(d => d.CopperAmount), Month = g.Key.Month, Year = g.Key.Year, }) .OrderBy(md => md.CharacterId) .ThenBy(md => md.Year) .ThenBy(md => md.Month) .ToListAsync(cancellationToken); return(new(results, scope)); }