实体框架5,首先从代码转换到数据库? [英] Entity Framework 5, switch from code first to database first?

查看:147
本文介绍了实体框架5,首先从代码转换到数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用代码创建了数据库。它工作得很好。此后,对Visual Studio之外的数据库进行了许多更改。这么多,任何迁移的尝试都会产生错误。所以我的问题是,有没有办法从代码首先切换到数据库首先?

I've already created a database using code first. It worked well. Many changes have since been made to the database outside Visual Studio. So many that any attempt at migration generates errors. So my question is, is there a way to switch a solution from code first to database first?

推荐答案

只需创建一个新的,数据库的第一个模型并删除你的代码第一个模型。如果你在同一个命名空间中,你的大多数代码将编译得很好。

This should be easy, just create a new, database first model and delete your code first model. Most of your code will compile just fine if you are in the same namespace and take care of naming your context in the same way.

然而,切换到数据库,使你失去迁移的能力,这是代码第一方法的固体优势。如果我是你,我会花更多的时间来尝试创建迁移,即使生成器失败,但仍然坚持使用代码,还是手动写入。

Switching to database first however, makes you lose the ability to migrate which is a solid advantage of the code first approach. If I were you, I would spend more time on trying to create a migration, even write one manually if the generator fails but still stick with the code first.

这篇关于实体框架5,首先从代码转换到数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆