Enhance IRepository and add RepositoryExtensions

Updated the IRepository<TEntity> interface to include an overloaded CreateAsync method for handling multiple entities and removed the CancellationToken from the Read method. Introduced a new RepositoryExtensions class with a Where extension method to facilitate applying multiple filters to IReadQuery<TEntity> queries.
This commit is contained in:
Developer 02 2025-05-20 10:05:57 +02:00
parent 21c895c22b
commit 89a77019dc
2 changed files with 15 additions and 1 deletions

View File

@ -10,7 +10,7 @@ public interface IRepository<TEntity>
public Task<IEnumerable<TEntity>> CreateAsync(IEnumerable<TEntity> entities, CancellationToken ct = default);
public IReadQuery<TEntity> Read(Expression<Func<TEntity, bool>> expression, CancellationToken ct = default);
public IReadQuery<TEntity> Read(Expression<Func<TEntity, bool>> expression);
public Task UpdateAsync<TDto>(TDto dto, Expression<Func<TEntity, bool>> expression, CancellationToken ct = default);

View File

@ -0,0 +1,14 @@
using System.Linq.Expressions;
namespace DigitalData.Core.Application.Interfaces.Repository;
public static class RepositoryExtensions
{
public static IReadQuery<TEntity> Where<TEntity>(this IReadQuery<TEntity> query, params Expression<Func<TEntity, bool>>[] expressions)
{
foreach (var expression in expressions)
query = query.Where(expression);
return query;
}
}