简体   繁体   中英

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?

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM