concept Migrate method in category entity framework

This is an excerpt from Manning's book Entity Framework Core in Action.
If you want to run your seed database method only when a new migration has been applied, you can use the DbContext method
Database.GetPendingMigrationsto get the list of migrations that are about to be applied. You must callGetPendingMigrationsbefore you execute theDatabase.Migratemethod, because the pending migration is empty after theMigratemethod has finished.
Section 5.9.2 showed how to apply a migration on the startup of an ASP.NET Core application. You can apply a similar approach with other application types. The following listing shows an example for a console application, which executes the
Migratemethod every time it starts. If the database is up-to-date, theMigratemethod does nothing.Listing 11.4 Running the
Migratecommand during startup of a console applicationclass Program { static void Main(string[] args) { using (var context = new EfCoreContext()) #1 { context.Database.Migrate(); #2 } //... then start the rest of my code } } #1 Setup of the appliction’s DbContext is done by overriding the OnConfiguring method, so you don’t need to provide any connection string of the database provider here. #2 Calling the Migrate method applies any outstanding migrations to the database it’s attached to. If no outstanding migrations exist, it does nothing.The advantage of using the
Database.Migratemethod is simplicity. This method ensures that any database that it connects to is migrated to the correct level before using it. This is the only approach that makes all migrations, breaking and nonbreaking changes (see section 11.5), in one stage. This works across all your databases, including the production database (with some caveats). But there are a few disadvantages: