Skip to content

easyextensionsentityframeworkcoredatabaserepository BaseRepositoryT

BigMakCode edited this page Aug 5, 2024 · 1 revision

BaseRepository<TItem> Public class

Description

Create base repository based on database entity set with autosaving.

Diagram

  flowchart LR
  classDef interfaceStyle stroke-dasharray: 5 5;
  classDef abstractStyle stroke-width:4px
  subgraph EasyExtensions.EntityFrameworkCore.Abstractions
  EasyExtensions.EntityFrameworkCore.Abstractions.BaseEntity[[BaseEntity]]
  class EasyExtensions.EntityFrameworkCore.Abstractions.BaseEntity abstractStyle;
  end
  subgraph EasyExtensions.EntityFrameworkCore.Database.Repository
  EasyExtensions.EntityFrameworkCore.Database.Repository.BaseRepository_1[[BaseRepository< TItem >]]
  class EasyExtensions.EntityFrameworkCore.Database.Repository.BaseRepository_1 abstractStyle;
  EasyExtensions.EntityFrameworkCore.Database.Repository.BaseRepository_1TItem((TItem));
  EasyExtensions.EntityFrameworkCore.Database.Repository.BaseRepository_1 -- where --o EasyExtensions.EntityFrameworkCore.Database.Repository.BaseRepository_1TItem
EasyExtensions.EntityFrameworkCore.Abstractions.BaseEntity --> EasyExtensions.EntityFrameworkCore.Database.Repository.BaseRepository_1TItem

  EasyExtensions.EntityFrameworkCore.Database.Repository.IRepository_1[[IRepository< TItem >]]
  class EasyExtensions.EntityFrameworkCore.Database.Repository.IRepository_1 interfaceStyle;
  EasyExtensions.EntityFrameworkCore.Database.Repository.IRepository_1TItem((TItem));
  EasyExtensions.EntityFrameworkCore.Database.Repository.IRepository_1 -- where --o EasyExtensions.EntityFrameworkCore.Database.Repository.IRepository_1TItem
EasyExtensions.EntityFrameworkCore.Abstractions.BaseEntity --> EasyExtensions.EntityFrameworkCore.Database.Repository.IRepository_1TItem

  EasyExtensions.EntityFrameworkCore.Database.Repository.IRepository[[IRepository]]
  class EasyExtensions.EntityFrameworkCore.Database.Repository.IRepository interfaceStyle;
  end
EasyExtensions.EntityFrameworkCore.Database.Repository.IRepository_1 --> EasyExtensions.EntityFrameworkCore.Database.Repository.BaseRepository_1
EasyExtensions.EntityFrameworkCore.Database.Repository.IRepository --> EasyExtensions.EntityFrameworkCore.Database.Repository.IRepository_1
Loading

Members

Methods

Public methods

Returns Name
Task<TItem> CreateAsync(TItem item)
Task<bool> DeleteAsync(TItem item)
Task<int> DeleteRangeAsync(IEnumerable<TItem> items)
Task<Paging<TItem>> FilterAsync(...)
Filters and paginates the entities asynchronously based on the specified query.
Task<IEnumerable<TItem>> FindAsync(Expression<Func<TItem, bool>> predicate)
Task<TItem> GetByIdAsync(int id)
Retrieves an entity by its ID asynchronously.
Task<IList<TItem>> ListAsync(...)
IQueryable<TItem> Query()
Get queryable database set.
Task<int> SaveChangesAsync()
Saves all changes made in the context to the underlying database asynchronously.
Task<TItem> UpdateAsync(TItem item)

Details

Summary

Create base repository based on database entity set with autosaving.

Inheritance

Constructors

BaseRepository [1/2]

protected BaseRepository(DbSet<TItem> db, Func<CancellationToken, Task<int>> saveChangesCallback)
Arguments
Type Name Description
DbSet<TItem> db
Func<CancellationToken, Task<int>> saveChangesCallback

BaseRepository [2/2]

public BaseRepository(DbSet<TItem> db)
Arguments
Type Name Description
DbSet<TItem> db

Methods

GetByIdAsync

public virtual async Task<TItem> GetByIdAsync(int id)
Arguments
Type Name Description
int id The ID of the entity.
Summary

Retrieves an entity by its ID asynchronously.

Returns

A task that represents the asynchronous operation. The task result contains the entity with the specified ID.

CreateAsync

public virtual async Task<TItem> CreateAsync(TItem item)
Arguments
Type Name Description
TItem item

DeleteAsync

public virtual async Task<bool> DeleteAsync(TItem item)
Arguments
Type Name Description
TItem item

DeleteRangeAsync

public virtual async Task<int> DeleteRangeAsync(IEnumerable<TItem> items)
Arguments
Type Name Description
IEnumerable<TItem> items

UpdateAsync

public virtual async Task<TItem> UpdateAsync(TItem item)
Arguments
Type Name Description
TItem item

FilterAsync [1/2]

public virtual async Task<Paging<TItem>> FilterAsync(IGridifyQuery query)
Arguments
Type Name Description
IGridifyQuery query The query parameters for filtering and pagination.
Summary

Filters and paginates the entities asynchronously based on the specified query.

Returns

A task that represents the asynchronous operation. The task result contains the filtered and paginated entities.

FilterAsync [2/2]

public virtual async Task<Paging<TItem>> FilterAsync(IGridifyQuery query, IGridifyMapper<TItem> mapper)
Arguments
Type Name Description
IGridifyQuery query
IGridifyMapper<TItem> mapper

FindAsync

public virtual Task<IEnumerable<TItem>> FindAsync(Expression<Func<TItem, bool>> predicate)
Arguments
Type Name Description
Expression<Func<TItem, bool>> predicate

ListAsync [1/2]

public virtual async Task<IList<TItem>> ListAsync(Expression<Func<TItem, bool>> predicate)
Arguments
Type Name Description
Expression<Func<TItem, bool>> predicate

ListAsync [2/2]

public virtual async Task<IList<TItem>> ListAsync()
Summary

Gets all entities asynchronously.

Returns

A task that represents the asynchronous operation. The task result contains a collection of all entities.

SaveChangesAsync

public virtual async Task<int> SaveChangesAsync()
Summary

Saves all changes made in the context to the underlying database asynchronously.

Returns

A task that represents the asynchronous save operation. The task result contains the number of state entries written to the database.

Query

public virtual IQueryable<TItem> Query()
Summary

Get queryable database set.

Returns

Queryable database set.

Generated with ModularDoc

Clone this wiki locally