Entity Framework 5 - Migrations and creating table from entity

纵然是瞬间 提交于 2020-01-13 16:55:25

问题


I am using Entity Framework 5 RC and i have some code that require a specific table on the database. The entity is already created using Code-First.

a) Is there a way to tell EF to create the table if its not already created in the database ? If yes.. how ? b) Also.. if the table already exist, can it handle entity changes such adding properties to the entity.. will it get reflected on the database ? (We still use the code-first approach here)

Thanks!


回答1:


Use code first migrations (either automatic or code based). If you are adding table to existing database create initial migration first and than add your new entity. All links are for EF 4.3 but the usage is exactly the same in EF 5.




回答2:


For reference for anyone else having this problem, I had the same problem and my solution is here Entity Framework: Generating specific table if doesn't exist?



来源:https://stackoverflow.com/questions/11183595/entity-framework-5-migrations-and-creating-table-from-entity

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