Nuget CodeFirst EntityFramework 迁移或同步数据库
我一直在使用 EntityFramework 的代码优先方法尝试 ASP.NET MVC 3。我面临着几个问题。
如果架构更改和/或更新模型,如何同步数据库。现在我必须删除并重新创建数据库,从而丢失所有数据。是否有可用的包我可以用来自动更新架构。在其中一个演示中,我看到 Scott Hanselman 使用“EntityFramework.Migration”包。我猜是没有释放使用。有替代方案吗?
MvcScaffolding 重新创建所有视图/控制器。如果执行 MVCScaffolding 并重新创建视图,是否有办法在视图中保留 CSS 样式。
提前致谢。
I have been trying ASP.NET MVC 3 using Code-First approach with EntityFramework. There are couple of issues I am facing.
How do I sync the database if schema changes and/or I update my model. Right now i have to delete and re-create the database thus loose all my data. Is there a package available i can use to automatically update the schema. In one of the demos I saw Scott Hanselman using "EntityFramework.Migration" package. I guess that is not released use. Any alternatives?
MvcScaffolding recreates all View/Controllers. Is there a way to preserve CSS Styling in Views if the MVCScaffolding is executed and views are re-created.
Thanks in advanced.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
有多种工具可以生成数据库更改脚本。就实体框架本身而言,即将推出的 EntityFramework.Migrations 也将处理此问题。
http:// /blogs.msdn.com/b/efdesign/archive/2010/10/22/code-first-database-evolution-aka-migrations.aspx
我不确定你的第二个问题。我个人不使用自动生成视图,但是,我相信您应该能够修改 T4 模板以按照您想要的方式生成视图。
There are various tools to generate change scripts for databases. As far as entity framework itself, there is the soon to come EntityFramework.Migrations that will also handle this.
http://blogs.msdn.com/b/efdesign/archive/2010/10/22/code-first-database-evolution-aka-migrations.aspx
I am not sure about your second question. I personally do not use the automatic generation of views, however, I believe you should be able to modify a T4 template to generate your views the way you want.
关于您的数据丢失问题,请考虑使用数据库 初始值设定项 类。您可以在每次模型更改时播种数据。我知道这并不理想,但这就是我们现在 EF 4.1 所拥有的一切。您可以使用类似 红门的 SQL保持环境同步的工具带。作为包的一部分,您可以同步数据。您始终可以备份 SQLToolbelt 创建的脚本。
Regarding your data loss issue, look into using the database initializer classes. You can seed data each time your model changes. I know this is not ideal, but it is all we have right now with EF 4.1. You can use something like Red Gate's SQL tool-belt to keep environments synced. As part of the package, you can sync data. You can always back-up the scripts created by SQLToolbelt.
对于脚手架问题,只需更改脚手架模板本身,使其包含 CSS 类。这样,每当你重新搭建脚手架时,CSS 类都会在那里。
更多相关信息
For Scaffolding issue, just change the scaffolding templates themselves so they contain the CSS classes. this way, whenever you re-scaffold, the CSS classes will be there.
More about this here