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
TContextThe 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
contextTContext
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
cancellationTokenCancellationTokenA token to observe while waiting for the task to complete.
Returns
- Task<Result<Unit>>
A Result<TValue> with Unit representing success or failure.