Class EfCoreRepository<TEntity, TKey>
- Namespace
- Savvyio.Extensions.EFCore
- Assembly
- Savvyio.Extensions.EFCore.dll
Provides a default implementation of the IPersistentRepository<TEntity, TKey> interface to serve as an abstraction layer before the actual I/O communication with a source of data using Microsoft Entity Framework Core.
public class EfCoreRepository<TEntity, TKey> : IPersistentRepository<TEntity, TKey>, IWritableRepository<TEntity, TKey>, IReadableRepository<TEntity, TKey>, ISearchableRepository<TEntity, TKey>, IDeletableRepository<TEntity, TKey>, IRepository<TEntity, TKey> where TEntity : class, IIdentity<TKey>
Type Parameters
TEntityThe type of the entity.
TKeyThe type of the key that uniquely identifies the entity.
- Inheritance
-
EfCoreRepository<TEntity, TKey>
- Implements
-
IPersistentRepository<TEntity, TKey>IWritableRepository<TEntity, TKey>IReadableRepository<TEntity, TKey>ISearchableRepository<TEntity, TKey>IDeletableRepository<TEntity, TKey>IRepository<TEntity, TKey>
- Derived
Constructors
EfCoreRepository(IEfCoreDataSource)
Initializes a new instance of the EfCoreRepository<TEntity, TKey> class.
public EfCoreRepository(IEfCoreDataSource source)
Parameters
sourceIEfCoreDataSourceThe IEfCoreDataSource that handles actual I/O communication with a source of data.
Properties
Set
Gets the associated DbSet<TEntity> for this repository.
protected DbSet<TEntity> Set { get; }
Property Value
- DbSet<TEntity>
The associated DbSet<TEntity> for this repository.
Methods
Add(TEntity)
Marks the specified entity to be added in the data store when SaveChangesAsync(Action<AsyncOptions>) is called.
public virtual void Add(TEntity entity)
Parameters
entityTEntityThe entity to add.
AddRange(IEnumerable<TEntity>)
Marks the specified entities to be added in the data store when SaveChangesAsync(Action<AsyncOptions>) is called.
public virtual void AddRange(IEnumerable<TEntity> entities)
Parameters
entitiesIEnumerable<TEntity>The entities to add.
FindAllAsync(Expression<Func<TEntity, bool>>, Action<AsyncOptions>)
Finds all entities matching the specified predicate asynchronous.
public virtual Task<IEnumerable<TEntity>> FindAllAsync(Expression<Func<TEntity, bool>> predicate = null, Action<AsyncOptions> setup = null)
Parameters
predicateExpression<Func<TEntity, bool>>The predicate that matches the entities to retrieve.
setupAction<AsyncOptions>The AsyncOptions which may be configured.
Returns
- Task<IEnumerable<TEntity>>
A Task<TResult> that represents the asynchronous operation. The task result either contains the matching entities of the operation or an empty sequence if no match was found.
GetByIdAsync(TKey, Action<AsyncOptions>)
Loads the entity from the specified id asynchronous.
public virtual Task<TEntity> GetByIdAsync(TKey id, Action<AsyncOptions> setup = null)
Parameters
idTKeyThe key that uniquely identifies the entity.
setupAction<AsyncOptions>The AsyncOptions which may be configured.
Returns
- Task<TEntity>
A Task<TResult> that represents the asynchronous operation. The task result either contains the entity of the operation or
nullif not found.
Remove(TEntity)
Marks the specified entity to be removed from the data store when SaveChangesAsync(Action<AsyncOptions>) is called.
public virtual void Remove(TEntity entity)
Parameters
entityTEntityThe entity to remove.
RemoveRange(IEnumerable<TEntity>)
Marks the specified entities to be removed from the data store when SaveChangesAsync(Action<AsyncOptions>) is called.
public virtual void RemoveRange(IEnumerable<TEntity> entities)
Parameters
entitiesIEnumerable<TEntity>The entities to remove.