Eternet.Crud.Relational 3.9.0

Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
dotnet add package Eternet.Crud.Relational --version 3.9.0
                    
NuGet\Install-Package Eternet.Crud.Relational -Version 3.9.0
                    
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="Eternet.Crud.Relational" Version="3.9.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Eternet.Crud.Relational" Version="3.9.0" />
                    
Directory.Packages.props
<PackageReference Include="Eternet.Crud.Relational" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Eternet.Crud.Relational --version 3.9.0
                    
#r "nuget: Eternet.Crud.Relational, 3.9.0"
                    
#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.
#:package Eternet.Crud.Relational@3.9.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Eternet.Crud.Relational&version=3.9.0
                    
Install as a Cake Addin
#tool nuget:?package=Eternet.Crud.Relational&version=3.9.0
                    
Install as a Cake Tool

Eternet.Crud.Relational

Relational CRUD runtime, generated relational bridge conventions, bulk primitives, and relational outbox support for Eternet.Mediator.

Installation

dotnet add package Eternet.Crud.Relational

Current Package Shape

As of April 2026, the supported authoring model is:

  • request-first relational CRUD, where the public contract stays on the contracts/public handler and the internal relational request becomes the semantic source of truth
  • aggregate-root semantics for single-entity create, update, delete, and upsert lanes
  • first-class homogeneous bulk create, bulk delete, and bulk update lanes
  • generated relational bridges that bind deterministic request/runtime inputs and publish reserved downstream outputs
  • explicit IDomainEvent plus relational outbox projection as the default outbox model
  • legacy CreateEntityCommand<Response> / UpdateEntityCommand<Response> / DeleteEntityCommand<Response> and [HandlerForEntity<TEntity>] only as compatibility paths

The modern relational lane is centered on a single explicit relational request type:

public sealed partial class UpdateJournalEntryHandler :
    UpdateJournalEntry,
    IRelationalUpdateImplementation<UpdateJournalEntryRelational.Request>
{
    public override Response Handle(Request request) => request.StepsResults!.Response!;
}

public static partial class UpdateJournalEntryRelational
{
    public sealed partial record Request
        : RelationalUpdateEntityCommand<AccountingContext, JournalEntry, int>
    {
        public override int GetKey() => Id;
    }
}

For update work, the internal relational request above is the supported replacement for authoring new features on UpdateEntityCommand<Response>.

Recent Changes

The last two weeks materially changed both Eternet.Crud.Relational and Eternet.Crud.Relational.Generator:

  • bulk delete, bulk create, and bulk update are now first-class relational lanes instead of bespoke custom-write patterns
  • relational CRUD moved to the request-first API where IRelational*Implementation<TRelationalRequest> declares one explicit internal relational request type
  • create/update/delete/upsert semantics are documented and enforced at the aggregate-root boundary
  • generated bridge steps now return StepResult<T> and preserve compatible custom relational result types for single-entity lanes
  • GeneratedPipelineRuntime is no longer the public runtime anchor for generated bridge glue; generated code now stays behind assembly-local helpers backed by GeneratedBindingRuntime
  • relational outbox authoring now defaults to explicit IDomainEvent emission plus registered projector translation; the old legacy outbox compatibility APIs were removed
  • generated bridge policy is emitted as assembly metadata so test/runtime discovery can reason about handlers across files and referenced assemblies
  • nested relational handlers now get deterministic unique bridge artifact names
  • [RelationalEntityBinding("Alias")] can publish an additional downstream alias for the aggregate entity while keeping the default Entity output
  • scalar binding in generated bridges was tightened so request members bind deterministically by member name and type

Preferred Authoring Model

For new relational features:

  1. Keep the public request/contract in the contracts or public server layer and express API semantics with IEndpointCreate, IEndpointUpdate, IEndpointDelete, IEndpointUpsert, or the relevant query contract.
  2. Keep the public handler on that contract and implement one of the IRelationalCreate/Update/Delete/UpsertImplementation<TRelationalRequest> interfaces.
  3. Declare an app-owned internal relational request that inherits the appropriate relational request base: RelationalCreateEntityCommand<...>, RelationalUpdateEntityCommand<...>, RelationalDeleteEntityCommand<...>, or RelationalUpsertEntityCommand<...>.
  4. Let Eternet.Crud.Relational.Generator augment that request, generate the bridge, and publish the reserved downstream outputs.
  5. Keep domain materialization/mutation and IDomainEvent emission in the app-owned relational business handler or pipeline steps.

The preferred bridge ownership split is:

  • public handler: API contract shape, authorization/binding concerns when needed, and final response assembly from request.StepsResults
  • generated bridge: exact public request property transfer, supported keyed-state compatibility transfer, dispatch to the internal relational request, reserved output publishing, and generated relational pipeline result projection
  • relational request/handler pipeline: write validation, lookups, derived write state, mutation, domain events, and the relational result

For new migrations, prefer a bridge-only public handler when the public side only needs response assembly. Put write-specific derived state on the relational pipeline instead of producing it as public keyed state. Public keyed-state binding remains supported for compatibility and for transport-layer facts that genuinely belong before the bridge. When the internal relational request has generated pipeline steps, the generated bridge copies that request's StepsResults object to request.StepsResults.RelationalStepsResults. Public response assembly can read auxiliary relational-side outputs through that nested property without moving lookup/check steps back to the public pipeline.

When a generated mediator pipeline already owns custom multi-entity behavior, migrate it to EntityChangesCommand<TDbContext, TResponse> instead of forcing a primitive companion. This keeps lookup/check/mutation steps visible on the public pipeline, removes only the explicit SaveChanges step, and lets UnitOfWorkBehavior own the transaction and final save. The generator analyzer marks this deterministic path with CodeFixKind=RelationalEntityChangesPipeline only for preserved-state cases it can prove, such as ticket-action preservation or one shared transaction. It keeps the diagnostic non-codefixable for database-generated key reads, intermediate flushes, get-or-create flows, and bulk item derived-state flows.

For generated pipeline migrations, ECR015 is intentionally single-DbContext. If the analyzer sees pipeline evidence for more than one DbContext, it does not offer the deterministic migration. Transaction boundary steps are identified semantically by following local call trees to EF Core DatabaseFacade.BeginTransaction*, DatabaseFacade.CommitTransaction*, or IDbContextTransaction.Commit* calls. When the boundary belongs to the same DbContext as the recommended relational command, the diagnostic emits TransactionBoundarySteps, TransactionStartSteps, and TransactionCommitSteps so EAC can remove explicit start/commit steps without relying on step names.

For homogeneous set writes, keep the same request-first model and switch the internal relational request to one of the bulk bases:

  • RelationalBulkCreateCommand<...>
  • RelationalBulkDeleteCommand<...>
  • RelationalBulkUpdateCommand<...>

Bulk create consumes the relational request's GetItems() result. If each item needs a lookup-derived value such as a vendor or tenant id, include that value in the typed item input before GetItems() materializes entities, derive it in the relational lane, or choose EntityChangesCommand<TDbContext, TResponse> for a richer workflow.

Compatibility And Roadmap

Legacy relational surfaces still compile, but they are no longer the design target for new code:

  • [HandlerForEntity<TEntity>] remains compatibility-only
  • CreateEntityCommand<Response>, UpdateEntityCommand<Response>, and DeleteEntityCommand<Response> remain compatibility-only
  • ConfigureGeneratedRelationalCommand(...) remains deprecated migration scaffolding
  • legacy *RelationalHooks are already unsupported
  • Eternet.Crud.Relational.Generator discovers the relational key path from deterministic EF metadata and explicit relational contracts instead of naming heuristics (Id, <EntityName>Id, [Key]) or IIntIdentity/IStringIdentity; the remaining cleanup is the runtime/public-surface identity coupling

The relational identity decoupling work is tracked in docs/plans/relational/identity-decoupling-plan.md:

  • remove nondeterministic key and lookup heuristics from the relational lane (done)
  • stop treating IIntIdentity and IStringIdentity as part of the modern relational authoring model
  • decouple the modern relational lane from IIdentity
  • obsolete legacy relational authoring entry points and back that stance with analyzer diagnostics and migration guidance

That future wave is intentionally scoped to Crud.Relational first; it does not require broad immediate cleanup across all of Eternet.Mediator.

Entity Revisions

Eternet.Crud.Relational.Revisions keeps an opaque token per logical scope (for example contract-catalog) that changes in the same transaction as every change-tracker write to the entity types registered for the scope:

modelBuilder.ApplyEntityRevisions("EntityRevisions", "contract-catalog");

services.AddEntityRevisionTracking<BillingDbContext>(options => options.Track<Contract>("contract-catalog"));
services.AddDbContext<BillingDbContext>((provider, options) => options
    .UseSqlServer(connectionString)
    .AddEntityRevisionTracking(provider));

IEntityRevisionReader.GetTokenAsync(scope) returns the current token for ETag-based conditional reads. Bulk operations and raw SQL bypass the interceptor and must call TouchEntityRevisionAsync in the same transaction. See docs/guides/entity-revisions.md.

Transient Failures And Lock Ordering

When UnitOfWorkBehavior owns the transaction, a deadlock (40P01), serialization failure (40001), or other provider-transient failure rolls the transaction back and returns a retryable TransientPersistenceError instead of throwing. Callers detect it with response.TryGetTransientPersistenceError(out var error) and retry the request in a fresh scope. Caller-owned transactions, durable-batch participants, and failures with an unknown commit outcome keep propagating the exception; UnitOfWorkOptions.TransientFailureHandling = Throw restores the previous behavior.

To prevent deadlocks between transactions that write the same rows, declare a canonical lock order and acquire it with dbContext.LockRowAsync<TEntity>(key, RowLockMode.NoKeyUpdate, cancellationToken) (PostgreSQL; a no-op that returns NotSupported on SQLite and other providers). See docs/guides/transient-failures-and-locking.md.

Migration Note: ScopedStates Retirement

Eternet.Crud.Relational 3.0.0 aligned with the ScopedStates retirement in Eternet.Mediator.

  • GeneratedRelationalCommandBinder no longer depends on a public ScopedStates service or constructor argument.
  • Relational bridge binding now resolves values through GeneratedBindingRuntime and the ambient generated runtime scope.
  • Tests or custom infrastructure that previously created ScopedStates manually should migrate to GeneratedBindingRuntime.EnterScope() and GeneratedBindingRuntime.Publish(...) when they need runtime state in-process.

Migration guide: ../../Eternet.Mediator/docs/scoped-states-breaking-change-v3.md

Opt-in held transactions

AddEternetRelationalHeldTransactions() registers IHeldTransactionUnitOfWork<TDbContext> without changing ordinary command behaviors. It supports one owned relational transaction across intermediate tracked insert/update flushes and application work. It requires an empty change tracker, automatic commit, no existing/ambient/enlisted transaction, and no participating unit-of-work participant, outbox or domain-event staging.

Implement IHeldTransactionWork<TDbContext,TRequest,TResponse>. Register each tracked insert/update with the supplied session and await FlushAsync before any external effect that depends on its success. A flush keeps the same transaction and tracked identities. Deletes, unregistered pending writes, concurrent session calls and capabilities retained past their phase are rejected. Application code must not save, complete or replace the owned transaction, and must await its own background work. This API does not sandbox arbitrary use of an injected DbContext.

Return HeldTransactionDecision.Fail(primaryError, optionalPreparation) to preserve a business error. Selected preparation may reload/register the failed state; Prepared requests its final flush and commit, while NoStateToPersist rolls back. Preparation failures remain secondary to the original error. A retry can prepare an existing row even if this attempt has not flushed a new pending row. Preparation must not dispatch external effects or perform its own save/transaction completion.

Return HeldTransactionDecision.Commit(facts, projection) for success. The owner flushes, commits and retires the transaction before projection constructs the response. Projection must not stage changes. The owner discards the attempt's tracked state after rejection or after projection, so a later ordinary save cannot persist rejected changes.

Always consume the HeldTransactionCompletion<TResponse> envelope and its outcome. A commit exception means CommitUnknown; disposal or projection failure after an acknowledged commit preserves Committed. Cleanup failure is explicit and retains the primary error and secondary exceptions. The owner never retries external work or rolls back after starting commit. Contexts with uncertain ownership or failed cleanup cannot start another held attempt. Application reconciliation must precede any reissue. This API supplies no HTTP/client metadata protocol, consumer migration, package publication or deployment.

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on Eternet.Crud.Relational:

Package Downloads
Eternet.Legacy.EF.Tests

Eternet legacy EF tests customization

Eternet.Legacy.EF

Eternet legacy EF models

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
3.10.0 48 11/24/2026
3.9.0 80 11/20/2026
3.8.0 376 11/5/2026
3.7.1 276 10/12/2026
3.7.0 422 10/10/2026
3.6.0 1,716 10/7/2026
3.5.20 607 9/14/2026
3.5.19 128 9/11/2026
3.5.18 163 9/7/2026
3.5.17 197 9/1/2026
3.5.16 130 8/31/2026
3.5.15 251 8/29/2026
3.5.14 132 8/19/2026
3.5.13 318 8/14/2026
3.5.12 533 8/13/2026
3.5.11 144 8/12/2026
3.5.10 172 8/12/2026
3.5.9 262 8/11/2026
3.5.8 137 8/11/2026
3.5.7 138 8/9/2026
Loading failed

UnitOfWorkBehavior returns a retryable TransientPersistenceError (instead of throwing) for deadlocks, serialization failures, and other provider-transient failures in transactions it owns; UnitOfWorkOptions.TransientFailureHandling = Throw keeps the previous behavior. Adds DbContext.LockRowAsync for explicit, provider-aware row lock ordering (PostgreSQL). Now references Microsoft.EntityFrameworkCore.Relational.