Refactor CRUDRepository for improved flexibility

- Added using directives for new application interfaces.
- Removed constraint for IUnique<TId> from TEntity.
- Updated CountAsync method to use GetId() for identifier retrieval.
This commit is contained in:
Developer 02 2025-05-19 15:27:08 +02:00
parent 9ea2599553
commit 63f914d188

View File

@ -1,4 +1,5 @@
using DigitalData.Core.Abstractions;
using DigitalData.Core.Application;
using DigitalData.Core.Application.Interfaces.Repository;
using Microsoft.EntityFrameworkCore;
@ -15,7 +16,7 @@ namespace DigitalData.Core.Infrastructure
/// It leverages the EF Core's DbContext and DbSet to perform these operations.
/// </remarks>
public class CRUDRepository<TEntity, TId, TDbContext> : ICRUDRepository<TEntity, TId>
where TEntity : class, IUnique<TId>
where TEntity : class
where TDbContext : DbContext
{
protected readonly TDbContext _dbContext;
@ -107,6 +108,6 @@ namespace DigitalData.Core.Infrastructure
/// If there are multiple entities with the same identifier, they will all be counted.
/// The default implementation assumes that the identifier is unique for each entity.
/// </remarks>
public virtual async Task<int> CountAsync(TId id) => await _dbSet.Where(e => e.Id!.Equals(id)).CountAsync();
public virtual async Task<int> CountAsync(TId id) => await _dbSet.Where(e => e.GetId().Equals(id)).CountAsync();
}
}