Encamina.Enmarcha.Data.EntityFramework
8.1.7-preview-08
See the version list below for details.
dotnet add package Encamina.Enmarcha.Data.EntityFramework --version 8.1.7-preview-08
NuGet\Install-Package Encamina.Enmarcha.Data.EntityFramework -Version 8.1.7-preview-08
<PackageReference Include="Encamina.Enmarcha.Data.EntityFramework" Version="8.1.7-preview-08" />
paket add Encamina.Enmarcha.Data.EntityFramework --version 8.1.7-preview-08
#r "nuget: Encamina.Enmarcha.Data.EntityFramework, 8.1.7-preview-08"
// Install Encamina.Enmarcha.Data.EntityFramework as a Cake Addin #addin nuget:?package=Encamina.Enmarcha.Data.EntityFramework&version=8.1.7-preview-08&prerelease // Install Encamina.Enmarcha.Data.EntityFramework as a Cake Tool #tool nuget:?package=Encamina.Enmarcha.Data.EntityFramework&version=8.1.7-preview-08&prerelease
Data - Entity Framework
Entity Framework Data project primarily contains Entity Framework implementations based on the abstractions provided by Encamina.Enmarcha.Data.Abstractions, as well as some other utilities related to Entity Framework.
Setup
Nuget package
First, install NuGet. Then, install Encamina.Enmarcha.Data.EntityFramework from the package manager console:
PM> Install-Package Encamina.Enmarcha.Data.EntityFramework
.NET CLI:
First, install .NET CLI. Then, install Encamina.Enmarcha.Data.EntityFramework from the .NET CLI:
dotnet add package Encamina.Enmarcha.Data.EntityFramework
How to use
In the following example, we will demonstrate how to configure and add an Entity Framework implementation of the IFullUnitOfWork interface to the ServiceCollection
, based on the FullUnitOfWork, using the following DbContext
.
public class Foo
{
public int Id { get; set; }
public string Text { get; set; }
}
public class Bar
{
public int Id { get; set; }
public string Text { get; set; }
}
public class MyDBContext : DbContext
{
public DbSet<Foo> Foos { get; set; }
public DbSet<Bar> Bars { get; set; }
}
The next step is to inherit from FullUnitOfWork
and create a custom class that receives an instance of MyDBContext
in its constructor.
public class MyFullUnitOfWork: FullUnitOfWork, IFullUnitOfWork
{
public MyFullUnitOfWork(MyDBContext dbContext)
: base(dbContext)
{
}
}
In the Program.cs
or a similar entry point file in your project, add the following code:
// Entry point
var builder = WebApplication.CreateBuilder(new WebApplicationOptions
{
// ...
});
// ...
services.AddDbContext<DatabaseContext>(opt =>
{
opt.UseSqlServer(configuration.GetConnectionString("DefaultConnection")); // Configures your provider
}, ServiceLifetime.Scoped);
// ...
builder.Services.AddScoped<IFullUnitOfWork, MyFullUnitOfWork>();
And now, we can resolve the IFullUnitOfWork
interface with construction injection:
public class MyClass
{
private readonly IFullUnitOfWork uow;
public MyClass(IFullUnitOfWork uow)
{
this.uow = uow;
}
public async Task TestAddFooAndBarAndSaveAsync(CancellationToken cts)
{
var fooRepository = uow.GetAsyncRepository<Foo>();
var barRepository = uow.GetAsyncRepository<Bar>();
await fooRepository.AddAsync(new Foo() { Text = "Foo1" }, cts);
await fooRepository.AddAsync(new Foo() { Text = "Foo2" }, cts);
await barRepository.AddAsync(new Bar() { Text = "Bar1" }, cts);
await uow.SaveAsync(cts);
}
}
Within the NuGet package, there are more interfaces along with their corresponding base implementations.
- AsyncReadRepositoryBase<TEntity>: Base class for asynchronous read repositories. It implements IAsyncReadRepository<TEntity>.
- AsyncRepositoryBase<TEntity>: Base class for asynchronous repositories. It implements IAsyncRepository<TEntity>.
- AsyncUnitOfWorkBase: Base class for an asynchronous unit of work. It implements IAsyncUnitOfWork.
- AsyncWriteRepositoryBase<TEntity>: Base class for asynchronous write repositories. It implements IAsyncWriteRepository<TEntity>.
- FullRepositoryBase<TEntity>: Base class for a repository with both synchronous and asynchronous operations to read and write entities. It implements IFullRepository<TEntity>.
- FullUnitOfWork: Base class for a unit of work that can manage both synchronous and asynchronous operations. It implements IFullUnitOfWork.
- ReadRepositoryBase<TEntity>: Base class for a read repositories. It implements IReadRepository<TEntity>.
- RepositoryBase<TEntity>: Base class for a repositories. It implements IRepository<TEntity>.
- UnitOfWorkBase: Base class for an unit of work. It implements IUnitOfWork.
- WriteRepositoryBase<TEntity>: Base class for write repositories. It implements IWriteRepository<TEntity>.
Other functionalities
Inside the NuGet package, you will find some extension methods related to Entity Framework.
// ...
var queryableFoo = dbContext.AsQueryable<Foo>(withNoTracking: true, withIdentityResolution: true);
// More methods available in DbContextExtensions...
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. 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. |
-
net8.0
- CommunityToolkit.Diagnostics (>= 8.2.2)
- Encamina.Enmarcha.Data.Abstractions (>= 8.1.7-preview-08)
- Microsoft.EntityFrameworkCore (>= 8.0.6)
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 |
---|---|---|
8.2.0 | 69 | 10/22/2024 |
8.2.0-preview-01-m01 | 93 | 9/17/2024 |
8.1.9-preview-03 | 55 | 11/19/2024 |
8.1.9-preview-02 | 71 | 10/22/2024 |
8.1.9-preview-01 | 59 | 10/4/2024 |
8.1.8 | 82 | 9/23/2024 |
8.1.8-preview-07 | 79 | 9/12/2024 |
8.1.8-preview-06 | 95 | 9/11/2024 |
8.1.8-preview-05 | 93 | 9/10/2024 |
8.1.8-preview-04 | 103 | 8/16/2024 |
8.1.8-preview-03 | 102 | 8/13/2024 |
8.1.8-preview-02 | 98 | 8/13/2024 |
8.1.8-preview-01 | 89 | 8/12/2024 |
8.1.7 | 97 | 8/7/2024 |
8.1.7-preview-09 | 108 | 7/3/2024 |
8.1.7-preview-08 | 90 | 7/2/2024 |
8.1.7-preview-07 | 89 | 6/10/2024 |
8.1.7-preview-06 | 81 | 6/10/2024 |
8.1.7-preview-05 | 97 | 6/6/2024 |
8.1.7-preview-04 | 91 | 6/6/2024 |
8.1.7-preview-03 | 85 | 5/24/2024 |
8.1.7-preview-02 | 95 | 5/10/2024 |
8.1.7-preview-01 | 88 | 5/8/2024 |
8.1.6 | 113 | 5/7/2024 |
8.1.6-preview-08 | 55 | 5/2/2024 |
8.1.6-preview-07 | 89 | 4/29/2024 |
8.1.6-preview-06 | 86 | 4/26/2024 |
8.1.6-preview-05 | 88 | 4/24/2024 |
8.1.6-preview-04 | 74 | 4/22/2024 |
8.1.6-preview-03 | 88 | 4/22/2024 |
8.1.6-preview-02 | 90 | 4/17/2024 |
8.1.6-preview-01 | 92 | 4/15/2024 |
8.1.5 | 126 | 4/15/2024 |
8.1.5-preview-15 | 86 | 4/10/2024 |
8.1.5-preview-14 | 94 | 3/20/2024 |
8.1.5-preview-13 | 82 | 3/18/2024 |
8.1.5-preview-12 | 105 | 3/13/2024 |
8.1.5-preview-11 | 90 | 3/13/2024 |
8.1.5-preview-10 | 86 | 3/13/2024 |
8.1.5-preview-09 | 92 | 3/12/2024 |
8.1.5-preview-08 | 88 | 3/12/2024 |
8.1.5-preview-07 | 95 | 3/8/2024 |
8.1.5-preview-06 | 70 | 3/8/2024 |
8.1.5-preview-05 | 85 | 3/7/2024 |
8.1.5-preview-04 | 94 | 3/7/2024 |
8.1.5-preview-03 | 88 | 3/7/2024 |
8.1.5-preview-02 | 102 | 2/28/2024 |
8.1.5-preview-01 | 81 | 2/19/2024 |
8.1.4 | 113 | 2/15/2024 |
8.1.3 | 109 | 2/13/2024 |
8.1.3-preview-07 | 81 | 2/13/2024 |
8.1.3-preview-06 | 92 | 2/12/2024 |
8.1.3-preview-05 | 103 | 2/9/2024 |
8.1.3-preview-04 | 95 | 2/8/2024 |
8.1.3-preview-03 | 89 | 2/7/2024 |
8.1.3-preview-02 | 89 | 2/2/2024 |
8.1.3-preview-01 | 85 | 2/2/2024 |
8.1.2 | 117 | 2/1/2024 |
8.1.2-preview-9 | 97 | 1/22/2024 |
8.1.2-preview-8 | 86 | 1/19/2024 |
8.1.2-preview-7 | 88 | 1/19/2024 |
8.1.2-preview-6 | 78 | 1/19/2024 |
8.1.2-preview-5 | 87 | 1/19/2024 |
8.1.2-preview-4 | 85 | 1/19/2024 |
8.1.2-preview-3 | 83 | 1/18/2024 |
8.1.2-preview-2 | 89 | 1/18/2024 |
8.1.2-preview-16 | 81 | 1/31/2024 |
8.1.2-preview-15 | 84 | 1/31/2024 |
8.1.2-preview-14 | 83 | 1/25/2024 |
8.1.2-preview-13 | 84 | 1/25/2024 |
8.1.2-preview-12 | 96 | 1/23/2024 |
8.1.2-preview-11 | 84 | 1/23/2024 |
8.1.2-preview-10 | 83 | 1/22/2024 |
8.1.2-preview-1 | 82 | 1/18/2024 |
8.1.1 | 126 | 1/18/2024 |
8.1.0 | 103 | 1/18/2024 |
8.0.3 | 163 | 12/29/2023 |
8.0.1 | 127 | 12/14/2023 |
8.0.0 | 137 | 12/7/2023 |
6.0.4.3 | 124 | 12/29/2023 |
6.0.4.2 | 117 | 12/20/2023 |
6.0.4.1 | 120 | 12/19/2023 |
6.0.4 | 142 | 12/4/2023 |
6.0.3.20 | 131 | 11/27/2023 |
6.0.3.19 | 144 | 11/22/2023 |