如何首先将我的EF Code-First转换为数据库? [英] How to convert my EF Code-First to Database first?
问题描述
无法将您的代码优先类转换为数据库优先类。无论您是否存在代码优先类,都可以从数据库创建模型创建一整套新的类。
但是,您可能不想删除代码优先课程。实体框架数据库第一模型为所有实体对象创建部分类。如果您的代码优先类中有任何业务逻辑(除了普通的旧属性之外的任何东西),可以将它们声明为 partial
,删除属性,并维护业务逻辑。基本上,您在EF Designer中生成* Designer.cs文件中的属性,同时在.cs文件中定义业务逻辑。
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?
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.
这篇关于如何首先将我的EF Code-First转换为数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!