DataAnnotations or Application Validation block

浪尽此生 提交于 2020-01-02 03:36:12

问题


Whats the difference between DataAnnotations and Application Validation Block?


回答1:


DataAnnotations is an attribute based model to 'annotate' your data and it is in the .NET framework itself. Its most obvious use is for validation, as ASP.NET MVC does for instance. Validation Application Block itself is a validation framework, created by the Microsoft P&P team, but it is not part of the .NET framework. It also contains attributes to 'annotate' your data and in its newest version (5.0) the attributes inherit from DataAnnotations, making it interchangeable with DataAnnotations to some extent.

Validation Application Block, or the whole Enterprise Library actually, is more focused on enterprise development. VAB allows many more complex scenarios. For instance it allows you to put the validation rules in configuration files, or (with a bit of work) in code. It also allows a feature called 'rulesets', allowing to group validations and trigger only a single group of rules on an object. There isn’t much you cannot do what validation is concerned with VAB, but this of course comes at a price. The price is complexity. While designed properly, VAB is not easy to learn as I’m still learning new ways to do things with it.

Compared to DataAnnotations, DataAnnotations is very easy, but also very limited when it comes to more complex scenarios.



来源:https://stackoverflow.com/questions/3565097/dataannotations-or-application-validation-block

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