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!
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.
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