Tutorial by Examples

Implementation of IDatabaseInitializer that is used in EntityFramework by default. As the name implies, it creates the database if none exists. However when you change the model, it throws an exception. Usage: public class MyContext : DbContext { public MyContext() { Database.SetIni...
This implementation of IDatabaseInitializer drops and recreates the database if the model changes automatically. Usage: public class MyContext : DbContext { public MyContext() { Database.SetInitializer(new DropCreateDatabaseIfModelChanges<MyContext>()); } }
This implementation of IDatabaseInitializer drops and recreates the database everytime your context is used in applications app domain. Beware of the data loss due to the fact, that the database is recreated. Usage: public class MyContext : DbContext { public MyContext() { Database.S...
You can create your own implementation of IDatabaseInitializer. Example implementation of an initializer, that will migrate the database to 0 and then migrate all the way to the newest migration (usefull e.g. when running integration tests). In order to do that you would need a DbMigrationsConfigur...
An implementation of IDatabaseInitializer that will use Code First Migrations to update the database to the latest version. To use this initializer you have to use DbMigrationsConfiguration type too. Usage: public class MyContext : DbContext { public MyContext() { Database.SetInitial...

Page 1 of 1