Entity Framework Several initializer

https://www.cnblogs.com/godbell/p/7384940.html

 

Database.SetInitializer<TContext>(new NullDatabaseInitializer<TContext>());
Database.SetInitializer<TContext>(null);

 

NullDatabaseInitializer <TContext> initializer this disables the given context type database initialization, equivalents, and transmission null, so that the above two identical wording.

Database.SetInitializer<TContext>(new MigrateDatabaseToLatestVersion<TContext, TMigrationsConfiguration>());

 

MigrateDatabaseToLatestVersion initialize a new instance of the class to specify whether to perform the migration using the connection information in the context initialization trigger. Also it allows you to specify to be used during initialization of the migration configuration.

Database.SetInitializer<TContext>(new DropCreateDatabaseAlways<TContext>());

 

IDatabaseInitializer realization, it will always be the first use in the context of the application domain, re-create the database and the database can choose to re-set seed. To set the seed database, create a derived class and override the Seed method.

Database.SetInitializer<TContext>(new DropCreateDatabaseIfModelChanges<TContext>());

 

IDatabaseInitializer implementation, it only delete the database when you change the model occurred since the database is created, re-create the database and select Reset database seed.

Database.SetInitializer<TContext>(new NullDatabaseInitializer<TContext>());
Database.SetInitializer<TContext>(null);

 

NullDatabaseInitializer <TContext> initializer this disables the given context type database initialization, equivalents, and transmission null, so that the above two identical wording.

Database.SetInitializer<TContext>(new MigrateDatabaseToLatestVersion<TContext, TMigrationsConfiguration>());

 

MigrateDatabaseToLatestVersion initialize a new instance of the class to specify whether to perform the migration using the connection information in the context initialization trigger. Also it allows you to specify to be used during initialization of the migration configuration.

Database.SetInitializer<TContext>(new DropCreateDatabaseAlways<TContext>());

 

IDatabaseInitializer realization, it will always be the first use in the context of the application domain, re-create the database and the database can choose to re-set seed. To set the seed database, create a derived class and override the Seed method.

Database.SetInitializer<TContext>(new DropCreateDatabaseIfModelChanges<TContext>());

 

IDatabaseInitializer implementation, it only delete the database when you change the model occurred since the database is created, re-create the database and select Reset database seed.

Guess you like

Origin www.cnblogs.com/wfy680/p/12370620.html