#19775 fixed get user data by applying OrderBy after counting (#19776)

* #19775 fixed get user data by applying OrderBy after counting

* Apply suggestions from code review

---------

Co-authored-by: Andy Butland <abutland73@gmail.com>
This commit is contained in:
Markus Johansson
2025-07-23 11:33:49 +02:00
committed by GitHub
parent 5e68bf7c21
commit 73c995c8ec

View File

@@ -44,13 +44,14 @@ internal sealed class UserDataRepository : IUserDataRepository
sql = ApplyFilter(sql, filter);
}
// Fetching the total before applying OrderBy to avoid issue with count subquery.
var totalItems = _scopeAccessor.AmbientScope?.Database.Count(sql!) ?? 0;
sql = sql.OrderBy<UserDataDto>(dto => dto.Identifier); // need to order to skiptake
List<UserDataDto>? userDataDtos =
await _scopeAccessor.AmbientScope?.Database.SkipTakeAsync<UserDataDto>(skip, take, sql)!;
var totalItems = _scopeAccessor.AmbientScope?.Database.Count(sql!) ?? 0;
return new PagedModel<IUserData> { Total = totalItems, Items = DtosToModels(userDataDtos) };
}