From the course: Migrating from MVC 5 to ASP.NET Core MVC

Unlock the full course today

Join today to access over 22,400 courses taught by industry experts or purchase this course individually.

Add initial data

Add initial data

From the course: Migrating from MVC 5 to ASP.NET Core MVC

Start my 1-month free trial

Add initial data

- [Instructor] Prior versions of EF had the ability to seed the database with initial data either through the migrations or through a database initializer. This was very useful for application or unit testing. Unfortunately, data initializers from EF 6 are not supported. You must roll your own, and we're going to do that now. We're back in Visual Studio in the MovieDAL project and we're going to add a new directory called Initializers. And into this directory, we're going to add a prebuilt class that's available from the download code. So we'll select Add Existing Item, go into your Assets directory and look for the StoreDataInitializer class. The main method here is InitializeData. What this does is delete the database here on line 22. Then creates a database and runs any migrations. And then I have custom methods to clear the data and seed the data. Clear the data is very simple. It deletes all of the movies and movie genres, and then it resets the identity. So every time the…

Contents