简体   繁体   English

实体框架数据库首先POCO t4生成和验证

[英]Entity Framework Database First POCO t4 generation and validation

NOTE: I am using ASP.Net application and not MVC [so no validation attribute are supported] 注意:我使用的是ASP.Net应用程序,而不是MVC [因此不支持验证属性]

I used Database First approach and then generated my POCO classes using the POCO t4 template. 我使用Database First方法,然后使用POCO t4模板生成我的POCO类。 I moved the generated POCO classes in it's own library (Domain.Model). 我将生成的POCO类移动到它自己的库(Domain.Model)中。

Now I want to inject validation to the POCO class using Enterprise Library 5. How can I do that. 现在我想使用Enterprise Library 5向POCO类注入验证。我该怎么做。 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. 我不想在UI中执行验证,但是想要使用Enterprise Library将验证属性添加到POCO类而不修改生成的POCO类。 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. 所以想要在POCO类之外执行验证,但是使用属性。

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. 在这种情况下,您必须放弃POCO生成器并自己手动创建类 - 它将允许您使用您想要的任何属性,或者您必须修改T4模板以为您添加属性。 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. 要修改T4模板,您必须使用元数据中的信息来设置正确的属性,或者必须使用结构注释并在EDMX中以XML格式手动定义属性。 I described structural annotations here but the example is not related to your problem. 在这里描述了结构注释但该示例与您的问题无关。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM