Populating the database
Now that we have a SQL database available and a DbContext
that we can use to read from and write to it, we are finally ready to populate those tables with our world cities data.
To do that, we need to implement a data seeding strategy. We can do this using one of the various Entity Framework Core-supported approaches:
- Model data seed
- Manual migration customization
- Custom initialization logic
These three methods are well explained in the following article, along with their very own sets of pros and cons: https://docs.microsoft.com/en-us/ef/core/modeling/data-seeding.
Since we have to handle a relatively big Excel file, we’re going to adopt the most customizable pattern we can make use of: some custom initialization logic relying upon a dedicated .NET controller that we can execute—manually or even automatically—whenever we need to seed our database.
Implement SeedController
Our custom initialization...