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:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user