How to apply database changes to ASP.NET Core MVC DBContext using migrations?

Viewed 279

In my ASP.NET Core MVC application, I generate a model from my existing database in Entity Framework Core using Scaffold-DbContext command:

PM> Scaffold-DbContext "Server=.;Database=myDatabase;user id=sa;password=myPassword" 
                       Microsoft.EntityFrameworkCore.SqlServer 
                       -outputDir Model -Context myContext

Then I create a migration to keep using the following command:

add-migration migrationName

If I made a change in my database (ex: add a new field, change type of field .. etc), How can I apply this changes to my model?

I DO NOT want to rescaffold because I will lose any work done on my models, such as data validations.

0 Answers
Related