Table of Contents

Class EfUnitOfWork<TContext>

Namespace
Trellis.EntityFrameworkCore
Assembly
Trellis.EntityFrameworkCore.dll

EF Core implementation of IUnitOfWork. Delegates to SaveChangesResultUnitAsync(DbContext, CancellationToken) which already maps DbUpdateConcurrencyException to Error.Conflict, duplicate-key exceptions to Error.Conflict, and foreign-key violations to Error.Conflict.

public class EfUnitOfWork<TContext> : IUnitOfWork where TContext : DbContext

Type Parameters

TContext

The concrete DbContext type registered in DI.

Inheritance
EfUnitOfWork<TContext>
Implements
Inherited Members
Extension Methods

Constructors

EfUnitOfWork(TContext)

EF Core implementation of IUnitOfWork. Delegates to SaveChangesResultUnitAsync(DbContext, CancellationToken) which already maps DbUpdateConcurrencyException to Error.Conflict, duplicate-key exceptions to Error.Conflict, and foreign-key violations to Error.Conflict.

public EfUnitOfWork(TContext context)

Parameters

context TContext

Methods

CommitAsync(CancellationToken)

Persists all staged changes to the database. Returns Result<TValue> with Unit to surface concurrency, duplicate-key, and foreign-key errors as Error instead of exceptions.

public Task<Result<Unit>> CommitAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

A token to observe while waiting for the task to complete.

Returns

Task<Result<Unit>>

A Result<TValue> with Unit representing success or failure.