问题
I've already created a database using code first. It worked well. Many changes have since been made to the database outside Visual Studio. So many that any attempt at migration generates errors. So my question is, is there a way to switch a solution from code first to database first?
回答1:
This should be easy, just create a new, database first model and delete your code first model. Most of your code will compile just fine if you are in the same namespace and take care of naming your context in the same way.
Switching to database first however, makes you lose the ability to migrate which is a solid advantage of the code first approach. If I were you, I would spend more time on trying to create a migration, even write one manually if the generator fails but still stick with the code first.
来源:https://stackoverflow.com/questions/18879513/entity-framework-5-switch-from-code-first-to-database-first