是否可以从EF模型中恢复数据库? [英] Is database recovery from EF model possible?

查看:119
本文介绍了是否可以从EF模型中恢复数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Web服务项目,数据库集成当然:)我使用Entity Framework,所以我从我的db(sql server express)生成了我的EF模型。一切都好,直到我的电脑坏了。我有我的项目文件备份,所以我恢复了他们。但是我没有db备份(耻辱)。



据我所知,这个概念是 Code First ,我想知道的是我可以使用它重新生成我的数据库?否则,我必须尝试从旧磁盘获取数据库,或重写整个数据库。



在进入这些斗争之前,我想要问和得到一个适当的答案,因为我以为可以帮助别人。

解决方案

当然可以。



在DbContext构造函数中指定一个连接字符串,存在的数据库,数据库将从头开始创建。



EF工作流程是可逆的,您可以从DB到模型或从模型到DB ,无论模型是图形EDM还是DbContext。


I had a web service project, with a database integration of course :) I use Entity Framework, so I generated my EF model from my db (sql server express). Everything was okay till my computer got broke. I had my project files backed up so I recovered them. But I didn't have the db backup(shame).

As far as I know there is this concept Code First, and what I am wondering is can I use it to regenerate my db? Otherwise I'll have to try getting the db from the old disk, or rewriting the whole db.

Before going into those struggles I wanted ask and get a proper answer to this since I thought it could help others too.

解决方案

Of course, you can.

Specify a connection string in your DbContext constructor, which points to a non-existent database, and the database will be created from scratch.

The EF workflows are "reversible" in the sense that you can go from DB to model or from model to DB, no matter if the model is a graphic EDM or a DbContext.

这篇关于是否可以从EF模型中恢复数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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