实体框架数据库首个POCO t4生成和验证 [英] Entity Framework Database First POCO t4 generation and validation
问题描述
我使用Database First方法,然后生成我的POCO类使用POCO t4模板。我将生成的POCO类移动到自己的库(Domain.Model)中。
现在我要使用Enterprise Library 5向POCO类注入验证。那。我不想在UI中执行验证,但是希望使用Enterprise Library将验证属性添加到POCO类中,而无需修改生成的POCO类。如果我修改它,那么每当我生成新的类时,我将会放弃所有的更改。所以要在POCO类之外执行验证,但使用属性。
希望我不要求不可能的东西
在这种情况下,您必须放弃POCO生成器并手动创建类 - 它将允许您使用任何您想要的属性,或者您必须修改T4模板以添加属性您。要修改T4模板,您必须使用元数据中的信息来设置正确的属性,否则您必须使用结构注释,并手动定义以XML格式打开的EDMX中的属性。我描述了结构注释这里,但该示例与您的问题无关。
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
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.
这篇关于实体框架数据库首个POCO t4生成和验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!