Naravel.Database.EntityFrameworkCore
0.2.0
dotnet add package Naravel.Database.EntityFrameworkCore --version 0.2.0
NuGet\Install-Package Naravel.Database.EntityFrameworkCore -Version 0.2.0
<PackageReference Include="Naravel.Database.EntityFrameworkCore" Version="0.2.0" />
<PackageVersion Include="Naravel.Database.EntityFrameworkCore" Version="0.2.0" />
<PackageReference Include="Naravel.Database.EntityFrameworkCore" />
paket add Naravel.Database.EntityFrameworkCore --version 0.2.0
#r "nuget: Naravel.Database.EntityFrameworkCore, 0.2.0"
#:package Naravel.Database.EntityFrameworkCore@0.2.0
#addin nuget:?package=Naravel.Database.EntityFrameworkCore&version=0.2.0
#tool nuget:?package=Naravel.Database.EntityFrameworkCore&version=0.2.0
Naravel.Database.EntityFrameworkCore
EF Core interop for Naravel.Database: a DbContext and the query builder share one connection and one transaction.
| Fact | Detail |
|---|---|
| Install | dotnet add package Naravel.Database.EntityFrameworkCore |
| Targets | .NET 10 |
| Needs | Naravel.Database and Microsoft.EntityFrameworkCore.Relational, which NuGet installs with it, and the EF Core provider that your own DbContext uses |
| Providers | SQLite, SQL Server, PostgreSQL (Npgsql) and MySQL |
What you get
- A builder query on the context.
dbContext.Query("table")starts a query on the context's own connection and its current transaction. - One unit of work. An EF
SaveChangesAsyncand a builder write commit or roll back together, in the transaction you begin on the context. - Atomic statements beside tracked entities. Entities and change tracking stay in EF Core, while a guarded
DecrementAsyncor a bulk statement runs in the builder. - Listeners and the query log still see it.
naravelDatabase.Using(dbContext)returns anIDatabaseon the context's connection and transaction.
Quick start
using Microsoft.EntityFrameworkCore;
using Naravel.Database.EntityFrameworkCore; // adds dbContext.Query("table") and database.Using(dbContext)
// db is your own DbContext, "Accounts" is the table that EF maps for your Accounts DbSet, and fromId, toId and amount are yours
await using var transaction = await db.Database.BeginTransactionAsync(ct); // EF Core owns the transaction: begin it before the first builder call
var debited = await db.Query("Accounts")
.Where("Id", fromId)
.Where("Balance", ">=", amount)
.DecrementAsync("Balance", amount, cancellationToken: ct); // one guarded, atomic UPDATE on the context's connection
if (debited == 0)
throw new InvalidOperationException("Unknown account or insufficient funds."); // no commit: disposing the transaction rolls back
await db.Query("Accounts").Where("Id", toId).IncrementAsync("Balance", amount, cancellationToken: ct);
await db.SaveChangesAsync(ct); // EF Core changes are saved in the same transaction
await transaction.CommitAsync(ct);
For dbContext.Query(...) only EF Core needs registering. The query builder only joins the transaction that is current when each command runs, so begin and finish it on the context; it never commits or rolls back one it did not start. The builder bypasses EF change tracking: an entity you already loaded does not see a builder update until you reload it or read it with AsNoTracking(). Use the table and column names that EF maps. For naravelDatabase.Using(dbContext), register AddNaravelDatabase as usual.
Related packages
| Package | Adds |
|---|---|
Naravel.Database |
The query builder, named connections and raw SQL |
Learn more
- Database: English guide
- Changelog · Source and issues · MIT license
Part of Naravel: Laravel's names, .NET's type system. All Naravel packages share one version.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Microsoft.EntityFrameworkCore.Relational (>= 10.0.14)
- Naravel.Database (>= 0.2.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Release notes: https://github.com/km-arc/Naravel/releases/tag/v0.2.0 - full history: https://github.com/km-arc/Naravel/blob/main/CHANGELOG.md