How to avoid data loss with EF Model First database schema upgrade?

二次信任 提交于 2019-12-04 04:54:30

The best way to migrate database schema (create / delete tables / columns) and also data, is using the SSDT - Sql Server Data Tools, available for Visual Studio 2010 and Visual Studio 2012.

Here are some very useful links:

http://msdn.microsoft.com/data/tools http://blogs.msdn.com/b/ssdt http://msdn.microsoft.com/en-us/data/hh297027

Muhammad Mustafa

In the Configuration class set the constructor as below:

public Configuration()  
{  
    AutomaticMigrationsEnabled = true;  
    AutomaticMigrationDataLossAllowed = false;  
}   

Set the AutomaticMigrationEnabled property to true means we are using automatic code first migration and another property AutomaticMigrationDataLossAllowed is set to false, means that during the migration no existing data is lost from that migration of the table of the database.

The entire Configuration class is as follows.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!