使用实体框架代码首先更新数据库模式 [英] Updating database schema with Entity Framework Code First
问题描述
到目前为止,我发现,当架构发生变化时,如何从头重新生成整个数据库,但是我不想丢失数据。
如果没有错误,Ruby on Rails有一个工具可以生成反映新数据库更改的SQL脚本。有没有办法在EF Code First中执行此操作?
我正在使用EntityFramework.Migrations库发展DB模式的问题。它可以创建生成SQL脚本以更新模式的迁移类。
目前它仍处于测试阶段,但我发现它很有用。不幸的是,您仍然应该生成数据迁移脚本。
您可以找到更多信息 here 。
Entity Framework Code First is a great framework for developing new projects. But what about extending an existing database?
For instance what if I simply want to add an additional property to an existing data entity? Is there any "code first" way to do this or will I have to add a database column by hand using SQL Server Management Studio or a similar tool?
All I have found so far is how to regenerate the entire database from scratch when the schema changes, but I don't want to lose my data.
If I'm not mistaken, there is a tool for Ruby on Rails that can generate an SQL script reflecting the new database changes. Is there any way to do this in EF Code First as well?
I'm currently using EntityFramework.Migrations library which addresses the problem of evolving the DB schema. It works creating migration classes which generate SQL scripts to update your schema.
It is still in beta at this time but I found it useful. Unfortunatly you should still generate data migration scripts.
You can find more information here.
这篇关于使用实体框架代码首先更新数据库模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!