Class Migration
- Namespace
- Microsoft.EntityFrameworkCore.Migrations
- Assembly
- Microsoft.EntityFrameworkCore.Relational.dll
A base class inherited by each EF Core migration.
public abstract class Migration
- Inheritance
-
Migration
- Inherited Members
- Extension Methods
Constructors
Migration()
protected Migration()
Fields
InitialDatabase
The migration identifier for the empty database.
public const string InitialDatabase = "0"
Field Value
Properties
ActiveProvider
The name of the current database provider.
This can be used to write conditional code in the migration such that different changes can be made to the database depending on the type of database being used.
public virtual string ActiveProvider { get; set; }
Property Value
DownOperations
The MigrationOperations that will migrate the database 'down'.
That is, those operations that need to be applied to the database to take it from the state left in by this migration so that it returns to the state that it was in before this migration was applied.
public virtual IReadOnlyList<MigrationOperation> DownOperations { get; }
Property Value
TargetModel
The Microsoft.EntityFrameworkCore.Metadata.IModel that the database will map to after the migration has been applied.
public virtual IModel TargetModel { get; }
Property Value
- IModel
UpOperations
The MigrationOperations that will migrate the database 'up'.
That is, those operations that need to be applied to the database to take it from the state left in by the previous migration so that it is up-to-date with regard to this migration.
public virtual IReadOnlyList<MigrationOperation> UpOperations { get; }
Property Value
Methods
BuildTargetModel(ModelBuilder)
Implemented to build the TargetModel.
protected virtual void BuildTargetModel(ModelBuilder modelBuilder)
Parameters
modelBuilder
ModelBuilderThe Microsoft.EntityFrameworkCore.ModelBuilder to use to build the model.
Down(MigrationBuilder)
Builds the operations that will migrate the database 'down'.
That is, builds the operations that will take the database from the state left in by this migration so that it returns to the state that it was in before this migration was applied.
This method must be overridden in each class the inherits from Migration if both 'up' and 'down' migrations are to be supported. If it is not overridden, then calling it will throw and it will not be possible to migrate in the 'down' direction.
protected virtual void Down(MigrationBuilder migrationBuilder)
Parameters
migrationBuilder
MigrationBuilderThe MigrationBuilder that will build the operations.
Up(MigrationBuilder)
Builds the operations that will migrate the database 'up'.
That is, builds the operations that will take the database from the state left in by the previous migration so that it is up-to-date with regard to this migration.
This method must be overridden in each class the inherits from Migration.
protected abstract void Up(MigrationBuilder migrationBuilder)
Parameters
migrationBuilder
MigrationBuilderThe MigrationBuilder that will build the operations.