feat(DbRepository): add GetAll and GetAllAsync, make Where read-only

- Updated Where() to use AsNoTracking() for read-only queries
- Added GetAll() and GetAllAsync() to retrieve all entities
- Improved repository methods for efficient read operations
This commit is contained in:
tekh 2025-09-12 11:50:59 +02:00
parent 56b467ddfc
commit babddfff83

View File

@ -35,9 +35,11 @@ public class DbRepository<TDbContext, TEntity> : IRepository<TEntity> where TDbC
return entities; return entities;
} }
public IQueryable<TEntity> Where(Expression<Func<TEntity, bool>> expression) => Entities.AsQueryable().Where(expression); public IQueryable<TEntity> Where(Expression<Func<TEntity, bool>> expression) => Entities.AsNoTracking().Where(expression);
public IQueryable<TEntity> Get() => Entities.AsNoTracking(); public IEnumerable<TEntity> GetAll() => Entities.AsNoTracking().ToList();
public async Task<IEnumerable<TEntity>> GetAllAsync(CancellationToken cancel = default) => await Entities.AsNoTracking().ToListAsync(cancel);
public virtual Task UpdateAsync<TDto>(TDto dto, Expression<Func<TEntity, bool>> expression, CancellationToken cancel = default) => UpdateAsync(dto, q => q.Where(expression), cancel); public virtual Task UpdateAsync<TDto>(TDto dto, Expression<Func<TEntity, bool>> expression, CancellationToken cancel = default) => UpdateAsync(dto, q => q.Where(expression), cancel);