Namespace Trellis.EntityFrameworkCore
Classes
- DbContextExtensions
Extension methods on DbContext that wrap SaveChangesAsync(CancellationToken) and convert expected database exceptions to Result<TValue> failures.
- DbContextOptionsBuilderExtensions
Extension methods for DbContextOptionsBuilder that register Trellis EF Core interceptors.
- DbExceptionClassifier
Classifies database exceptions across providers (SQL Server, PostgreSQL, SQLite). Used internally by both SaveChangesResultAsync(DbContext, CancellationToken) and SaveChangesResultAsync(DbContext, bool, CancellationToken) overloads. Also available for direct use in repositories that need custom error messages per exception type.
- 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.
- EntityTimestampInterceptor
EF Core SaveChanges interceptor that automatically sets CreatedAt and LastModified on entities before save.
- MaybeEntityTypeBuilderExtensions
Entity type builder helpers that resolve Maybe<T> properties to their mapped storage members.
- MaybeModelExtensions
Diagnostics helpers for inspecting resolved EF Core mappings for Maybe<T> properties.
- MaybePropertyMapping
Describes how a Maybe<T> property resolved to an EF Core mapped backing field.
- MaybeQueryInterceptor
An EF Core query expression interceptor that automatically rewrites Maybe<T> property accesses in LINQ expression trees to their underlying storage member equivalents.
- MaybeQueryableExtensions
LINQ query extensions for Maybe<T> properties backed by generated nullable storage members. These methods rewrite the expression tree to target the underlying
_camelCasestorage member via Property<TProperty>(object, string), enabling EF Core to translate the query to SQL.
- MaybeUpdateExtensions
ExecuteUpdate helpers for setting and clearing mapped Maybe<T> properties via CLR selectors.
- ModelConfigurationBuilderExtensions
Extension methods for ModelConfigurationBuilder that register Trellis value object conventions before EF Core model building.
- OwnedEntityAttribute
Marks a composite ValueObject as an EF Core owned entity type, triggering source generation of the private parameterless constructor required for EF Core materialization.
- QueryableExtensions
Extension methods on IQueryable<T> that wrap EF Core query results in Maybe<T> or Result<TValue>.
- RepositoryBase<TAggregate, TId>
Base class for EF Core repositories that persist Aggregate<TId> instances. Provides standard read and staging methods. Repositories stage changes to the DbContext change tracker; the IUnitOfWork (typically driven by a pipeline behavior) is responsible for committing staged changes.
- ScalarValueQueryInterceptor
An EF Core query expression interceptor that enables natural scalar value object syntax in LINQ queries — comparisons, string methods, and properties translate to SQL without requiring
.Value.
- TransactionalCommandBehavior<TMessage, TResponse>
Pipeline behavior that automatically commits staged changes after a successful command handler.
The behavior calls
nextto run the handler (which stages changes via repositories), then calls CommitAsync(CancellationToken) if the handler returned success. If the handler returned a failure Result<TValue>, no commit occurs and the staged changes are discarded when the DbContext is disposed.This behavior is constrained to Mediator.ICommand<TResponse> messages — queries are not wrapped and incur no overhead.
Atomicity: EF Core wraps each
SaveChangescall in an implicit database transaction, so all staged changes within a single handler are committed atomically. Cross-aggregate operations that share the same DbContext are automatically transactional.
- TrellisPersistenceMappingException
Represents a failure to materialize a Trellis value object from persisted data.
- TrellisScalarConverter<TModel, TProvider>
Value converter for Trellis IScalarValue<TSelf, TPrimitive> types.
Converts to database using the
Valueproperty and from database using the type's validation factory methods. Invalid persisted values throw TrellisPersistenceMappingException with explicit materialization details.
- UnitOfWorkServiceCollectionExtensions
Extension methods for registering IUnitOfWork and the TransactionalCommandBehavior<TMessage, TResponse> pipeline behavior.
Interfaces
- IUnitOfWork
Abstraction over the commit boundary for staged changes. Repositories stage changes; calling CommitAsync(CancellationToken) persists them.
In the standard Trellis pipeline, commit is handled automatically by TransactionalCommandBehavior<TMessage, TResponse> after a successful handler. Inject IUnitOfWork directly only in non-pipeline scenarios (background jobs, integration tests, etc.).