Now that we have an empty database, let's fill it with some test data. To do this, we'll need to create a method that we will call after our database creation:
- Create a folder in your project called Data. In the folder, add a class called DbInitializer.cs:
The class has an Initialize method that takes our ResearchContext as a parameter:
public static void Initialize(ResearchContext context)
- In the Initialize method, we first call the Database.EnsureCreated method to make sure the database exists and creates it if not:
context.Database.EnsureCreated();
- Next up, we do a quick Linq query to check if ...