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:
parent
9ea2599553
commit
63f914d188
@ -1,4 +1,5 @@
|
|||||||
using DigitalData.Core.Abstractions;
|
using DigitalData.Core.Abstractions;
|
||||||
|
using DigitalData.Core.Application;
|
||||||
using DigitalData.Core.Application.Interfaces.Repository;
|
using DigitalData.Core.Application.Interfaces.Repository;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
@ -15,7 +16,7 @@ namespace DigitalData.Core.Infrastructure
|
|||||||
/// It leverages the EF Core's DbContext and DbSet to perform these operations.
|
/// It leverages the EF Core's DbContext and DbSet to perform these operations.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
public class CRUDRepository<TEntity, TId, TDbContext> : ICRUDRepository<TEntity, TId>
|
public class CRUDRepository<TEntity, TId, TDbContext> : ICRUDRepository<TEntity, TId>
|
||||||
where TEntity : class, IUnique<TId>
|
where TEntity : class
|
||||||
where TDbContext : DbContext
|
where TDbContext : DbContext
|
||||||
{
|
{
|
||||||
protected readonly 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.
|
/// 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.
|
/// The default implementation assumes that the identifier is unique for each entity.
|
||||||
/// </remarks>
|
/// </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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user