Repositories - Nano-Core/Nano.Library GitHub Wiki
Repositories represents data repositories within an application.
The IRepository
interface contains methods for getting, querying, adding, updating and deleting models in the application. Inject this, when implementations requires access to the application data.
The BaseRepository<TContext>
implements the interface, and ensures data is stored and retrieved through the data context defined by the generic class parameter and injected into the constructor when resolved at runtime.
The DefaultRepository
derives from BaseRepository<DefaultDbContext>
. and the DefaultDbContext
contains overridden methods for saving changes, featuring eventing by annotation and custom extensions for entity framework.
The services follow the UnitOfWork
pattern.
The BaseRepository<TContext>
implementation contains various methods for getting, querying, updating, adding and deleting entities in the data context defined by the generic type parameter TContext
. This dependency is registered when configuring the data provider.
The methods definitions of IRepository
, has different generic type constraints, depending on the operation. For instance AddAsync<TEntity>
, is constrained to models implementing IEntityCreatable
.
The IRepository
also contains a property, to access the underlying DbSet
of an entity,
DbSet<TEntity> GetEntitySet<TEntity>()
Use it for advanced operations not directly supported by the repository implementation.
Type | Method | Description |
---|---|---|
Get | IEntity GetAsync<IEntity, TIdentity>(key) |
Finds the entity with the provided unique key. Overloads exists for int , long , string and Guid (to avoid specify the TIdentity type parameter. |
Get First | IEntity GetFirstAsync<IEntity>(expression); |
Finds the first entity, matching the expression. |
Get First | TEntity GetFirstAsync<TEntity, TCriteria>(IQuery<TCriteria> criteria) |
Finds the first entity satisfying the criteria. |
Get Many | IEnumerable<IEntity> GetManyAsync<IEntity>(keys); |
Finds all entities with a key in the provided keys array. |
Get Many | IEnumerable<TEntity> GetManyAsync<TEntity>(query) |
Finds all entities satisfying the query. |
Get Many | IEnumerable<TEntity> GetManyAsync<TEntity, TCriteria>(IQuery<TCriteria> criteria) |
Finds all entities satisfying the criteria. |
Get Many | IEnumerable<IEntity> GetManyAsync<IEntity>(expression); |
Finds all entities satisfying the expression. |
Get Many | IEnumerable<IEntity> GetManyAsync<IEntity>(expression, pagination); |
Finds all entities satisfying the expression, and returns results based on the pagination. |
Get Many | IEnumerable<IEntity> GetManyAsync<IEntity>(expression, pagination, ordering); |
Finds all entities satisfying the expression, and returns results based on the pagination and ordering. |
Get Many | IEnumerable<IEntity> GetManyAsync<IEntity, TKey>(expression, orderBy, pagination, orderingDirection); |
Finds all entities satisfying the expression, and returns results based on the pagination and order by expression. |
Add | EntityCreatable AddAsync<IEntityCreatable>(entity); |
Adds the provided entity. |
Add And Get | EntityCreatable AddAndGetAsync<IEntityCreatable>(entity); |
Adds the provided entity, and reloads it with includes. |
Add Many | void AddManyAsync<IEntityCreatable>(entities); |
Adds the provided array of entities. |
Add Many Bulk | void AddManyBulkAsync<IEntityCreatable>(entities) |
Bulk adds the provided array of entities. |
Update | IEntityUpdatable Update<IEntityUpdatable>(entity); |
Updates the provided entity. |
Update And Get | IEntityUpdatable Update<IEntityUpdatable>(entity); |
Updates the provided entity, and reloads it with includes. |
Update Many | void UpdateManyAsync<IEntityUpdatable>(entities); |
Updates the provided array of entities. |
Update Many Query | void UpdateManyQueryAsync<IEntityUpdatable>(expression, propertiesUpdate); |
Updates the entities that matches the expression. |
Update Many Bulk | void UpdateManyBulkAsync<IEntityCreatable>(entities) |
Bulk updates the provided array of entities. |
Add / Update | IEntityCreatableOrUpdatable AddOrUpdateAsync<IEntityCreatableAndUpdatable>(entity); |
Adds or updates the provided entity. |
Add / Update Many | void AddOrUpdateManyAsync<IEntityCreatableAndUpdatable>(entities); |
Adds or updates the provided array of entities. |
Delete | void DeleteAsync<IEntityDeletable>(id); |
Deletes the entity with the provided id. |
Delete | void DeleteAsync<IEntityDeletable>(entity); |
Deletes the provided entity. |
Delete Many | void DeleteManyAsync<IEntityDeletable>(entities); |
Deletes the provided array of entities. |
Delete Many | void DeleteManyAsync<TEntityDeletable, TCriteria>(critiera) |
Deletes all the entities satisfying the provided criteria. |
Delete Many | void DeleteManyAsync<IEntityDeletable>(expression); |
Deletes all the entities satisfying the provided expression. |
Delete Many Query | void DeleteManyQueryAsync<IEntityUpdatable>(expression); |
deletes the entities that matches the expression. |
Delete Many Bulk | void DeleteManyBulkAsync<TEntityDeletable, TCriteria>(critiera) |
Deletes all the entities satisfying the provided criteria. |
Delete Many Bulk | void DeleteManyBulkAsync<IEntityDeletable>(expression); |
Deletes all the entities satisfying the provided expression. |
Delete Many Bulk | void DeleteManyBulkAsync<IEntityDeletable>(ids); |
Bulk deletes (hard) the entities of the provided array of id's. |
Delete Many Bulk | void DeleteManyBulkAsync<IEntityDeletable>(entities); |
Bulk deletes (hard) the provided array of entities. |
Count | void CountAsync<TEntity>(criteria) |
Gets the count of elements satisfying the provided criteria. |
Count | void CountAsync<TEntity>(expression) |
Gets the count of elements satisfying the provided expression. |
Sum | void SumAsync<TEntity>(whereExpr, sumExpr) |
Gets the sum of a property, of elements satisfying the provided expression. |
Average | void AverageAsync<TEntity>(whereExpr, sumExpr) |
Gets the average of a property, of elements satisfying the provided expression. |
Nano.Repository.Interfaces.IRepository
Nano.Repository.Interfaces.IRepositorySpatial
Nano.Repository.BaseRepository
Nano.Repository.BaseRepositorySpatial
Nano.Repository.DefaultRepository
Nano.Repository.DefaultRepositorySpatial
For a full list of services and dependencies, see Injected Dependencies