Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entity Framework 5, switch from code first to database first?

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?

like image 705
Heath Avatar asked Oct 02 '22 22:10

Heath


1 Answers

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.

like image 53
Wiktor Zychla Avatar answered Oct 11 '22 15:10

Wiktor Zychla