Skip to content

Base Repository Classes

Dennis C. Mitchell edited this page Mar 16, 2019 · 22 revisions

(under construction) EDennis.AspNetCore.Base provides four base repository classes, which cross writeability with temporality. Two of the base repos are writeable and two are readonly. Two of the base repos have temporal support (write to history tables) and two do not have temporal support. The table below summarizes the four repo types.

4 Repo Types Image

WriteableRepo

WriteableRepo provides methods for reading from and writing to current-record tables.

Type Parameters

WriteableRepo has two type parameters:

Type Parameter Constraints
TEntity TEntity is a class with a default constructor and implements IHasSysUser
TContext TContext extends Microsoft.EntityFrameworkCore.DbContext

Constructor

The WriteableRepo constructor accepts two arguments:

  • TContext -- any subclass of Entity Framework Core's DbContext
  • ScopeProperties -- a class designed to communicate the user name and other data (e.g., headers) from one or more MVC filters to the repo. This class should be dependency injected with a scoped lifetime.
public WriteableRepo(TContext context, ScopeProperties scopeProperties)

Methods

WriteableRepo provides basic CRUD methods, which automatically save data to the database when needed.

Method Description
public virtual TEntity GetById(params object[] keyValues) Retrieve a record by the primary key
public virtual async Task<TEntity> GetByIdAsync(params object[] keyValues) Asynchronous version of GetById
public virtual bool Exists(params object[] keyValues) Determine if a record with the provided key exists
public virtual async Task<bool> ExistsAsync(params object[] keyValues) Asynchronous version of Exists
public virtual TEntity Create(TEntity entity) Inserts a new TEntity record into the database
public virtual async Task<TEntity> CreateAsync(TEntity entity) Asynchronous version of Create
public virtual TEntity Update(TEntity entity, params object[] keyValues) Replaces the TEntity record with data from the provided object
public virtual async Task<TEntity> UpdateAsync(TEntity entity, params object[] keyValues) Asynchronous version of Update
public virtual void Delete(params object[] keyValues) Delete the record with the provided primary key
public virtual async Task DeleteAsync(params object[] keyValues) Asynchronous version of Delete

Clone this wiki locally