Class GenericBaseRepository<TEntity, TContext, TKey>
- Namespace
- Axolotl.EFCore.Repository
- Assembly
- Axolotl.EFCore.dll
public abstract class GenericBaseRepository<TEntity, TContext, TKey> : RepositoryBase<TEntity>, IRepository<TEntity, TKey>, IReadRepository<TEntity>, IRepositoryBase<TEntity>, IReadRepositoryBase<TEntity> where TEntity : class, IAggregateRoot, IHasKey<TKey> where TContext : DbContext where TKey : notnull
Type Parameters
TEntity
TContext
TKey
- Inheritance
-
RepositoryBase<TEntity>GenericBaseRepository<TEntity, TContext, TKey>
- Implements
-
IRepository<TEntity, TKey>IReadRepository<TEntity>IRepositoryBase<TEntity>IReadRepositoryBase<TEntity>
- Inherited Members
-
RepositoryBase<TEntity>.GetBySpecAsync<TResult>(ISpecification<TEntity, TResult>, CancellationToken)
- Extension Methods
Constructors
GenericBaseRepository(IUnitOfWork<TContext>)
protected GenericBaseRepository(IUnitOfWork<TContext> unitOfWork)
Parameters
unitOfWork
IUnitOfWork<TContext>
Fields
UnitOfWork
protected readonly IUnitOfWork<TContext> UnitOfWork
Field Value
- IUnitOfWork<TContext>
Methods
DeleteAsync(TEntity, CancellationToken)
Removes an entity in the database
public override Task<TEntity?> DeleteAsync(TEntity entity, CancellationToken cancellationToken = default)
Parameters
entity
TEntityThe entity to delete.
cancellationToken
CancellationToken
Returns
- Task<TEntity>
A task that represents the asynchronous operation.
DeleteAsync(TKey, CancellationToken)
public Task<TEntity?> DeleteAsync(TKey id, CancellationToken cancellationToken = default)
Parameters
id
TKeycancellationToken
CancellationToken
Returns
- Task<TEntity>
DeleteBySpec(ISpecification<TEntity>, CancellationToken)
public Task<IEnumerable<TEntity>> DeleteBySpec(ISpecification<TEntity> specification, CancellationToken cancellationToken = default)
Parameters
specification
ISpecification<TEntity>cancellationToken
CancellationToken
Returns
- Task<IEnumerable<TEntity>>
DeleteRangeAsync(IEnumerable<TEntity>, CancellationToken)
Removes the given entities in the database
public override Task<IEnumerable<TEntity>> DeleteRangeAsync(IEnumerable<TEntity> entities, CancellationToken cancellationToken = default)
Parameters
entities
IEnumerable<TEntity>The entities to remove.
cancellationToken
CancellationToken
Returns
- Task<IEnumerable<TEntity>>
A task that represents the asynchronous operation.
DeleteRangeAsync(IEnumerable<TKey>, CancellationToken)
public Task<int> DeleteRangeAsync(IEnumerable<TKey> ids, CancellationToken cancellationToken = default)
Parameters
ids
IEnumerable<TKey>cancellationToken
CancellationToken
Returns
Find(ISpecification<TEntity>, Expression<Func<TEntity, bool>>)
public IEnumerable<TEntity> Find(ISpecification<TEntity> specification, Expression<Func<TEntity, bool>> expression)
Parameters
specification
ISpecification<TEntity>expression
Expression<Func<TEntity, bool>>
Returns
- IEnumerable<TEntity>
Find(Expression<Func<TEntity, bool>>)
Returns the all element of a sequence, or a default value if the sequence contains no elements.
public IEnumerable<TEntity> Find(Expression<Func<TEntity, bool>> expression)
Parameters
expression
Expression<Func<TEntity, bool>>The Linq expression for query.
Returns
- IEnumerable<TEntity>
A task that represents the asynchronous operation. The sequence result contains the
TEntity
, or null.
FirstOrDefaultAsync(CancellationToken)
Returns the first element of a sequence, or a default value if the sequence contains no elements.
public Task<TEntity?> FirstOrDefaultAsync(CancellationToken cancellationToken = default)
Parameters
cancellationToken
CancellationTokenA CancellationToken to observe while waiting for the task to complete.
Returns
- Task<TEntity>
A task that represents the asynchronous operation. The task result contains the
T??
, or null.
GetBySpec(ISpecification<TEntity>, CancellationToken)
public Task<IEnumerable<TEntity>> GetBySpec(ISpecification<TEntity> specification, CancellationToken cancellationToken = default)
Parameters
specification
ISpecification<TEntity>cancellationToken
CancellationToken
Returns
- Task<IEnumerable<TEntity>>
Query(ISpecification<TEntity>, CancellationToken)
Returns the all element of a sequence, or a default value if the sequence contains no elements.
public IQueryable<TEntity> Query(ISpecification<TEntity> specification, CancellationToken cancellationToken = default)
Parameters
specification
ISpecification<TEntity>The encapsulated query logic.
cancellationToken
CancellationTokenA CancellationToken to observe while waiting for the task to complete.
Returns
- IQueryable<TEntity>
A task that represents the asynchronous operation. The IQueryable result contains the
TEntity
, or null.
Query(CancellationToken)
Returns the all element of a sequence, or a default value if the sequence contains no elements.
public IQueryable<TEntity> Query(CancellationToken cancellationToken = default)
Parameters
cancellationToken
CancellationTokenA CancellationToken to observe while waiting for the task to complete.
Returns
- IQueryable<TEntity>
A task that represents the asynchronous operation. The IQueryable result contains the
TEntity
, or null.
UpdateAsync(TEntity, CancellationToken)
Updates an entity in the database
public override Task<TEntity> UpdateAsync(TEntity entity, CancellationToken cancellationToken = default)
Parameters
entity
TEntityThe entity to update.
cancellationToken
CancellationToken
Returns
- Task<TEntity>
A task that represents the asynchronous operation.
UpdateRangeAsync(IEnumerable<TEntity>, CancellationToken)
Updates the given entities in the database
public override Task<IEnumerable<TEntity>> UpdateRangeAsync(IEnumerable<TEntity> entities, CancellationToken cancellationToken = default)
Parameters
entities
IEnumerable<TEntity>The entities to update.
cancellationToken
CancellationToken
Returns
- Task<IEnumerable<TEntity>>
A task that represents the asynchronous operation.