本文介绍了如何在不丢失数据的情况下在Entity Framework 5 Code First迁移中重命名数据库列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我成功使用EF 5.0 Code First Migrations成功运行了默认的ASP.NET MVC 4模板。但是,当我更新模型属性名称时,EF 5.0会删除相应的表列数据。
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?
推荐答案
手动编辑迁移的上下方法以使用 RenameColumn
方法替换自动为您生成的 AddColumn
和 DropColumn
。
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.
这篇关于如何在不丢失数据的情况下在Entity Framework 5 Code First迁移中重命名数据库列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!