UnitOfWork.EntityFrameworkCore 5.3.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package UnitOfWork.EntityFrameworkCore --version 5.3.1
NuGet\Install-Package UnitOfWork.EntityFrameworkCore -Version 5.3.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="UnitOfWork.EntityFrameworkCore" Version="5.3.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add UnitOfWork.EntityFrameworkCore --version 5.3.1
#r "nuget: UnitOfWork.EntityFrameworkCore, 5.3.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install UnitOfWork.EntityFrameworkCore as a Cake Addin
#addin nuget:?package=UnitOfWork.EntityFrameworkCore&version=5.3.1

// Install UnitOfWork.EntityFrameworkCore as a Cake Tool
#tool nuget:?package=UnitOfWork.EntityFrameworkCore&version=5.3.1

UnitOfWork.EntityFrameworkCore

A plugin for Microsoft.EntityFrameworkCore to support repository, unit of work patterns, and multiple database with distributed transaction supported.

Installation

Install-Package UnitOfWork.EntityFrameworkCore -Version 5.3.1

Usage

The following code demonstrates basic usage.

First of all, please register the dependencies into the MS Built-In container:

services.AddDbContext<ExampleDbContext>(options =>
            {
                options.UseSqlServer(Configuration.GetConnectionString(SystemConstants.MainConnectionString), sqlServerOptions =>
                {
                    sqlServerOptions.MigrationsAssembly((typeof(ExampleDbContext).Assembly).GetName().Name);
                });
            }).AddUnitOfWork<ExampleDbContext>();

After that, use the structure in your code like that:

private readonly IUnitOfWork _unitOfWork;
// Injection
 public ExampleController(IUnitOfWork<ExampleDbContext> unitOfWork )
        {
            _unitOfWork = unitOfWork;
        }

#returns GetAll

public async Task GetAll(){
  var books= _unitOfWork.GetRepository<Book>().GetAll();
}

returns Get ByFilter

public async Task GetAllByFilter(){
  var blogs = _unitOfWork.GetRepository<Book>().GetAllByFilter(
                predicate: x => x.Descriptions.Contains("Book Example"),
                orderBy: x => x.OrderByDescending(i => i.DateCreated),
                include: x => x.Include(i => i.Category));
}

returns GetPaging

public async Task GetAllByFilter(){
   var blogs = _unitOfWork.GetRepository<Blog>().GetPagedListAsync(
               predicate: x => x.Descriptions.Contains("Book Example"),
               orderBy: x => x.OrderByDescending(i => i.DateCreated),
               include: x => x.Include(i => i.Category),
               pageIndex:1,pageSize:20);
}

returns GetStagesPaging

public async Task GetStagesPaging(){
   var repository = _unitOfWork.GetRepository<Book>();
   var query = repository.Queryable()
                .Where(x => x.Descriptions.Contains("Book Example"));
   var books= _unitOfWork.GetRepository<Book>().GetStagesPagedListAsync(
               stages: query,
               selector:x=>x.Descriptions,
               pageIndex: 1, pageSize: 20);
}

returns GetBookById

public async Task voidGetBookById(int id){
  var book= await _unitOfWork.GetRepository<Book>().FindAsync(id);
}

returns AddBook

public async Task AddBook(Book book){
    await _unitOfWork.GetRepository<Book>().InsertAsync(book);
    await _unitOfWork.SaveChangesAsync();
}

returns UpdateBook

public async Task UpdateBook(Book book){
    _unitOfWork.GetRepository<Book>().Update(book);
    await _unitOfWork.SaveChangesAsync();
}

returns DeleteBook

public async Task DeleteBook(int id){
    _unitOfWork.GetRepository<Book>().Delete(id);
    await _unitOfWork.SaveChangesAsync();
}

returns GetBookCount

public async Task GetBookCount(){
   var count= _unitOfWork.GetRepository<Book>().CountAsync(id);
}

......................

The operations above are also available as async.

Support / Contributing

If you want to help with the project, feel free to open pull requests and submit issues.

https://github.com/minhyentcu/EFCore.UnitOfWork

Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
7.0.2 195 10/14/2023
7.0.1 116 10/14/2023
6.0.3 689 3/2/2022
6.0.2 454 2/22/2022
5.3.1 436 10/11/2021
5.3.0 321 10/11/2021
5.2.1 322 10/9/2021
5.2.0 314 10/8/2021
5.1.0 318 10/8/2021
5.0.0 381 10/8/2021