IGenericRepository

Namespace: Babel.Data Assembly: Babel.Data.dll

Interface for generic repository.

public interface IGenericRepository<TEntity> where TEntity : class

Type Parameters

NameDescription

TEntity

Type of the entity.

Properties

DbSet

Gets the set the database belongs to.

DbSet<TEntity> DbSet { get; }

Property Value

DbSet<TEntity>

Methods

CountAsync(Expression<Func<TEntity, bool>>, CancellationToken)

Asynchronously returns the number of elements in the repository.

Task<int> CountAsync(Expression<Func<TEntity, bool>> filter = null, CancellationToken cancellationToken = default)

Parameters

NameDescription

filter Expression<Func<TEntity, bool>>

(Optional) Specifies the filter.

cancellationToken CancellationToken

(Optional) A token that allows processing to be cancelled.

Returns

NameDescription

An asynchronous result that yields the number of elements in the repository.

CountAsync(string, CancellationToken)

Asynchronously returns the number of elements in the repository.

Task<int> CountAsync(string filter, CancellationToken cancellationToken = default)

Parameters

NameDescription

filter string

Specifies the string filter.

cancellationToken CancellationToken

(Optional) A token that allows processing to be cancelled.

Returns

NameDescription

An asynchronous result that yields the number of elements in the repository.

Delete(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

void Delete(object[] ids)

Parameters

NameDescription

ids object[]

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.

void Delete(TEntity entityToDelete)

Parameters

NameDescription

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.

IList<TEntity> Get(Expression<Func<TEntity, bool>> filter = null, Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>> orderBy = null, string columns = "", string includeProperties = "", int? skip = null, int? take = null)

Parameters

NameDescription

filter Expression<Func<TEntity, bool>>

(Optional) Specifies the filter expression.

orderBy Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>>

(Optional) Order by expression.

columns string

(Optional) A comma separated list of column names to retrieve.

includeProperties string

(Optional) A comma separated list of nested entity names to retrieve.

skip int?

(Optional) The number of records to skip before the first record found.

take int?

(Optional) The number of records to take after the first record found.

Returns

NameDescription

IList<TEntity>

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.

Task<List<TEntity>> GetAsync(Expression<Func<TEntity, bool>> filter = null, Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>> orderBy = null, string columns = "", string includeProperties = "", int? skip = null, int? take = null, CancellationToken cancellationToken = default)

Parameters

NameDescription

filter Expression<Func<TEntity, bool>>

(Optional) Specifies the filter expression.

orderBy Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>>

(Optional) Order by expression.

columns string

(Optional) A comma separated list of column names to retrieve.

includeProperties string

(Optional) A comma separated list of nested entity names to retrieve.

skip int?

(Optional) The number of records to skip before the first record found.

take int?

(Optional) The number of records to take after the first record found.

cancellationToken CancellationToken

(Optional) A token that allows processing to be cancelled.

Returns

NameDescription

Task<List<TEntity>>

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.

TEntity GetById(params object[] ids)

Parameters

NameDescription

ids object[]

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.

Task<TEntity> GetByIdAsync(params object[] ids)

Parameters

NameDescription

ids object[]

The values of the primary key for the entity to be found.

Returns

NameDescription

Task<TEntity>

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.

Task<TEntity> GetByIdAsync(object[] ids, CancellationToken cancellationToken = default)

Parameters

NameDescription

ids object[]

The values of the primary key for the entity to be found.

cancellationToken CancellationToken

(Optional) A token that allows processing to be cancelled.

Returns

NameDescription

Task<TEntity>

A task that represents the asynchronous get operation. The task result contains the entity found, or null.

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

void Insert(TEntity entity)

Parameters

NameDescription

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

Task<EntityEntry<TEntity>> InsertAsync(TEntity entity, CancellationToken cancellationToken = default)

Parameters

NameDescription

entity TEntity

The entity.

cancellationToken CancellationToken

(Optional) A token that allows processing to be cancelled.

Returns

NameDescription

Task<EntityEntry<TEntity>>

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.

Task<List<TEntity>> QueryAsync(string select = null, string filter = null, string orderBy = null, string includeProperties = "", int? skip = null, int? take = null, CancellationToken cancellationToken = default)

Parameters

NameDescription

select string

(Optional) Specifies a select expression.

filter string

(Optional) Specifies the filter expression.

orderBy string

(Optional) Order by expression.

includeProperties string

(Optional) A comma separated list of nested entity names to retrieve.

skip int?

(Optional) The number of records to skip before the first record found.

take int?

(Optional) The number of records to take after the first record found.

cancellationToken CancellationToken

(Optional) A token that allows processing to be cancelled.

Returns

NameDescription

Task<List<TEntity>>

A task that represents the asynchronous get operation.

Save()

Saves all changes made in this repository to the underlying database.

bool Save()

Returns

NameDescription

True if it succeeds, false if it fails.

SaveAsync(CancellationToken)

Asynchronously saves all changes made in this repository to the underlying database.

Task<bool> SaveAsync(CancellationToken cancellationToken = default)

Parameters

NameDescription

cancellationToken CancellationToken

(Optional) A token that allows processing to be cancelled.

Returns

NameDescription

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.

void Update(TEntity entityToUpdate)

Parameters

NameDescription

entityToUpdate TEntity

The entity to update.

Last updated