Private
Public Access
1
0

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 <noreply@anthropic.com>
This commit is contained in:
Catherine Renelle
2026-02-09 00:22:34 -05:00
parent 10bbca84be
commit edc32367d4
+1 -1
View File
@@ -55,7 +55,7 @@ public class DashboardService : IDashboardService
.Include(t => t.Category) .Include(t => t.Category)
.Where(t => t.Account.UserId == userId && t.Date >= startOfMonth && t.Amount < 0 && !t.IsVoid && t.CategoryId.HasValue) .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 }) .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) .OrderByDescending(c => c.Amount)
.Take(5) .Take(5)
.ToListAsync(); .ToListAsync();