开发者

Putting validation at property level in entity of entity framework

开发者 https://www.devze.com 2023-03-25 17:45 出处:网络
I am using T4 template to generate entity from .edmx file, now i want to put validation on entity, My requirements are :

I am using T4 template to generate entity from .edmx file, now i want to put validation on entity,

My requirements are :

1) I am developing win application,Each property of entity is binding with data source, so want to ke开发者_运维问答ep strategy, that when save button is pressed ,corresponding entity is validated and controls which binds invalid property will display error icon,

2) I dont want to keep my validation in data layer, because there are some business validation and custom messages in business layer...


I'm using the Fluent Validation framework. The approach is to implement an external Validator for each entity you want to validate. It's very easy but the most important thing it allows you to choose in which layer you want to place validation. You find it on codeplex at:

http://fluentvalidation.codeplex.com/

You can gain the separation between entities and validators that you cannot get with Annotations (e.g.: Enterprise Library).

Hope it helps

0

精彩评论

暂无评论...
验证码 换一张
取 消