From edc32367d4b349a2d25bf1bd0dc8ff50acb596d2 Mon Sep 17 00:00:00 2001 From: Catherine Renelle <32781029+catrenelle@users.noreply.github.com> Date: Mon, 9 Feb 2026 00:22:34 -0500 Subject: [PATCH] Fix Dashboard query: replace Math.Abs with negation in GroupBy Math.Abs() inside a GroupBy().Select() cannot be translated to SQL by EF Core. Since the query already filters for Amount < 0, negating the sum produces the same result and translates cleanly. Co-Authored-By: Claude Opus 4.6 --- src/Purrse.Api/Services/DashboardService.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Purrse.Api/Services/DashboardService.cs b/src/Purrse.Api/Services/DashboardService.cs index 54fb0ec..80e10eb 100644 --- a/src/Purrse.Api/Services/DashboardService.cs +++ b/src/Purrse.Api/Services/DashboardService.cs @@ -55,7 +55,7 @@ public class DashboardService : IDashboardService .Include(t => t.Category) .Where(t => t.Account.UserId == userId && t.Date >= startOfMonth && t.Amount < 0 && !t.IsVoid && t.CategoryId.HasValue) .GroupBy(t => new { t.CategoryId, CategoryName = t.Category!.Name }) - .Select(g => new CategorySpending(g.Key.CategoryName, Math.Abs(g.Sum(t => t.Amount)), 0, null)) + .Select(g => new CategorySpending(g.Key.CategoryName, -g.Sum(t => t.Amount), 0, null)) .OrderByDescending(c => c.Amount) .Take(5) .ToListAsync();