Whats the difference between DataAnnotations and Application Validation Block?
To add validation using DataAnnotations attributesAdd a namespace declaration to the partial class that matches the namespace of the data model that you are using. An incorrect namespace used in a partial class results in a naked partial class, which is a partial class that is not associated with any other class.
DataAnnotations is used to configure your model classes, which will highlight the most commonly needed configurations. DataAnnotations are also understood by a number of . NET applications, such as ASP.NET MVC, which allows these applications to leverage the same annotations for client-side validations.
The following three type of validations we can do in ASP.NET MVC web applications: HTML validation / JavaScript validation. ASP.NET MVC Model validation.
Data annotations (available as part of the System. ComponentModel. DataAnnotations namespace) are attributes that can be applied to classes or class members to specify the relationship between classes, describe how the data is to be displayed in the UI, and specify validation rules.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With