Class WriteDbContext<TContext>
- Assembly
- Stratara.EventSourcing.EntityFrameworkCore.dll
Base write-store DbContext that consumer DbContexts derive from. Hosts the event-sourcing
tables — event_stream_entry, snapshot, command_log_entry, and
outbox_entry — that the command, hashing, and outbox workers persist into.
public class WriteDbContext<TContext> : DbContext, IInfrastructure<IServiceProvider>, IDbContextDependencies, IDbSetCache, IDbContextPoolable, IResettableService, IDisposable, IAsyncDisposable, IWriteDbContext, IDbContext where TContext : DbContext
Type Parameters
TContextThe concrete derived DbContext type (used for DbContextOptions<TContext> binding).
- Inheritance
-
WriteDbContext<TContext>
- Implements
- Derived
- Inherited Members
- Extension Methods
Remarks
Filters ApplyConfigurationsFromAssembly by the Stratara.EventSourcing.EntityFrameworkCore.WriteStore namespace so
the read-store and identity-store IEntityTypeConfiguration<> implementations
co-hosted in the same assembly do not leak into the write model. Missing the namespace
predicate yields PendingModelChangesWarning at runtime — a regression that escapes
unit tests and only surfaces against a real Postgres in the consumer's E2E pipeline.
Constructors
WriteDbContext(DbContextOptions<TContext>)
Base write-store DbContext that consumer DbContexts derive from. Hosts the event-sourcing
tables — event_stream_entry, snapshot, command_log_entry, and
outbox_entry — that the command, hashing, and outbox workers persist into.
public WriteDbContext(DbContextOptions<TContext> options)
Parameters
optionsDbContextOptions<TContext>Options bound by the host's
AddNpgsqlWriteDbContextFactoryregistration.
Remarks
Filters ApplyConfigurationsFromAssembly by the Stratara.EventSourcing.EntityFrameworkCore.WriteStore namespace so
the read-store and identity-store IEntityTypeConfiguration<> implementations
co-hosted in the same assembly do not leak into the write model. Missing the namespace
predicate yields PendingModelChangesWarning at runtime — a regression that escapes
unit tests and only surfaces against a real Postgres in the consumer's E2E pipeline.
Methods
OnModelCreating(ModelBuilder)
Override this method to further configure the model that was discovered by convention from the entity types exposed in DbSet<TEntity> properties on your derived context. The resulting model may be cached and re-used for subsequent instances of your derived context.
protected override void OnModelCreating(ModelBuilder modelBuilder)
Parameters
modelBuilderModelBuilderThe builder being used to construct the model for this context. Databases (and other extensions) typically define extension methods on this object that allow you to configure aspects of the model that are specific to a given database.
Remarks
If a model is explicitly set on the options for this context (via UseModel(IModel)) then this method will not be run. However, it will still run when creating a compiled model.
See Modeling entity types and relationships for more information and examples.