user3177651
user3177651

Reputation:

How to convert my EF Code-First to Database first?

I want to convert my code-first project to Database first. Is there an automated way or should I just delete the entities and context code and create a model from the created database?

Upvotes: 7

Views: 9140

Answers (2)

BJ Myers
BJ Myers

Reputation: 6813

There is no way to convert your code-first classes into database-first classes. Creating the model from the database will create a whole new set of classes, regardless of the presence of your code-first classes.

However, you might not want to delete your code-first classes right away. The entity framework database-first model creates partial classes for all of the entity objects. If you have any business logic (anything besides the plain old properties) in your code-first classes, you can declare them as partial, remove the properties, and maintain the business logic. Essentially, you're letting EF generate the properties in the *Designer.cs file, while you define the business logic in your .cs files.

Upvotes: 3

Adam Modlin
Adam Modlin

Reputation: 3024

It appears Entity Framework Power Tools supports a feature called "Reverse Engineer Code-First". You can download it here.

Upvotes: 3

Related Questions