1
- namespace ClassLibrary . EFCore ;
1
+ using ClassLibrary . EFCore . Extensions ;
2
+
3
+ namespace ClassLibrary . EFCore ;
2
4
3
5
/// <summary>
4
6
/// Repository class for Entity Framework Core operations.
@@ -104,14 +106,14 @@ public async Task DeleteByIdAsync(TKey id)
104
106
/// Asynchronously gets a paginated list of entities.
105
107
/// </summary>
106
108
/// <param name="includes">A function to include related entities.</param>
107
- /// <param name="conditionWhere">A function to filter the entities.</param>
108
- /// <param name="orderBy">A function to sort the entities.</param>
109
- /// <param name="orderType">The type of the order ("ASC" for ascending, "DESC" for descending) .</param>
110
- /// <param name="pageIndex">The index of the page.</param>
111
- /// <param name="pageSize">The size of the page.</param>
112
- /// <returns>A task that represents the asynchronous operation. The task result contains a list of entities.</returns>
109
+ /// <param name="conditionWhere">A condition to filter the entities.</param>
110
+ /// <param name="orderBy">A function to order the entities.</param>
111
+ /// <param name="ascending">A boolean indicating whether the order is ascending.</param>
112
+ /// <param name="pageIndex">The index of the page to retrieve .</param>
113
+ /// <param name="pageSize">The size of the page to retrieve .</param>
114
+ /// <returns>A task that represents the asynchronous operation. The task result contains a list of paginated entities.</returns>
113
115
public Task < List < TEntity > > GetPaginatedAsync ( Func < IQueryable < TEntity > , IIncludableQueryable < TEntity , object > > includes ,
114
- Expression < Func < TEntity , bool > > conditionWhere , Expression < Func < TEntity , dynamic > > orderBy , string orderType , int pageIndex , int pageSize )
116
+ Expression < Func < TEntity , bool > > conditionWhere , Expression < Func < TEntity , dynamic > > orderBy , bool ascending , int pageIndex , int pageSize )
115
117
{
116
118
IQueryable < TEntity > query = DbContext . Set < TEntity > ( ) ;
117
119
@@ -127,19 +129,9 @@ public Task<List<TEntity>> GetPaginatedAsync(Func<IQueryable<TEntity>, IIncludab
127
129
128
130
if ( orderBy != null )
129
131
{
130
- query = orderType switch
131
- {
132
- "ASC" => query . OrderBy ( orderBy ) ,
133
- "DESC" => query . OrderByDescending ( orderBy ) ,
134
- _ => query . OrderBy ( orderBy ) ,
135
- } ;
136
- }
137
-
138
- if ( pageIndex != 0 && pageSize != 0 )
139
- {
140
- query = query . Skip ( ( pageIndex - 1 ) * pageSize ) . Take ( pageSize ) ;
132
+ query = query . OrderedByAscending ( orderBy , ascending ) ;
141
133
}
142
134
143
- return query . AsNoTracking ( ) . ToListAsync ( ) ;
135
+ return query . Page ( pageIndex , pageSize ) . AsNoTracking ( ) . ToListAsync ( ) ;
144
136
}
145
137
}
0 commit comments