的EntityFramework修改数据库,而不是重新创建的 [英] EntityFramework Modify Database Instead of Recreate

查看:194
本文介绍了的EntityFramework修改数据库,而不是重新创建的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

林与EF 4.1 C#MVC3工作。
当我修改我的车型之一的atributte(IE:我添加属性公共BOOL死{集;获取;} 我Player.cs)的EF下降,重新创建整个数据库。

Im working with C# MVC3 with EF 4.1. When i modify an atributte of one of my Models (IE: I add the property public bool dead {set; get;} to my Player.cs) the EF Drops and Recreate the whole Database.

我知道这happend因为我有这样的:

I know that this happend because i have this:

的Global.asax.cs

protected void Application_Start(){
    ...
    Database.SetInitializer<GameContext>(new DropCreateDatabaseIfModelChanges<GameContext>());
    ...
}

我只想EF新列添加到我的播放表,无需重新创建完整的数据库,我已经使用Django同样的问题,但我用南来解决这个(一个amaizing工具)。存在类似EF什么?

I just want to EF add the new column to my Player table, no re-create the full database, i had the same problem with Django, but i used South to solve that (an amaizing tool). Exist something similar to the EF?

我不能种子与公共类GameInitializer数据库:DropCreateDatabaseIfModelChanges&LT; GameContext&GT; 定义,由我自己把所有的值,因为是DINAMIC

I can't seed the Database with an public class GameInitializer : DropCreateDatabaseIfModelChanges<GameContext> definition and put all the values by myself, because are dinamic.

我几乎认为,唯一的选择就是手动将列添加到我的表,嗯......我有一个问题,当我的MDF文件添加到我的服务器资源管理器,项目无法打开数据库再次(甚至当我分离,并关闭了连接),它有点怪怪的。

I hardly think that the only option is to add manually the columns to my table, well... i have a problem with that, when i add the MDF File to my server explorer, the project can't open the database again (even when i detached and closed the connection), its kinda strange.

嗯,这是我的问题!
TIA。

Well, that's my problem! TIA.

推荐答案

EF目前还没有建立数据库的任何增量方式,但有一个叫单独的项目<一个href=\"http://blogs.msdn.com/b/adonet/archive/2011/11/29/$c$c-first-migrations-beta-1-released.aspx\">$c$c首先迁移将提供此功能。迁移目前处于测试阶段,应该是未来的EF版本的一部分。

EF currently don't have any incremental way to build the database but there is separate project called Code First Migrations which will offer this functionality. Migrations are currently in Beta and should be part of future EF version.

所以,你既可以使用迁移或您必须手动修改数据库(尝试关闭/打开VS解决您的本期)。

So you can either use migrations or you must manually modify your database (try to close / open VS to solve your current issue).

这篇关于的EntityFramework修改数据库,而不是重新创建的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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