
DropCreateDatabaseIfModelChanges students. The class needs to inherit from DropCreateDatabaseIfModelChanges. To do this, you need to create an initializer class in the same folder as your DbContext class. You can configure Entity Framework to delete (drop) and recreate your database every time there is a change to your schema. Drop and Recreate Your Databaseĭuring the development process, the domain models will be changing often. Entity Framework Core doesn’t include database initializer classes.


Note: In this post I cover how to use database initializers with Entity Framework 6.x in an ASP.NET project. However, during development Entity Framework can be configured to drop and recreate the database every time there’s a schema change. By default, Entity Framework will create a database only if one does not already exist using the CreateDatabaseIfNotExists class. These database initializers are intended to be used in different stages of the development process. But how do you control when and how the database will be created, and how the structure is updated?Įntity Framework 6.x includes a range of database initializers that specify how and when EF should generate a new database.

Using Code First with Entity Framework, EF will create a database for you based on your domain models.
