refactor(repository): add query parameter to IRepository.Where and constrain IRepository.Entity
- Updated `IRepository<TEntity>.Where()` to accept an `Expression<Func<TEntity, bool>>` for filtering. - Added `where TEntity : IEntity` constraint to `IRepository.Entity<TEntity>()` method. - No functional logic changes, only interface refactoring for stronger typing and query support.
This commit is contained in:
parent
b181e1543f
commit
be96bd0c07
@ -19,37 +19,52 @@ public static class Extensions
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region IRepository
|
#region IRepository
|
||||||
public static IQueryable<TEntity> Get<TEntity>(this IRepository repository) => repository.Entity<TEntity>().Get();
|
public static IQueryable<TEntity> Get<TEntity>(this IRepository repository) where TEntity : IEntity
|
||||||
|
=> repository.Entity<TEntity>().Get();
|
||||||
|
|
||||||
public static IQueryable<TEntity> Where<TEntity>(this IRepository repository) => repository.Entity<TEntity>().Where();
|
public static IQueryable<TEntity> Where<TEntity>(this IRepository repository, Expression<Func<TEntity, bool>> expression)
|
||||||
|
where TEntity : IEntity
|
||||||
|
=> repository.Entity<TEntity>().Where(expression);
|
||||||
|
|
||||||
#region Create
|
#region Create
|
||||||
public static Task<TEntity> CreateAsync<TEntity>(this IRepository repository, TEntity entity, CancellationToken cancel = default)
|
public static Task<TEntity> CreateAsync<TEntity>(this IRepository repository, TEntity entity, CancellationToken cancel = default)
|
||||||
|
where TEntity : IEntity
|
||||||
=> repository.Entity<TEntity>().CreateAsync(entity, cancel);
|
=> repository.Entity<TEntity>().CreateAsync(entity, cancel);
|
||||||
|
|
||||||
public static Task<TEntity> CreateAsync<TEntity, TDto>(this IRepository repository, TDto dto, CancellationToken cancel = default)
|
public static Task<TEntity> CreateAsync<TEntity, TDto>(this IRepository repository, TDto dto, CancellationToken cancel = default)
|
||||||
|
where TEntity : IEntity
|
||||||
|
where TDto : IDto<TEntity>
|
||||||
=> repository.Entity<TEntity>().CreateAsync(dto, cancel);
|
=> repository.Entity<TEntity>().CreateAsync(dto, cancel);
|
||||||
|
|
||||||
public static Task<IEnumerable<TEntity>> CreateAsync<TEntity>(this IRepository repository, IEnumerable<TEntity> entities, CancellationToken cancel = default)
|
public static Task<IEnumerable<TEntity>> CreateAsync<TEntity>(this IRepository repository, IEnumerable<TEntity> entities, CancellationToken cancel = default)
|
||||||
|
where TEntity : IEntity
|
||||||
=> repository.Entity<TEntity>().CreateAsync(entities, cancel);
|
=> repository.Entity<TEntity>().CreateAsync(entities, cancel);
|
||||||
|
|
||||||
public static Task<IEnumerable<TEntity>> CreateAsync<TEntity, TDto>(this IRepository repository, IEnumerable<TDto> dtos, CancellationToken cancel = default)
|
public static Task<IEnumerable<TEntity>> CreateAsync<TEntity, TDto>(this IRepository repository, IEnumerable<TDto> dtos, CancellationToken cancel = default)
|
||||||
|
where TEntity : IEntity
|
||||||
|
where TDto : IDto<TEntity>
|
||||||
=> repository.Entity<TEntity>().CreateAsync(dtos, cancel);
|
=> repository.Entity<TEntity>().CreateAsync(dtos, cancel);
|
||||||
#endregion Create
|
#endregion Create
|
||||||
|
|
||||||
#region Update
|
#region Update
|
||||||
public static Task UpdateAsync<TEntity, TDto>(this IRepository repository, TDto dto, Expression<Func<TEntity, bool>> expression, CancellationToken cancel = default)
|
public static Task UpdateAsync<TEntity, TDto>(this IRepository repository, TDto dto, Expression<Func<TEntity, bool>> expression, CancellationToken cancel = default)
|
||||||
|
where TEntity : IEntity
|
||||||
|
where TDto : IDto<TEntity>
|
||||||
=> repository.Entity<TEntity>().UpdateAsync(dto, expression, cancel);
|
=> repository.Entity<TEntity>().UpdateAsync(dto, expression, cancel);
|
||||||
|
|
||||||
public static Task UpdateAsync<TEntity, TDto>(this IRepository repository, TDto dto, Func<IQueryable<TEntity>, IQueryable<TEntity>> query, CancellationToken cancel = default)
|
public static Task UpdateAsync<TEntity, TDto>(this IRepository repository, TDto dto, Func<IQueryable<TEntity>, IQueryable<TEntity>> query, CancellationToken cancel = default)
|
||||||
|
where TEntity : IEntity
|
||||||
|
where TDto : IDto<TEntity>
|
||||||
=> repository.Entity<TEntity>().UpdateAsync(dto, query, cancel);
|
=> repository.Entity<TEntity>().UpdateAsync(dto, query, cancel);
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Delete
|
#region Delete
|
||||||
public static Task DeleteAsync<TEntity>(this IRepository repository, Expression<Func<TEntity, bool>> expression, CancellationToken cancel = default)
|
public static Task DeleteAsync<TEntity>(this IRepository repository, Expression<Func<TEntity, bool>> expression, CancellationToken cancel = default)
|
||||||
|
where TEntity : IEntity
|
||||||
=> repository.Entity<TEntity>().DeleteAsync(expression, cancel);
|
=> repository.Entity<TEntity>().DeleteAsync(expression, cancel);
|
||||||
|
|
||||||
public static Task DeleteAsync<TEntity>(this IRepository repository, Func<IQueryable<TEntity>, IQueryable<TEntity>> query, CancellationToken cancel = default)
|
public static Task DeleteAsync<TEntity>(this IRepository repository, Func<IQueryable<TEntity>, IQueryable<TEntity>> query, CancellationToken cancel = default)
|
||||||
|
where TEntity : IEntity
|
||||||
=> repository.Entity<TEntity>().DeleteAsync(query, cancel);
|
=> repository.Entity<TEntity>().DeleteAsync(query, cancel);
|
||||||
#endregion
|
#endregion
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
@ -11,7 +11,7 @@ public interface IRepository<TEntity>
|
|||||||
|
|
||||||
public Task<IEnumerable<TEntity>> CreateAsync(IEnumerable<TEntity> entities, CancellationToken cancel = default);
|
public Task<IEnumerable<TEntity>> CreateAsync(IEnumerable<TEntity> entities, CancellationToken cancel = default);
|
||||||
|
|
||||||
public IQueryable<TEntity> Where();
|
public IQueryable<TEntity> Where(Expression<Func<TEntity, bool>> expression);
|
||||||
|
|
||||||
public IQueryable<TEntity> Get();
|
public IQueryable<TEntity> Get();
|
||||||
|
|
||||||
@ -34,5 +34,5 @@ public interface IRepository<TEntity>
|
|||||||
|
|
||||||
public interface IRepository
|
public interface IRepository
|
||||||
{
|
{
|
||||||
public IRepository<TEntity> Entity<TEntity>();
|
public IRepository<TEntity> Entity<TEntity>() where TEntity : IEntity;
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user