问题
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:
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
来源:https://stackoverflow.com/questions/7237822/how-do-i-add-a-column-to-a-table-schema-upgrade-and-have-it-map-to-an-ef-code