[英]entity framework code first using existing database
I have started learning Entity framework and have a problem. 我已经开始学习实体框架,并且遇到了问题。 I have created a code first mvc project and I don't want to drop the database when the model changes.
我已经创建了第一个代码mvc项目,并且我不想在模型更改时删除数据库。 What can I do other than DropCreateDatabaseIfModelChanges in my initializer class so that the database and the tables stays along with the data?
除了初始化程序类中的DropCreateDatabaseIfModelChanges之外 ,我还能做什么,以便数据库和表与数据保持在一起?
You don't need to use an initializer at all. 您根本不需要使用初始化程序。 This is valid:
这是有效的:
Database.SetInitializer<YourContext>(null);
And in your configuration file set
AutomaticMigrationsEnabled = false;
并在您的配置文件中设置
AutomaticMigrationsEnabled = false;
Then you can do the migrations yourself. 然后,您可以自己进行迁移。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.