@@ -47,24 +47,22 @@ public class YourEntity : IEntity<int>
47
47
``` csharp
48
48
public interface IYourEntityService
49
49
{
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
+
51
56
Task <YourEntity > GetByIdAsync (int id );
52
57
Task CreateAsync (YourEntity entity );
53
58
Task UpdateAsync (YourEntity entity );
54
59
Task DeleteAsync (YourEntity entity );
55
60
56
- // Alternative method for extracting all records
57
- Task <IEnumerable <YourEntity >> GetAllEntitiesAsync (Func <YourEntity , bool > predicate )
58
-
59
61
// Alternative method for deleting
60
62
Task DeleteByIdAsync (int id );
61
63
62
64
// 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 );
68
66
}
69
67
```
70
68
@@ -80,7 +78,9 @@ public class YourEntityService : IYourEntityService
80
78
_repository = repository ;
81
79
}
82
80
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 ()
84
84
{
85
85
return await _repository .GetAllAsync ();
86
86
}
@@ -105,26 +105,20 @@ public class YourEntityService : IYourEntityService
105
105
await _repository .DeleteAsync (entity );
106
106
}
107
107
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
-
114
108
// Alternative method for deleting
115
109
public async Task DeleteByIdAsync (int id )
116
110
{
117
111
await _repository .DeleteByIdAsync (id );
118
112
}
119
113
120
114
// 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 )
126
116
{
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 ;
128
122
}
129
123
}
130
124
```
0 commit comments