GenericRepository
Namespace: Babel.Data Assembly: Babel.Data.dll
A generic repository.
Type Parameters
TEntity
Type of the entity.
Inheritance
object ← GenericRepository<TEntity>
Implements
Inherited Members
object.GetType(), object.MemberwiseClone(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()
Constructors
GenericRepository(BabelDbContext)
Initializes a new instance of the GenericRepository class.
Parameters
The database context.
Properties
Context
Gets the Babel database context.
Property Value
DbSet
Gets the set the database belongs to.
Property Value
DbSet<TEntity>
NoTracking
Whether to disable entity tracking
Property Value
Methods
CountAsync(Expression<Func<TEntity, bool>>, CancellationToken)
Asynchronously returns the number of elements in the repository.
Parameters
(Optional) Specifies the filter.
(Optional) A token that allows processing to be cancelled.
Returns
An asynchronous result that yields the number of elements in the repository.
CountAsync(string, CancellationToken)
Asynchronously returns the number of elements in the repository.
Parameters
Specifies the string filter.
(Optional) A token that allows processing to be cancelled.
Returns
An asynchronous result that yields the number of elements in the repository.
Delete(params object[])
Deletes an entity with the given primary key values. Begins tracking the given entity in the Detached state such that it will be deleted in the database when SaveChanges() is called.
Parameters
The values of the primary key for the entity to be found.
Delete(TEntity)
Deletes the given entity from the repository. Begins tracking the given entity in the Detached state such that it will be deleted in the database when SaveChanges() is called.
Parameters
entityToDelete
TEntity
The entity to delete.
Get(Expression<Func<TEntity, bool>>, Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>>, string, string, int?, int?)
Gets a list of entities from this repository.
Parameters
(Optional) Specifies the filter expression.
(Optional) Order by expression.
(Optional) A comma separated list of column names to retrieve.
(Optional) A comma separated list of nested entity names to retrieve.
(Optional) The number of records to skip before the first record found.
(Optional) The number of records to take after the first record found.
Returns
A list of entities.
GetAsync(Expression<Func<TEntity, bool>>, Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>>, string, string, int?, int?, CancellationToken)
Asynchronously gets a list of entities from this repository.
Parameters
(Optional) Specifies the filter expression.
(Optional) Order by expression.
(Optional) A comma separated list of column names to retrieve.
(Optional) A comma separated list of nested entity names to retrieve.
(Optional) The number of records to skip before the first record found.
(Optional) The number of records to take after the first record found.
(Optional) A token that allows processing to be cancelled.
Returns
A task that represents the asynchronous get operation.
GetById(params object[])
Gets an entity with the given primary key values. If an entity with the given primary key values exists in the context, then it is returned immediately without making a request to the store. Otherwise, a request is made to the store for an entity with the given primary key values and this entity, if found, is attached to the context and returned. If no entity is found in the context or the store, then null is returned.
Parameters
The values of the primary key for the entity to be found.
Returns
GetByIdAsync(params object[])
Asynchronously gets an entity with the given primary key values. If an entity with the given primary key values exists in the context, then it is returned immediately without making a request to the store. Otherwise, a request is made to the store for an entity with the given primary key values and this entity, if found, is attached to the context and returned. If no entity is found in the context or the store, then null is returned.
Parameters
The values of the primary key for the entity to be found.
Returns
A task that represents the asynchronous get operation. The task result contains the entity found, or null.
GetByIdAsync(object[], CancellationToken)
Asynchronously gets an entity with the given primary key values. If an entity with the given primary key values exists in the context, then it is returned immediately without making a request to the store. Otherwise, a request is made to the store for an entity with the given primary key values and this entity, if found, is attached to the context and returned. If no entity is found in the context or the store, then null is returned.
Parameters
The values of the primary key for the entity to be found.
(Optional) A token that allows processing to be cancelled.
Returns
A task that represents the asynchronous get operation. The task result contains the entity found, or null.
GroupByAsync(string, string, int?, int?, CancellationToken)
Asynchronously groups a list of entities from this repository.
Parameters
(Optional) Specifies the filter expression.
(Optional) Group by expression.
(Optional) The number of records to skip before the first record found.
(Optional) The number of records to take after the first record found.
(Optional) A token that allows processing to be cancelled.
Returns
A task that represents the asynchronous get operation.
Insert(TEntity)
Inserts the given entity in the repository. Begins tracking the given entity, and any other reachable entities that are not already being tracked, in the Added state such that they will be inserted into the database when SaveChanges() is called
Parameters
entity
TEntity
The entity to be inserted.
InsertAsync(TEntity, CancellationToken)
Asynchronously inserts the given entity in the repository. Begins tracking the given entity, and any other reachable entities that are not already being tracked, in the Added state such that they will be inserted into the database when SaveChanges() is called
Parameters
entity
TEntity
The entity.
(Optional) A token that allows processing to be cancelled.
Returns
A task that represents the asynchronous Insert operation.
QueryAsync(string, string, string, string, int?, int?, CancellationToken)
Asynchronously query a list of entities from this repository.
Parameters
(Optional) Specifies a select expression.
(Optional) Specifies the filter expression.
(Optional) Order by expression.
(Optional) A comma separated list of nested entity names to retrieve.
(Optional) The number of records to skip before the first record found.
(Optional) The number of records to take after the first record found.
(Optional) A token that allows processing to be cancelled.
Returns
A task that represents the asynchronous get operation.
Save()
Saves all changes made in this repository to the underlying database.
Returns
True if it succeeds, false if it fails.
SaveAsync(CancellationToken)
Asynchronously saves all changes made in this repository to the underlying database.
Parameters
(Optional) A token that allows processing to be cancelled.
Returns
A task that represents the asynchronous save operation.
Update(TEntity)
Updates the given entity in the repository. Begins tracking the given entity in the Modified state such that it will be updated in the database when SaveChanges() is called.
Parameters
entityToUpdate
TEntity
The entity to update.
Last updated