我首先使用 Entity Framework 4.1 代码为网站创建了一个数据库。我需要向我的实体类之一添加一个简单的属性,并向数据库添加相应的(可能可为空)列,而不会丢失数据库中的任何数据。
我认为我可以删除该网站,更改数据库以添加列,并使用更新的实体类重新部署网站,但我不确定这是进行此架构升级的最佳方法。
是否有一种标准(或更好)的方法对首先使用代码创建的数据库进行架构升级?
I have a database that I created for a site using Entity Framework 4.1 code first. I need to add a simple property to one of my entity classes, and add a corresponding (possibly nullable) column to the database without losing any of the data in the database.
I think I can take down the site, alter the database to add the column, and redeploy website with an updated entity class, but I'm not sure that's the best way to do this schema upgrade.
Is there a standard (or just better) way of doing a schema upgrade on a DB that was created using code first?
发布评论
评论(1)
实体框架 Code First 在预览版中有一个名为 Code First 迁移的新功能,它可以进行简单的架构升级。
您可以在这里查看 http://blogs.msdn.com/b/adonet/archive/2011/07/27/code-first-migrations-walkthrough-of-august-2011-ctp.aspx
Entity Framework Code First has a new feature in preview called Code First Migrations, which does simple schema upgrades.
You can check it out here http://blogs.msdn.com/b/adonet/archive/2011/07/27/code-first-migrations-walkthrough-of-august-2011-ctp.aspx