如何手动更新实体框架code第一个模型,以便更新数据库(一个新的列)? [英] How to manually update Entity framework Code first model so that it updates a database (with a new column)?

查看:136
本文介绍了如何手动更新实体框架code第一个模型,以便更新数据库(一个新的列)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以告诉我,我怎么能一个数据成员(COL)添加到我的MVC3模型(类),并无需生成一切从零开始它更新数据库?我是从code第一个工作日。当我改变我的模型,然后运行项目中,我得到一个错误,指出模型已经改变。任何清洁,简单的方法来同步与DB /模型创建一个新的COL /数据mamber?

can somebody tell me how I can add a data member (col) to my mvc3 model (class) and have it update the database without having to generate everything from scratch? I'm working from code first. When I change my model then run my project I get an error stating that model has changed. Any clean and easy way to synch creating a new col/data mamber with the db/model?

谢谢!

推荐答案

您可以在应用程序启动使用,

you can use this in application start,

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

这将重新生成数据库,如果你的模型变化happens.And如果你不想删除并创建数据库(以增量开发),可以使用SqlMigrations。 <一href=\"http://www.hanselman.com/blog/EntityFramework$c$cFirstMigrationsAlphaNuGetPackageOfTheWeek10.aspx\" rel=\"nofollow\">http://www.hanselman.com/blog/EntityFramework$c$cFirstMigrationsAlphaNuGetPackageOfTheWeek10.aspx

这篇关于如何手动更新实体框架code第一个模型,以便更新数据库(一个新的列)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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