Generate POCO classes and the mapping for an existing database using Entity Framework

限于喜欢 提交于 2019-12-24 00:44:00

问题


Is it possible to auto generate the POCO classes and the mapping with the database defined separately using Fluent API (instead of annotations) for an existing database? Instead of coding all these entity classes manually, I find it easier if they are auto generated and then I can change them as required if the names are not incorrect (plural or singular) or the some of the relationships are not correctly mapped etc. This will save lot of time for me compared to coding all the entity classes and relationships from scratch and I am not that familiar with the fluent API syntax as well.


回答1:


Yes, i encourage you to use Entity Framework Power Tools CTP1

Reverse Engineer Code First - Generates POCO classes, derived DbContext and Code First mapping for an existing database.

hope this helps




回答2:


The Power tools are incredibly slow to generate files. It takes over an hour to work on my companies database (has a lot of tables).

Instead take a look at this visual studio extension http://visualstudiogallery.msdn.microsoft.com/ee4fcff9-0c4c-4179-afd9-7a2fb90f5838

It generates cleaner code, WCF serialisation classes, and includes the database default constraints as part of the POCO ctor.

Disclaimer: I should mention that I am the author of this extension



来源:https://stackoverflow.com/questions/8315596/generate-poco-classes-and-the-mapping-for-an-existing-database-using-entity-fram

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