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

喜夏-厌秋 提交于 2020-01-22 15:15:31

问题


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?


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/21732865/how-to-convert-my-ef-code-first-to-database-first

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!