如何首先使用 EF 4 代码重构代码/数据库架构 - 数据迁移
使用 codefirst EF4 进行数据库重构的最佳实践是什么?
我很想听听当 RecreateDatabaseIfModelChanges 选项不可行时人们如何更改类和数据库。需要进行数据迁移。
目前,Microsoft 有一个首先使用模型来执行此操作的解决方案:
有人有代码优先的好策略吗?
What are the best practices for database refactoring with codefirst EF4?
I am interested to hear how people change the classes and the database when the RecreateDatabaseIfModelChanges option is not feasible. Migration of data will need to occur.
Currently Microsoft has a solution for doing this with model first:
Does anyone have a good strategy for code first?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
EF 团队一直致力于为 EF 开发迁移功能,以解决此问题。
http:// /blogs.msdn.com/b/efdesign/archive/2010/10/22/code-first-database-evolution-aka-migrations.aspx
Scott Gu 在他最近的欧洲之旅中表示,他们应该发布很快就有这个功能了。我屏住呼吸。
激动人心的更新:
现已作为 CTP 发布:
http ://blogs.msdn.com/b/adonet/archive/2011/07/27/code-first-migrations-august-2011-ctp-released.aspx
The EF team have been working on a migrations feature for EF that should solve this problem.
http://blogs.msdn.com/b/efdesign/archive/2010/10/22/code-first-database-evolution-aka-migrations.aspx
Scott Gu said on his recent tour around Europe that they should be releasing this feature soon. I'm holding my breath.
EXCITING UPDATE:
This has now been released as a CTP:
http://blogs.msdn.com/b/adonet/archive/2011/07/27/code-first-migrations-august-2011-ctp-released.aspx
我正在研究数据库上下文初始化程序,如果模型和数据库架构不同步,它将通知网站管理员,并显示不同之处。这对于喜欢完全控制代码优先模型和数据库模式的开发人员来说非常有用。看看:
https://github.com/rialib/efextensions
I am working on database context initializer which will notify webmaster if model and db schema are out of sync and will show what differs. This can by useful for developers who prefer to have complete control both over code-first model and database schema. Check it out:
https://github.com/rialib/efextensions
在我的 CodeFirst 应用程序中,本地构建有一个 app.config 标志,表示不在生产中。当我不在生产中时,它会完全破坏并重新创建数据库。由于我的生产数据库用户没有删除数据库的权限,即使我的 web.config 转换以某种方式丢失(因此 EF 尝试重新创建数据库),我的生产数据库也不会被删除,而是会引发异常。
我的工作流程是这样的:
步骤#2 根据最新的数据模型自动创建一个新的、干净的数据库,因此我始终知道我拥有一个最新的数据库,该数据库不包含可能尚未准备好生产的开发工作的工件。
In my CodeFirst application, local builds have a app.config flag that denotes not being in production. When I'm not in production it completely nukes and recreates the database. Since my production database user does NOT have permissions to drop the database even if my web.config transform is missed somehow (thus EF tries to recreate the database) my production database will not be deleted, and instead an exception will be thrown.
My workflow goes like this:
Step #2 automatically creates a new, clean database based on the latest data model so I always know I have an up to date database that doesn't have artifacts from development efforts that may not be production ready yet.