C# – Using Migrations – ASP.NET MVC with EF Core – Video

Migrations in C# are quite well facilitated by the EntityFramework. In general, when an application with databse is created, initially the database model is taken from the model classes. When these models classes change, then they get out of sync with the database. Thus, each time the model is changed, the database should be “informed” as well, so it can adapt to the change. These “informing-s” of the model towards the database are called “migration”. In Visual Studio, to work with migrations, one may use the Package Manager Console (PMC) and write the migrations there.

These are some commands, which could be used in the C# PMC for migrations:

When the first “Add-Migration” command is executed, VisualStudio EF creates a folder Migrations, in which information about the migrations are kept. When the database is updated, a corresponding table for the migrations is created as well. This is the migration code, generated by a single name change of a table in a database:

The rest of the project code is available in GitHub – https://github.com/Vitosh/ASP/tree/master/EFCoreAsp.NetMvcWebApp/ContosoUniversity004

Enjoy it!

Tagged with: , , , , ,