refactor(repository): make UpdateAsync more flexible with Action<TEntity>

- Introduced Action<TEntity>-based UpdateAsync method for more flexible updates
- Updated TDto-based UpdateAsync to delegate to the new method
- Reduced code duplication and Mapper dependency
- Preserved existing Create, Read, and Delete functionality
This commit is contained in:
2025-11-05 14:20:12 +01:00
parent 5567f6731b
commit d16a4b6bb4
2 changed files with 123 additions and 111 deletions

View File

@@ -1,5 +1,4 @@
using DigitalData.Core.Abstractions.Interfaces;
using System.Linq.Expressions;
using System.Linq.Expressions;
#if NETFRAMEWORK
using System;
using System.Collections.Generic;
@@ -15,90 +14,100 @@ namespace DigitalData.Core.Abstraction.Application.Repository
{
#endif
public interface IRepository<TEntity>
{
#region Create
public interface IRepository<TEntity>
{
#region Create
#if NET
public
#endif
Task<TEntity> CreateAsync(TEntity entity, CancellationToken cancel = default);
Task<TEntity> CreateAsync(TEntity entity, CancellationToken cancel = default);
#if NET
public
#endif
Task<IEnumerable<TEntity>> CreateAsync(IEnumerable<TEntity> entities, CancellationToken cancel = default);
Task<IEnumerable<TEntity>> CreateAsync(IEnumerable<TEntity> entities, CancellationToken cancel = default);
#if NET
public
#endif
Task<TEntity> CreateAsync<TDto>(TDto dto, CancellationToken cancel = default);
Task<TEntity> CreateAsync<TDto>(TDto dto, CancellationToken cancel = default);
#if NET
public
#endif
Task<IEnumerable<TEntity>> CreateAsync<TDto>(IEnumerable<TDto> dtos, CancellationToken cancel = default);
#endregion Create
Task<IEnumerable<TEntity>> CreateAsync<TDto>(IEnumerable<TDto> dtos, CancellationToken cancel = default);
#endregion Create
#region Read
#region Read
#if NET
public
#endif
IQueryable<TEntity> Query { get; }
IQueryable<TEntity> Query { get; }
#if NET
public
#endif
IQueryable<TEntity> Where(Expression<Func<TEntity, bool>> expression);
IQueryable<TEntity> Where(Expression<Func<TEntity, bool>> expression);
#if NET
public
#endif
IEnumerable<TEntity> GetAll();
IEnumerable<TEntity> GetAll();
#if NET
public
#endif
Task<IEnumerable<TEntity>> GetAllAsync(CancellationToken cancel = default);
#endregion Read
Task<IEnumerable<TEntity>> GetAllAsync(CancellationToken cancel = default);
#endregion Read
#region Update
#region Update
#if NET
public
#endif
Task UpdateAsync<TDto>(TDto dto, Expression<Func<TEntity, bool>> expression, CancellationToken cancel = default);
Task UpdateAsync<TDto>(TDto dto, Expression<Func<TEntity, bool>> expression, CancellationToken cancel = default);
#if NET
public
#endif
Task UpdateAsync<TDto>(TDto dto, Func<IQueryable<TEntity>, IQueryable<TEntity>> query, CancellationToken cancel = default);
#endregion Update
#region Delete
#if NET
public
#endif
Task DeleteAsync(Expression<Func<TEntity, bool>> expression, CancellationToken cancel = default);
Task UpdateAsync<TDto>(TDto dto, Func<IQueryable<TEntity>, IQueryable<TEntity>> query, CancellationToken cancel = default);
#if NET
public
#endif
Task DeleteAsync(Func<IQueryable<TEntity>, IQueryable<TEntity>> query, CancellationToken cancel = default);
#endregion Delete
Task UpdateAsync(Action<TEntity> modification, Func<IQueryable<TEntity>, IQueryable<TEntity>> query, CancellationToken cancel = default);
#region Obsolete
[Obsolete("Use CreateAsync, UpdateAsync or DeleteAsync")]
#if NET
public
#endif
IQueryable<TEntity> Read();
Task UpdateAsync(Action<TEntity> modification, Expression<Func<TEntity, bool>> expression, CancellationToken cancel = default);
#endregion Update
[Obsolete("Use IRepository<TEntity>.Where")]
#region Delete
#if NET
public
#endif
IQueryable<TEntity> ReadOnly();
#endregion
}
Task DeleteAsync(Expression<Func<TEntity, bool>> expression, CancellationToken cancel = default);
#if NET
public
#endif
Task DeleteAsync(Func<IQueryable<TEntity>, IQueryable<TEntity>> query, CancellationToken cancel = default);
#endregion Delete
#region Obsolete
[Obsolete("Use CreateAsync, UpdateAsync or DeleteAsync")]
#if NET
public
#endif
IQueryable<TEntity> Read();
[Obsolete("Use IRepository<TEntity>.Where")]
#if NET
public
#endif
IQueryable<TEntity> ReadOnly();
#endregion
}
#if NETFRAMEWORK
}
#endif