Adding automatic migrations

EF Core migration files encapsulate all the steps needed to reach a database structure that conforms to your code models, but in order to apply those steps to your database, there are a few different paths that you can take:

  • Generate an SQL script and execute it in your database
  • Run the external dotnet migrate command from the terminal
  • Add automatic migration capability to your application code.

 All of the mentioned methods are good, but I will concentrate on the third option because it's the most developer-friendly and allows you to move fast as you add new features. 

The DatabaseFacade object, held by the DbContext and exposed by the Database property, contains the Migrate method that runs the migration process ...

Get Hands-On Full-Stack Web Development with ASP.NET Core now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.