@@ -30,34 +30,34 @@ public static IQueryable<T> ApplySpecification<T>(this IQueryable<T> query, ISpe
3030 }
3131
3232 /// <summary>
33- /// Extension method to provided ordered queryable data to a paginated result set .
33+ /// Projects the query to a paginated data asynchronously .
3434 /// </summary>
35- /// <remarks>
36- /// This method will apply the given specification to the query, paginate the results, and project them to the desired
37- /// result type.
38- /// </remarks>
39- /// <typeparam name="T">Source type of the entities in the query</typeparam>
40- /// <typeparam name="TResult">Destination type to which the entities should be projected</typeparam>
41- /// <param name="query">The original ordered query to project and paginate</param>
42- /// <param name="spec">The specification to apply to the query before projection and pagination</param>
43- /// <param name="pageNumber">The desired page number of the paginated results</param>
44- /// <param name="pageSize">The number of items per page in the paginated results</param>
45- /// <param name="configuration">Configuration for the projection</param>
46- /// <param name="cancellationToken">Optional cancellation token to cancel the operation</param>
47- /// <returns>The paginated and projected data</returns>
35+ /// <typeparam name="T">The type of entities in the query</typeparam>
36+ /// <typeparam name="TResult">The type of the result</typeparam>
37+ /// <param name="query">The original ordered query</param>
38+ /// <param name="spec">The specification to apply to the query</param>
39+ /// <param name="pageNumber">The page number</param>
40+ /// <param name="pageSize">The size of the page</param>
41+ /// <param name="mapperFunc">The function to map entities to result</param>
42+ /// <param name="cancellationToken">The cancellation token</param>
43+ /// <returns>A task that represents the asynchronous operation. The task result contains the paginated data</returns>
4844 public static async Task < PaginatedData < TResult > > ProjectToPaginatedDataAsync < T , TResult > (
4945 this IOrderedQueryable < T > query , ISpecification < T > spec , int pageNumber , int pageSize ,
50- IConfigurationProvider configuration , CancellationToken cancellationToken = default ) where T : class , IEntity
46+ Func < T , TResult > mapperFunc , CancellationToken cancellationToken = default ) where T : class , IEntity
5147 {
5248 var specificationEvaluator = SpecificationEvaluator . Default ;
53- var count = await specificationEvaluator . GetQuery ( query . AsNoTracking ( ) , spec ) . CountAsync ( ) ;
54- var data = await specificationEvaluator . GetQuery ( query . AsNoTracking ( ) , spec ) . Skip ( ( pageNumber - 1 ) * pageSize )
49+ var queryWithSpec = specificationEvaluator . GetQuery ( query . AsNoTracking ( ) , spec ) ;
50+
51+ var count = await queryWithSpec . CountAsync ( cancellationToken ) ;
52+ var data = await queryWithSpec
53+ . Skip ( ( pageNumber - 1 ) * pageSize )
5554 . Take ( pageSize )
56- . ProjectTo < TResult > ( configuration )
5755 . ToListAsync ( cancellationToken ) ;
58- return new PaginatedData < TResult > ( data , count , pageNumber , pageSize ) ;
59- }
6056
57+ var items = data . Select ( x => mapperFunc ( x ) ) . ToList ( ) ;
58+
59+ return new PaginatedData < TResult > ( items , count , pageNumber , pageSize ) ;
60+ }
6161
6262 /// <summary>
6363 /// Filters the queryable data based on the specified keyword.
@@ -95,5 +95,4 @@ public static IQueryable<T> WhereContainsKeyword<T>(this IQueryable<T> source, s
9595 var lambda = Expression . Lambda < Func < T , bool > > ( predicate , parameter ) ;
9696 return source . Where ( lambda ) ;
9797 }
98-
99- }
98+ }
0 commit comments