Skip to main content
Table of Contents

Class ReadDbContext<TContext>

Namespace
Stratara.EventSourcing.EntityFrameworkCore.ReadStore
Assembly
Stratara.EventSourcing.EntityFrameworkCore.dll

Base read-store DbContext that consumer DbContexts derive from. Hosts the projection / read-model tables that the projection workers write into and queries read from.

public class ReadDbContext<TContext> : DbContext, IInfrastructure<IServiceProvider>, IDbContextDependencies, IDbSetCache, IDbContextPoolable, IResettableService, IDisposable, IAsyncDisposable, IReadDbContext, IDbContext where TContext : DbContext

Type Parameters

TContext

The concrete derived DbContext type (used for DbContextOptions<TContext> binding).

Inheritance
ReadDbContext<TContext>
Implements
Inherited Members
Extension Methods

Remarks

Filters ApplyConfigurationsFromAssembly by the Stratara.EventSourcing.EntityFrameworkCore.ReadStore namespace so the write-store and identity-store IEntityTypeConfiguration<> implementations co-hosted in the same assembly do not leak into the read 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

ReadDbContext(DbContextOptions<TContext>)

Base read-store DbContext that consumer DbContexts derive from. Hosts the projection / read-model tables that the projection workers write into and queries read from.

public ReadDbContext(DbContextOptions<TContext> options)

Parameters

options DbContextOptions<TContext>

Options bound by the host's AddNpgsqlReadDbContextFactory registration.

Remarks

Filters ApplyConfigurationsFromAssembly by the Stratara.EventSourcing.EntityFrameworkCore.ReadStore namespace so the write-store and identity-store IEntityTypeConfiguration<> implementations co-hosted in the same assembly do not leak into the read 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

modelBuilder ModelBuilder

The 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.