Fix tracked reference queries for SqlServer (#16020)

* Fixed issue with SqlServer and optimized queries to not do the actual paging if total count is 0

* Cleanup

---------

Co-authored-by: Elitsa <elm@umbraco.dk>
This commit is contained in:
Bjarke Berg
2024-04-10 12:03:32 +02:00
committed by GitHub
parent c241bfd85a
commit 082d504b33
4 changed files with 209 additions and 46 deletions

View File

@@ -77,7 +77,8 @@ internal static class UmbracoDatabaseExtensions
public static long Count(this IUmbracoDatabase database, Sql sql)
{
var query = new Sql().Select("COUNT(*)").From().Append("(").Append(sql).Append(")");
// We need to copy the sql into a new object, to avoid this method from changing the sql.
var query = new Sql().Select("COUNT(*)").From().Append("(").Append(new Sql(sql.SQL, sql.Arguments)).Append(") as count_query");
return database.ExecuteScalar<long>(query);
}