简体   繁体   English

首先使用现有数据库的实体框架代码

[英]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.

相关问题 在实体框架中使用数据库优先实体和代码优先实体 - Using database first entity with code first entity in entity framework 首先附加现有数据库实体框架代码时出错 - Error attaching existing database entity framework code first 使用Entity Framework Code First开发,我能否在现有数据库中创建一个或多个表? - Using Entity Framework Code First Development, can I get it to create a table or tables in an existing database? 我的数据库不会先使用实体​​框架代码进行播种 - my database won't seed using entity framework code first 实体框架7将现有数据库表转换为ASP.NET MVC中的代码第一类6 - entity framework 7 Convert existing database tables to code first classes in asp.net mvc 6 如何将Entity Framework Code First与现有的MS Access(.accdb)数据库一起使用? - How can I use Entity Framework Code First with an existing MS Access (.accdb) database? 实体框架“代码优先”未创建数据库表 - Entity Framework “Code First” not creating database tables 代码优先实体框架未建立数据库 - Code First Entity Framework not building database 实体框架代码优先使用 Oracle 数据库 - Entity Framework Code First With Oracle Database 使用实体框架插入记录(数据库优先) - Insert record using entity Framework (database first)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM