Entity Framework migration options navigation

I am trying to find the best way to migrate my database in my production environment, and I think I'm losing some of the terminology.

I have a class called "Migration" that I use to load my database. The constructor looks like this (my DbContext is called SiteDatabase):

internal sealed class Migration : DbMigrationsConfiguration<SiteDatabase>
{
    public Migration()
    {
        AutomaticMigrationsEnabled = true;
        AutomaticMigrationDataLossAllowed = true;
    }
}
  • What does AutomaticMigrationsEnabled do here? Is this how I turned on automatic migrations?

In my Application_Start () method, I saw the following elements added:

protected void Application_Start()
{
    new DbMigrator(new Migration()).Update();

    // Option 1
    Database.SetInitializer(new MigrateDatabaseToLatestVersion<SiteDatabase, Migration>());

    // Option 2
    Database.SetInitializer(new DropCreateDatabaseAlways<SiteDatabase>());
}
  1. Are only these options available?
  2. How does this relate to AutomaticMigrationsEnabled, what's in the migration class?

In the package manager console, I know about the following commands:

> update-database
> add-migration
  1. AutomaticMigrationsEnabled? ? DbMigrator?
  2. add-migration, ? , , .
  3. , , add-migration, ?
+4
1

AutomaticMigrationsEnabled ? ?

: . , add-migration update-database: . "".

?

, , CreateDatabaseIfNotExists, DropCreateDatabaseWhenModelChanges, DropCreateDatabaseAlways , .

AutomaticMigrationsEnabled, ?

, , . , . , , .

AutomaticMigrationsEnabled? ? DbMigrator?

. : add-migration.

add-migration, ?

, . , "add usermodel address", . , , .

, , add-migration, ?

.

+2

All Articles