I recently changed an application from using the following for dev:
DropCreateDatabaseIfModelChanges
To using:
I somewhat agree with Arthur Vickers response, however IMO Seed is for DbMigrations and I don't want the Seed method to be checking everything every time, e.g. If I have 4 migrations then I would need to test somehow which data must be seeded and that will be 4 more database hits at least.
In case you still would like to have the behavior of running Seed method only when migrations are applied, like me, I came with my own implementation of the IDatabaseInitializer strategy
public class CheckAndMigrateDatabaseToLatestVersion
: IDatabaseInitializer
where TContext : DbContext
where TMigrationsConfiguration : DbMigrationsConfiguration, new()
{
public virtual void InitializeDatabase(TContext context)
{
var migratorBase = ((MigratorBase)new DbMigrator(Activator.CreateInstance()));
if (migratorBase.GetPendingMigrations().Any())
migratorBase.Update();
}
}