简体   繁体   English

如何在数据库优先方法中进行迁移

[英]How to do Migrations in DB first approach

I am using entity framework DB first approach and wants to know how can i manage migrations in DB first approach. 我正在使用实体框架数据库优先方法,并且想知道如何在数据库优先方法中管理迁移。 We're doing changes in database schema manually. 我们正在手动更改数据库架构。 Is there any way by which Entity Framework can apply the changes accordingly to the project. 实体框架是否可以通过任何方式将更改相应地应用于项目。

I guess I got confused between the code first with existing database and database first with model. 我想我先将代码与existing database and database first与模型之间混淆了。 What I understood is, after searching in different forums, Migrations are allowed only in code first approach. 我的理解是,在不同的论坛中搜索后,仅允许使用代码优先方法进行迁移。 Code first assumes that you will never make any changes manually to the database. 代码首先假定您永远不会手动对数据库进行任何更改。 All the changes to the database will go through the code first migrations. 对数据库的所有更改将首先进行代码迁移。 This is true for code first with an existing database as well. 对于现有数据库中的代码优先也是这样。 If you are working with code first with existing database then it assumes that after connecting the the database for first time all the changes to the database will go through the code first migration instead of manually. 如果您首先在现有数据库上使用代码,则假定在首次连接数据库后,对数据库的所有更改将首先通过代码迁移,而不是手动进行。 When you are using Model instead of code first approach then any manual changes to the database can be migrated to the model by Update model from DataBase option. 当使用“模型”而不是“代码优先”方法时,可以通过Update model from DataBase选项Update model from DataBase将对数据库的任何手动更改迁移到模型。 Which can be accessed by right clicking on the model. 可以通过右键单击模型来访问。

I hope my understanding is correct but any modifications or corrections are welcome. 希望我的理解是正确的,但欢迎进行任何修改或更正。

  1. You'll have to make the appropriate change manually 您必须手动进行适当的更改
  2. You'll have to delete the model classes and generate them once again 您必须删除模型类并再次生成它们

EDIT: 编辑:

I would recommend you to go through this: http://msdn.microsoft.com/en-us/data/jj206878.aspx 我建议您阅读以下内容: http : //msdn.microsoft.com/zh-cn/data/jj206878.aspx

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 迁移 - 实体框架数据库优先方法 - Migrations - Entity Framework Database First Approach 如何以代码优先方式禁用Db模式不匹配的迁移? - How to disable migration on Db schema mismatch in code-first approach? 如何使用已在Azure中注册的应用程序使用实体框架数据库第一种方法连接到Azure SQL DB - How to connect to Azure SQL DB using entity framework database first approach using already registered app in Azure 如何通过 .NET CORE 2.2 中的代码优先方法使用 linq2db 在 Microsoft SQL Server 中创建数据库 - How to create database in Microsoft SQL Server using linq2db by code first approach in .NET CORE 2.2 如何使用“模型优先”方法在EF4中创建1x0..1关联? - How do I create a 1x0..1 association in EF4 using Model-First approach? 如何在不启用迁移的情况下从数据库删除列? - How to delete column from db without having migrations enabled? 如何使用ViewModel-First方法? - How to use the ViewModel-First approach? 如何首先使用EF代码重置数据库迁移? - How to reset database migrations using EF code first? 代码优先迁移 - 如何显示待定模型更改? - Code first migrations - how to display pending model changes? 使用代码优先迁移创建数据库:db.Initialize(…)和db.Create()之间的操作顺序是什么? - Create a database using code-first migrations: What is the order of operations between db.Initialize(…) and db.Create()?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM