Class HistoryRepository
- Namespace
- Microsoft.EntityFrameworkCore.Migrations
- Assembly
- Microsoft.EntityFrameworkCore.Relational.dll
A base class for the repository used to access the '__EFMigrationsHistory' table that tracks metadata about EF Core Migrations such as which migrations have been applied.
Database providers must inherit from this class to implement provider-specific functionality.
The service lifetime is Scoped. This means that each Microsoft.EntityFrameworkCore.DbContext instance will use its own instance of this service. The implementation may depend on other services registered with any lifetime. The implementation does not need to be thread-safe.
public abstract class HistoryRepository : IHistoryRepository
- Inheritance
-
HistoryRepository
- Implements
- Inherited Members
Constructors
HistoryRepository(HistoryRepositoryDependencies)
Initializes a new instance of this class.
protected HistoryRepository(HistoryRepositoryDependencies dependencies)
Parameters
dependencies
HistoryRepositoryDependenciesParameter object containing dependencies for this service.
Fields
DefaultTableName
The default name for the Migrations history table.
public const string DefaultTableName = "__EFMigrationsHistory"
Field Value
Properties
Dependencies
Parameter object containing service dependencies.
protected virtual HistoryRepositoryDependencies Dependencies { get; }
Property Value
ExistsSql
Overridden by database providers to generate SQL that tests for existence of the history table.
protected abstract string ExistsSql { get; }
Property Value
GetAppliedMigrationsSql
Generates SQL to query for the migrations that have been applied.
protected virtual string GetAppliedMigrationsSql { get; }
Property Value
MigrationIdColumnName
The name of the column that holds the Migration identifier.
protected virtual string MigrationIdColumnName { get; }
Property Value
ProductVersionColumnName
The name of the column that contains the Entity Framework product version.
protected virtual string ProductVersionColumnName { get; }
Property Value
SqlGenerationHelper
A helper class for generation of SQL.
protected virtual ISqlGenerationHelper SqlGenerationHelper { get; }
Property Value
TableName
THe history table name.
protected virtual string TableName { get; }
Property Value
TableSchema
The schema that contains the history table, or null if the default schema should be used.
protected virtual string TableSchema { get; }
Property Value
Methods
ConfigureTable(EntityTypeBuilder<HistoryRow>)
Configures the entity type mapped to the history table.
Database providers can override this to add or replace configuration.
protected virtual void ConfigureTable(EntityTypeBuilder<HistoryRow> history)
Parameters
history
EntityTypeBuilder<HistoryRow>A builder for the HistoryRow entity type.
Exists()
Checks whether or not the history table exists.
public virtual bool Exists()
Returns
ExistsAsync(CancellationToken)
Checks whether or not the history table exists.
public virtual Task<bool> ExistsAsync(CancellationToken cancellationToken = default)
Parameters
cancellationToken
CancellationTokenA CancellationToken to observe while waiting for the task to complete.
Returns
- Task<bool>
A task that represents the asynchronous operation. The task result contains true if the table already exists, false otherwise.
GetAppliedMigrations()
Queries the history table for all migrations that have been applied.
public virtual IReadOnlyList<HistoryRow> GetAppliedMigrations()
Returns
- IReadOnlyList<HistoryRow>
The list of applied migrations, as HistoryRow entities.
GetAppliedMigrationsAsync(CancellationToken)
Queries the history table for all migrations that have been applied.
public virtual Task<IReadOnlyList<HistoryRow>> GetAppliedMigrationsAsync(CancellationToken cancellationToken = default)
Parameters
cancellationToken
CancellationTokenA CancellationToken to observe while waiting for the task to complete.
Returns
- Task<IReadOnlyList<HistoryRow>>
A task that represents the asynchronous operation. The task result contains the list of applied migrations, as HistoryRow entities.
GetBeginIfExistsScript(string)
Overridden by database providers to generate a SQL Script that will BEGIN
a block
of SQL if and only if the migration with the given identifier already exists in the history table.
public abstract string GetBeginIfExistsScript(string migrationId)
Parameters
migrationId
stringThe migration identifier.
Returns
- string
The generated SQL.
GetBeginIfNotExistsScript(string)
Overridden by database providers to generate a SQL Script that will BEGIN
a block
of SQL if and only if the migration with the given identifier does not already exist in the history table.
public abstract string GetBeginIfNotExistsScript(string migrationId)
Parameters
migrationId
stringThe migration identifier.
Returns
- string
The generated SQL.
GetCreateIfNotExistsScript()
Overridden by a database provider to generate a SQL script that will create the history table if and only if it does not already exist.
public abstract string GetCreateIfNotExistsScript()
Returns
- string
The SQL script.
GetCreateScript()
Generates a SQL script that will create the history table.
public virtual string GetCreateScript()
Returns
- string
The SQL script.
GetDeleteScript(string)
Generates a SQL script to delete a row from the history table.
public virtual string GetDeleteScript(string migrationId)
Parameters
migrationId
stringThe migration identifier of the row to delete.
Returns
- string
The generated SQL.
GetEndIfScript()
Overridden by database providers to generate a SQL script to END
the SQL block.
public abstract string GetEndIfScript()
Returns
- string
The generated SQL.
GetInsertScript(HistoryRow)
Generates a SQL script to insert a row into the history table.
public virtual string GetInsertScript(HistoryRow row)
Parameters
row
HistoryRowThe row to insert, represented as a HistoryRow entity.
Returns
- string
The generated SQL.
InterpretExistsResult(object)
Interprets the result of executing ExistsSql.
protected abstract bool InterpretExistsResult(object value)
Parameters
value
object