Skip to content

Commit

Permalink
VCST-846: Fix First or FirstOrDefault operator without OrderBy (#420)
Browse files Browse the repository at this point in the history
fix: The query uses the 'First'/'FirstOrDefault' operator without 'OrderBy' and filter operators. This may lead to unpredictable results.
  • Loading branch information
OlegoO authored Jun 6, 2024
1 parent 5961e52 commit 47bcff9
Showing 1 changed file with 2 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ protected virtual Task<decimal> CalculateOrderAmount(DateTime startDate, DateTim
return repository.InPayments
.Where(x => x.CreatedDate >= startDate && x.CreatedDate <= endDate && !x.IsCancelled && x.Currency == currency)
.GroupBy(x => 1, (key, result) => result.Sum(x => x.Sum))
.OrderBy(x => x)
.FirstOrDefaultAsync();
}

Expand Down Expand Up @@ -176,6 +177,7 @@ protected virtual Task<decimal> CalculateAvgOrderValue(DateTime start, DateTime
return repository.CustomerOrders
.Where(x => x.CreatedDate >= start && x.CreatedDate <= end && x.Currency == currency)
.GroupBy(x => 1, (key, result) => result.Average(x => x.Total))
.OrderBy(x => x)
.FirstOrDefaultAsync();
}
}
Expand Down

0 comments on commit 47bcff9

Please sign in to comment.