@@ -47,24 +47,22 @@ public class YourEntity : IEntity<int>
4747``` csharp
4848public interface IYourEntityService
4949{
50- Task <IEnumerable <YourEntity >> GetAllAsync ();
50+ Task <IQueryable <YourEntity >> GetAllAsync (Func<IQueryable<YourEntity>,
51+ IIncludableQueryable<YourEntity, object>> includes = null ! ,
52+ Expression <Func <YourEntity , bool >> filter = null ! ,
53+ Expression <Func <YourEntity , object >> orderBy = null ! ,
54+ bool ascending = true );
55+
5156 Task <YourEntity > GetByIdAsync (int id );
5257 Task CreateAsync (YourEntity entity );
5358 Task UpdateAsync (YourEntity entity );
5459 Task DeleteAsync (YourEntity entity );
5560
56- // Alternative method for extracting all records
57- Task <IEnumerable <YourEntity >> GetAllEntitiesAsync (Func <YourEntity , bool > predicate )
58-
5961 // Alternative method for deleting
6062 Task DeleteByIdAsync (int id );
6163
6264 // Optional method
63- Task <List <YourEntity >> GetPaginatedAsync (Func<IQueryable<YourEntity>,
64- IIncludableQueryable<YourEntity, object>> includes,
65- Expression <Func <YourEntity , bool >> conditionWhere ,
66- Expression <Func <YourEntity , dynamic >> orderBy ,
67- bool ascending , int pageIndex , int pageSize );
65+ Task <PaginatedResult <TEntity >> GetPaginatedAsync (IQueryable <TEntity > query , int pageNumber , int pageSize );
6866}
6967```
7068
@@ -80,7 +78,9 @@ public class YourEntityService : IYourEntityService
8078 _repository = repository ;
8179 }
8280
83- public async Task <IEnumerable <YourEntity >> GetAllAsync ()
81+ // This method accepts optional lambdas as input (includes, where, order by),
82+ // while by default it is sorted in ascending order (set false if you want to sort in descending order)
83+ public async Task <IQueryable <TEntity >> GetAllAsync ()
8484 {
8585 return await _repository .GetAllAsync ();
8686 }
@@ -105,26 +105,20 @@ public class YourEntityService : IYourEntityService
105105 await _repository .DeleteAsync (entity );
106106 }
107107
108- // Alternative method for extracting all records
109- public async Task <IEnumerable <YourEntity >> GetAllEntitiesAsync (Func <YourEntity , bool > predicate )
110- {
111- return await _repository .GetAllEntitiesAsync (predicate );
112- }
113-
114108 // Alternative method for deleting
115109 public async Task DeleteByIdAsync (int id )
116110 {
117111 await _repository .DeleteByIdAsync (id );
118112 }
119113
120114 // Optional method for pagination
121- // If ascending is passed to true, the list is sorted in ascending order.
122- // If ascending is passed to false, the list is sorted in descending order.
123- public Task <List <YourEntity >> GetPaginatedAsync (Func<IQueryable<YourEntity>,
124- IIncludableQueryable<YourEntity, object>> includes, Expression <Func <YourEntity , bool >> conditionWhere ,
125- Expression <Func <YourEntity , dynamic >> orderBy , bool ascending , int pageIndex , int pageSize )
115+ public async Task <PaginatedResult <TEntity >> GetPaginatedAsync (IQueryable <TEntity > query , int pageNumber , int pageSize )
126116 {
127- return await _repository .GetPaginatedAsync (includes , conditionWhere , orderBy , ascending , pageIndex , pageSize );
117+ // For optional lambdas read the comments of the GetAllAsync method
118+ var query = await repository .GetAllAsync ();
119+ var result = await repository .GetPaginatedAsync (query , 2 , 5 );
120+
121+ return result ;
128122 }
129123}
130124```
0 commit comments