Skip to content

Commit 7700fc1

Browse files
committed
Add listBeforeFiltering option to FilterAsync method
The method `FilterAsync` in `BaseRepository.cs` now includes a `listBeforeFiltering` boolean parameter. This parameter allows listing all entities before applying filtering, which can be useful in certain scenarios but may impact performance with large datasets. The method signature and implementation have been updated to handle this new parameter.
1 parent f666d2b commit 7700fc1

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

Sources/EasyExtensions.EntityFrameworkCore/Repository/BaseRepository.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,16 +142,22 @@ public async Task<Paging<TItem>> FilterAsync(IGridifyQuery query, CancellationTo
142142
/// </summary>
143143
/// <param name="query">The query parameters for filtering and pagination.</param>
144144
/// <param name="mapper">The mapper used to map the entities.</param>
145+
/// <param name="listBeforeFiltering">Indicates whether to list the entities before filtering. Be careful with this option, as it may lead to performance issues if the dataset is large.</param>
145146
/// <param name="cancellationToken">The cancellation token.</param>
146147
/// <returns>A task that represents the asynchronous operation. The task result contains the filtered and paginated entities.</returns>
147-
public async Task<Paging<TItem>> FilterAsync(IGridifyQuery query, IGridifyMapper<TItem> mapper, CancellationToken cancellationToken = default)
148+
public async Task<Paging<TItem>> FilterAsync(IGridifyQuery query, IGridifyMapper<TItem> mapper, bool listBeforeFiltering = false, CancellationToken cancellationToken = default)
148149
{
149150
query ??= new GridifyQuery(1, 20, string.Empty, "id desc");
150151
if (string.IsNullOrWhiteSpace(query.OrderBy))
151152
{
152153
query.OrderBy = "id desc";
153154
}
154-
return await db.GridifyAsync(query, mapper);
155+
if (!listBeforeFiltering)
156+
{
157+
return await db.GridifyAsync(query, mapper);
158+
}
159+
var allItems = await ListAllAsync(cancellationToken);
160+
return allItems.AsQueryable().Gridify(query, mapper);
155161
}
156162

157163
/// <summary>

Sources/EasyExtensions.EntityFrameworkCore/Repository/IRepository.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,10 @@ public interface IRepository<TItem> : IRepository where TItem : BaseEntity
7373
/// </summary>
7474
/// <param name="query">The query parameters for filtering and pagination.</param>
7575
/// <param name="mapper">The mapper used to map the entities.</param>
76+
/// <param name="listBeforeFiltering">Indicates whether to list the entities before filtering. Be careful with this option, as it may lead to performance issues if the dataset is large.</param>
7677
/// <param name="cancellationToken">The cancellation token.</param>
7778
/// <returns>A task that represents the asynchronous operation. The task result contains the filtered and paginated entities.</returns>
78-
Task<Paging<TItem>> FilterAsync(IGridifyQuery query, IGridifyMapper<TItem> mapper, CancellationToken cancellationToken = default);
79+
Task<Paging<TItem>> FilterAsync(IGridifyQuery query, IGridifyMapper<TItem> mapper, bool listBeforeFiltering = false, CancellationToken cancellationToken = default);
7980

8081
/// <summary>
8182
/// Finds entities asynchronously based on the specified predicate.

0 commit comments

Comments
 (0)