Entity Framework Database First POCO t4 generation and validation

跟風遠走 提交于 2019-12-06 06:20:53

问题


NOTE: I am using ASP.Net application and not MVC [so no validation attribute are supported]

I used Database First approach and then generated my POCO classes using the POCO t4 template. I moved the generated POCO classes in it's own library (Domain.Model).

Now I want to inject validation to the POCO class using Enterprise Library 5. How can I do that. I don't want to perform validation in UI, but want to add the validation attributes using Enterprise Library to the POCO class without modifying the generated POCO class. If I modify it, then whenever I generate new classes, I will loose all my changes. So want to perform validation outside of POCO class but using attributes.

Hope I am not asking something which is not possible


回答1:


In such case you must either give up with POCO generator and create classes manually yourselves - it will allow you to use any attributes you want OR you must modify T4 template to add attributes for you. To modify T4 template you must either use information from metadata to setup correct attributes or you must use structural annotations and manually define attributes in EDMX opened as XML. I described structural annotations here but the example is not related to your problem.



来源:https://stackoverflow.com/questions/5963545/entity-framework-database-first-poco-t4-generation-and-validation

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