UnitOfWork.EntityFrameworkCore
5.3.1
There is a newer version of this package available.
See the version list below for details.
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
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#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
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
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.
Product | Versions 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.
-
net5.0
- Microsoft.EntityFrameworkCore (>= 5.0.10)
- Microsoft.EntityFrameworkCore.AutoHistory (>= 5.0.7)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.