Dante Dante - 3 months ago 23
C# Question

How to rename a database column in Entity Framework 5 Code First migrations without losing data?

I got the default ASP.NET MVC 4 template successfully running with EF 5.0 Code First Migrations. However, when I update a model property name, the corresponding table column data is dropped by EF 5.0.

Is it somehow possible to rename the table column without dropping data in an automated way?


Manually edit the Up and Down methods of the migration to use the RenameColumn method to replace the AddColumn and DropColumn that it automatically generates for you.