@@ -60,42 +60,44 @@ public static async Task<PagedResult<TEntity>> GetPagedResultsAsync<TEntity>(thi
6060 return new PagedResult < TEntity > ( items , itemsCount ) ;
6161 }
6262
63- /// <summary>
64- /// Returns a paged result for the specified query using a custom SQL query for total count.
65- /// </summary>
66- /// <typeparam name="TEntity">The type of the entity.</typeparam>
67- /// <typeparam name="TDbContext">The type of the DbContext.</typeparam>
68- /// <param name="query">The source query.</param>
69- /// <param name="dbContext">The database context to execute the query.</param>
70- /// <param name="page">The zero-based page index.</param>
71- /// <param name="pageSize">The number of items per page.</param>
72- /// <returns>A <see cref="PagedResult{TEntity}"/> containing the items and total count.</returns>
73- /// <example>
74- /// <code><![CDATA[
75- /// var paged = await dbContext.People.GetPagedResultsAsync(dbContext, 0, 10);
76- /// ]]></code>
77- /// </example>
78- public static async Task < PagedResult < TEntity > > GetPagedResultsAsync < TEntity , TDbContext > (
79- this IQueryable < TEntity > query ,
80- TDbContext dbContext , int page , int pageSize ) where TEntity : class where TDbContext : DbContext
81- {
82- // Generate SQL that includes COUNT(*) OVER() to get total count in single query
83- var sql = query . ToQueryString ( ) ;
84- var countedSql = $ "SELECT *, COUNT(*) OVER() AS TotalCount FROM ({ sql } ) AS CountedQuery " +
85- $ "ORDER BY (SELECT NULL) OFFSET { ( page * pageSize ) . ToString ( CultureInfo . InvariantCulture ) } " +
86- $ " ROWS FETCH NEXT { pageSize . ToString ( CultureInfo . InvariantCulture ) } ROWS ONLY";
87-
88- // Execute the query
89- var result = await dbContext . Set < TEntity > ( )
90- . FromSqlRaw ( countedSql )
91- . AsNoTracking ( )
92- . ToListAsync ( )
93- . ConfigureAwait ( false ) ;
94-
95- // Get total count from the first row (or 0 if no results)
96- var totalCount = result . Any ( )
97- ? ( long ) ( result [ 0 ] . GetType ( ) . GetProperty ( "TotalCount" ) ? . GetValue ( result [ 0 ] , null ) ?? 0 )
98- : 0 ;
99- return new PagedResult < TEntity > ( result , totalCount ) ;
100- }
101- }
63+ #pragma warning disable S125
64+ // /// <summary>
65+ // /// Returns a paged result for the specified query using a custom SQL query for total count.
66+ // /// </summary>
67+ // /// <typeparam name="TEntity">The type of the entity.</typeparam>
68+ // /// <typeparam name="TDbContext">The type of the DbContext.</typeparam>
69+ // /// <param name="query">The source query.</param>
70+ // /// <param name="dbContext">The database context to execute the query.</param>
71+ // /// <param name="page">The zero-based page index.</param>
72+ // /// <param name="pageSize">The number of items per page.</param>
73+ // /// <returns>A <see cref="PagedResult{TEntity}"/> containing the items and total count.</returns>
74+ // /// <example>
75+ // /// <code><![CDATA[
76+ // /// var paged = await dbContext.People.GetPagedResultsAsync(dbContext, 0, 10);
77+ // /// ]]></code>
78+ // /// </example>
79+ // public static async Task<PagedResult<TEntity>> GetPagedResultsAsync<TEntity, TDbContext>(
80+ // this IQueryable<TEntity> query,
81+ // TDbContext dbContext, int page, int pageSize) where TEntity : class where TDbContext : DbContext
82+ // {
83+ // // Generate SQL that includes COUNT(*) OVER() to get total count in single query
84+ // var sql = query.ToQueryString();
85+ // var countedSql = $"SELECT *, COUNT(*) OVER() AS TotalCount FROM ({sql}) AS CountedQuery " +
86+ // $"ORDER BY (SELECT NULL) OFFSET {(page * pageSize).ToString(CultureInfo.InvariantCulture)}" +
87+ // $" ROWS FETCH NEXT {pageSize.ToString(CultureInfo.InvariantCulture)} ROWS ONLY";
88+ //
89+ // // Execute the query
90+ // var result = await dbContext.Set<TEntity>()
91+ // .FromSqlRaw(countedSql)
92+ // .AsNoTracking()
93+ // .Select(x =>
94+ // new { Item = x, TotalCount = EF.Property<int>(x, "TotalCount") })
95+ // .ToListAsync()
96+ // .ConfigureAwait(false);
97+ //
98+ // // Get total count from the first row (or 0 if no results)
99+ // long totalCount = result.Count != 0 ? result[0].TotalCount : 0;
100+ // return new PagedResult<TEntity>(result.ConvertAll(x => x.Item), totalCount);
101+ // }
102+ #pragma warning restore S125
103+ }
0 commit comments