如何使用的LocalDB和EF工作,而无需使用迁移 [英] How to work with LocalDB and EF, without using migrations

查看:526
本文介绍了如何使用的LocalDB和EF工作,而无需使用迁移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在VS 2012 RTM,与EF 5.我做code第一,但试图忽略code迁移,因为我只是在开发中。为了避免他们,我有这一套。

I am on VS 2012 RTM, with EF 5. I am doing Code First, but trying to ignore Code Migrations since I am just in development. To avoid them, I have this set

Database.SetInitializer(new DropCreateDatabaseIfModelChanges<SomeContext>());

有时,甚至当我不认为我已经触及模式,它决定重建。没关系。但它通常导致错误

Occasionally, even when I don't think I've touched the model, it decides to recreate. That's fine. But it usually results in the error

,因为它正在使用中,无法删除数据库。

Cannot drop database because it is currently in use.

所以,我决定彻底删除数据库。我进入VS,转到SQL Server的对象资源管理器,找到DB并删除它。现在我被困在

So I decided to delete the database entirely. I go into VS, go to the "SQL Server Object Explorer", find the DB and delete it. Now I'm stuck at

无法附加文件{0}数据库{1}

Cannot attach the file '{0}' as database '{1}'

我有这种情况发生,昨晚,我只是摆弄周围,直到它的工作(关停任务,重新启动VS,在web.config等改变了DB和文件名。

I had this happen last night and I just fiddled around until it work (shut down tasks, restart VS, changed the DB and file names in the web.config, etc.

所以,问题1)如何摆脱这种状态吗?

So question 1) How do I get out of this state?

但更重要的问题,我怎么$ P $在这种状态让所有pvent自己?

But the more important question, how do I prevent myself from getting in this state at all?

推荐答案

SQL Server的对象资源管理器窗口可以容纳到数据库的连接。关闭从中打开窗户,所有窗口释放连接。

The SQL Server Object Explorer window can hold a connection to the database. Closing the window and all windows opened from it releases the connection.

这篇关于如何使用的LocalDB和EF工作,而无需使用迁移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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