views:

23

answers:

1

Whats the difference between DataAnnotations and Application Validation Block?

+1  A: 

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 scenario's. 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 scenario’s.

Steven