如何在 DB 优先方法中进行迁移

How to do Migrations in DB first approach(如何在 DB 优先方法中进行迁移)

本文介绍了如何在 DB 优先方法中进行迁移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用实体框架 DB 优先方法,并且想知道如何在 DB 优先方法中管理迁移.我们正在手动更改数据库架构.实体框架是否可以通过任何方式将更改相应地应用于项目.

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.

推荐答案

我想我对 existing database 和 database first 和 model 混淆了.我的理解是,在不同的论坛搜索后,迁移只允许在代码优先的方法中.代码首先假定您永远不会手动对数据库进行任何更改.对数据库的所有更改都将通过代码优先迁移.对于具有现有数据库的代码优先也是如此.如果您首先使用现有数据库使用代码,那么它假定在第一次连接数据库后,对数据库的所有更改都将通过代码首次迁移而不是手动进行.当您使用模型而不是代码优先方法时,对数据库的任何手动更改都可以通过 Update model from DataBase 选项迁移到模型.可以通过右键单击模型来访问.

I guess I got confused between the code first with existing database and database first with model. 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. Which can be accessed by right clicking on the model.

我希望我的理解是正确的,但欢迎任何修改或更正.

I hope my understanding is correct but any modifications or corrections are welcome.

这篇关于如何在 DB 优先方法中进行迁移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:如何在 DB 优先方法中进行迁移

上一篇: C# 和 PostgreSQL

基础教程推荐