Skip to main content
Table of Contents

Class DbContextMigrationUtility

Namespace
Stratara.EventSourcing.EntityFrameworkCore.Migration
Assembly
Stratara.EventSourcing.EntityFrameworkCore.dll

Helper for applying pending EF Core migrations across a set of DbContext option builders — typically used by host startup to ensure the target databases exist and are up to date before workers start.

public static class DbContextMigrationUtility
Inheritance
DbContextMigrationUtility
Inherited Members

Methods

MigrateAllDatabasesAsync<TDbContext>(IServiceProvider, IEnumerable<DbContextOptionsBuilder<TDbContext>>)

For each DbContextOptionsBuilder<TContext> in optionsBuilders, creates a context, ensures its database exists, and applies any pending migrations.

public static Task MigrateAllDatabasesAsync<TDbContext>(this IServiceProvider serviceProvider, IEnumerable<DbContextOptionsBuilder<TDbContext>> optionsBuilders) where TDbContext : DbContext

Parameters

serviceProvider IServiceProvider

The host service provider used to create a scope.

optionsBuilders IEnumerable<DbContextOptionsBuilder<TDbContext>>

Pre-configured option builders, one per target database.

Returns

Task

A task that completes when every database has been migrated.

Type Parameters

TDbContext

The DbContext type being migrated.

Exceptions

InvalidOperationException

Thrown if TDbContext cannot be instantiated via its DbContextOptions<TContext> constructor.