Auto generating metadata classes for Entity Framework

别说谁变了你拦得住时间么 提交于 2019-12-07 11:00:32

问题


I am considering using xVal for validation of Entity Framework classes in a MVC application. This involves writing metadata classes as explained in details by Graham O'Neale (http://goneale.com/2009/03/04/using-metadatatype-attribute-with-aspnet-mvc-xval-validation-framework).

I am wondering if there's a way to auto generate such metadata classes using the metadata from the SQL database (for example: not null fields will have [Required] class attribute.


回答1:


You could use Code Smith tool www.codesmithtools.com (there is a free version if I remember correctly)




回答2:


I wrote an application that will read an existing database and then generate a Data Annotation Class for every table (excluding aspnet_* and VersionInfo).

http://pfsolutions-mi.com/Product/MetaDataClassGenerator




回答3:


In EF 4, you can easily customize the code generation via a T4 template.



来源:https://stackoverflow.com/questions/2229716/auto-generating-metadata-classes-for-entity-framework

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