How do I add a column to a table (schema upgrade) and have it map to an EF code first object

大兔子大兔子 提交于 2019-12-11 02:54:28

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!