Update Db in EF5 with MVC5

I am working on a project using Entity Framework 5 with MVC5. My project is currently running. I am trying to add a column to a table. But, as we know, in EF, when we add a field to the model, it discards and re-creates the database, which I cannot do. One method for doing this is to search for code migration. But my manager does not allow me to use this (because it is a large database project).

Please help me and suggest something for this.

+4
source share
1 answer

When I start using code first with the Entity Framework, I was in the same situation as you. I always executed Update-Database -F, and then watched, all my tables are deleted and recreated, even for something as simple as renaming a field.

Versioned databases are complex, but much easier with named migrations (which, I think, is what you mean when referring to code migration). I know that your boss is against the idea, but he is very flexible.

Essentially, you run Add-Migration -Name xxxin the package management console, and the Entity Framework will raise a configuration class for you with default commands (both for versions Up()and Down()) that will be executed when Update-Database. If you do not like the commands, you can change them. You can even move data if you need (this is a bit unrealistic).

, :

  • . , , , . , .
  • . Configurations, .
  • , . First . , , , EF. DBA, , .
  • . , SQL-, , , ?

, .

+1

Source: https://habr.com/ru/post/1545816/


All Articles