diff --git a/src/BitzArt.CA.Core/Interfaces/IRepository.cs b/src/BitzArt.CA.Core/Interfaces/IRepository.cs index c40b563..016e7db 100644 --- a/src/BitzArt.CA.Core/Interfaces/IRepository.cs +++ b/src/BitzArt.CA.Core/Interfaces/IRepository.cs @@ -17,28 +17,28 @@ public interface IRepository : IRepository public void Remove(TEntity entity); public void RemoveRange(IEnumerable entities); - - [Obsolete("Use an overload with Func, IQueryable> instead")] - public Task> GetAllAsync(IFilterSet? filter = null, CancellationToken cancellationToken = default); + + public Task> GetAllAsync(CancellationToken cancellationToken = default); + public Task> GetAllAsync(Func, IQueryable> filter, CancellationToken cancellationToken = default); - [Obsolete("Use an overload with Func, IQueryable> instead")] - public Task> GetPageAsync(PageRequest pageRequest, IFilterSet? filter = null, CancellationToken cancellationToken = default); + public Task> GetPageAsync(PageRequest pageRequest, CancellationToken cancellationToken = default); + public Task> GetPageAsync(PageRequest pageRequest, Func, IQueryable> filter, CancellationToken cancellationToken = default); - [Obsolete("Use an overload with Func, IQueryable> instead")] - public Task GetAsync(IFilterSet filter, CancellationToken cancellationToken = default); + public Task GetAsync(CancellationToken cancellationToken = default); + public Task GetAsync(Func, IQueryable> filter, CancellationToken cancellationToken = default); - [Obsolete("Use an overload with Func, IQueryable> instead")] - public Task CountAsync(IFilterSet? filter = null, CancellationToken cancellationToken = default); + public Task CountAsync(CancellationToken cancellationToken = default); + public Task CountAsync(Func, IQueryable> filter, CancellationToken cancellationToken = default); - [Obsolete("Use an overload with Func, IQueryable> instead")] - public Task LongCountAsync(IFilterSet? filter = null, CancellationToken cancellationToken = default); + public Task LongCountAsync(CancellationToken cancellationToken = default); + public Task LongCountAsync(Func, IQueryable> filter, CancellationToken cancellationToken = default); - [Obsolete("Use an overload with Func, IQueryable> instead")] - public Task AnyAsync(IFilterSet? filter = null, CancellationToken cancellationToken = default); + public Task AnyAsync(CancellationToken cancellationToken = default); + public Task AnyAsync(Func, IQueryable> filter, CancellationToken cancellationToken = default); } \ No newline at end of file diff --git a/src/BitzArt.CA.Persistence.EntityFrameworkCore/Repositories/AppDbRepository.cs b/src/BitzArt.CA.Persistence.EntityFrameworkCore/Repositories/AppDbRepository.cs index 3a4bb5e..4a739c1 100644 --- a/src/BitzArt.CA.Persistence.EntityFrameworkCore/Repositories/AppDbRepository.cs +++ b/src/BitzArt.CA.Persistence.EntityFrameworkCore/Repositories/AppDbRepository.cs @@ -39,23 +39,20 @@ public override async Task SaveChangesAsync(CancellationToken cancellationT protected virtual IQueryable Set(Func, IQueryable> filter) { - return filter(Db.Set()); + return filter(Set()); } - protected virtual IQueryable Set(IFilterSet? filter = null) + protected virtual IQueryable Set() { - var result = Db.Set() as IQueryable; - if (filter is not null) result = result.Apply(filter); - - return result; + return Db.Set(); } - public virtual async Task> GetAllAsync(IFilterSet? filter = null, CancellationToken cancellationToken = default) + public virtual async Task> GetAllAsync(CancellationToken cancellationToken = default) { using var saveActivity = Activity.Current?.Source .StartActivity($"{RepositoryName}: GetAll"); - return await Set(filter) + return await Set() .ToListAsync(cancellationToken); } @@ -68,12 +65,12 @@ public virtual async Task> GetAllAsync(Func> GetPageAsync(PageRequest pageRequest, IFilterSet? filter = null, CancellationToken cancellationToken = default) + public virtual async Task> GetPageAsync(PageRequest pageRequest, CancellationToken cancellationToken = default) { using var saveActivity = Activity.Current?.Source .StartActivity($"{RepositoryName}: GetPage"); - return await Set(filter) + return await Set() .ToPageAsync(pageRequest, cancellationToken); } @@ -86,12 +83,12 @@ public virtual async Task> GetPageAsync(PageRequest .ToPageAsync(pageRequest, cancellationToken); } - public virtual async Task GetAsync(IFilterSet filter, CancellationToken cancellationToken = default) + public virtual async Task GetAsync(CancellationToken cancellationToken = default) { using var saveActivity = Activity.Current?.Source .StartActivity($"{RepositoryName}: Get"); - return await Set(filter) + return await Set() .FirstOrDefaultAsync(cancellationToken); } @@ -104,12 +101,12 @@ public virtual async Task> GetPageAsync(PageRequest .FirstOrDefaultAsync(cancellationToken); } - public virtual async Task CountAsync(IFilterSet? filter = null, CancellationToken cancellationToken = default) + public virtual async Task CountAsync(CancellationToken cancellationToken = default) { using var saveActivity = Activity.Current?.Source .StartActivity($"{RepositoryName}: Count"); - return await Set(filter) + return await Set() .CountAsync(cancellationToken); } @@ -122,12 +119,12 @@ public virtual async Task CountAsync(Func, IQu .CountAsync(cancellationToken); } - public virtual async Task LongCountAsync(IFilterSet? filter = null, CancellationToken cancellationToken = default) + public virtual async Task LongCountAsync(CancellationToken cancellationToken = default) { using var saveActivity = Activity.Current?.Source .StartActivity($"{RepositoryName}: LongCount"); - return await Set(filter) + return await Set() .LongCountAsync(cancellationToken); } @@ -140,12 +137,12 @@ public virtual async Task LongCountAsync(Func .LongCountAsync(cancellationToken); } - public virtual async Task AnyAsync(IFilterSet? filter = null, CancellationToken cancellationToken = default) + public virtual async Task AnyAsync(CancellationToken cancellationToken = default) { using var saveActivity = Activity.Current?.Source .StartActivity($"{RepositoryName}: Any"); - return await Set(filter) + return await Set() .AnyAsync(cancellationToken); } @@ -163,16 +160,9 @@ public class AppDbRepository(AppDbContext db) : AppDbRepository where TKey : struct { - protected override IQueryable Set(IFilterSet? filter = null) + protected override IQueryable Set() { - var result = Db.Set() as IQueryable; - - // Default behavior: order by Id, - result = result.OrderBy(x => x.Id); - - // Default ordering may be overridden when applying the filter - if (filter is not null) result = result.Apply(filter); - - return result; + // Default order: Id, ascending + return base.Set().OrderBy(x => x.Id); } }