实体框架数据库第一POCO T4生成和验证 [英] Entity Framework Database First POCO t4 generation and validation

查看:113
本文介绍了实体框架数据库第一POCO T4生成和验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请注意:我使用ASP.Net应用程序,而不是MVC [所以没有验证特性支持]

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

我使用的数据库第一种方法,然后使用POCO T4模板生成我的POCO类。我感动于它自己的库中生成的POCO类(Domain.Model)。

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).

现在我想用企业库5.我怎样才能做到这一点注入验证该POCO类。我不想在UI执行验证,但要添加使用企业库的POCO类属性的验证,而无需修改生成的POCO类。如果我修改它,然后每当我产生新的类,我将失去我的所有更改。所以想POCO类的,但使用属性之外执行验证。

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

推荐答案

在这种情况下,你必须要么放弃与POCO发生器和手动创建类自己 - 它可以让你使用任何你想要的属性或您必须修改T4模板添加属性为您服务。要修改模板,T4,你必须使用信息从元数据来设置正确的属性或必须使用的结构性注释,并在EDMX开辟为XML手动定义属性。我所描述的结构注释<一个href=\"http://stackoverflow.com/questions/5912839/how-do-i-use-structural-annotations-to-set-sql-type-to-date-in-model-first-approa/5924143#5924143\">here但这个例子不涉及您的问题。

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆