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:
parent
21c895c22b
commit
89a77019dc
@ -10,7 +10,7 @@ public interface IRepository<TEntity>
|
|||||||
|
|
||||||
public Task<IEnumerable<TEntity>> CreateAsync(IEnumerable<TEntity> entities, CancellationToken ct = default);
|
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);
|
public Task UpdateAsync<TDto>(TDto dto, Expression<Func<TEntity, bool>> expression, CancellationToken ct = default);
|
||||||
|
|
||||||
|
|||||||
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user