如何在 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 优先方法中进行迁移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
quot;Overflowquot; compiler error with -9223372036854775808L(编译器错误-9223372036854775808L(Q;溢出Q))
Visual Studio 2010 ReportViewer Assembly References(Visual Studio 2010 ReportViewer程序集引用)
Weird behaviour when I open a reportviewer in WPF(在WPF中打开报表查看器时出现奇怪的行为)
how do i pass parameters to aspnet reportviewer(如何将参数传递给aspnet report查看器)