Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fluent Validation vs. Data Annotations

People also ask

Should I use fluent validation?

Advantages of using Fluent ValidationsSpeed of development- It is easy to work with. Decoupling validation rules and models- Fluent Validation allows you to separate validation rules from your model and helps you structure the rules so that they are nice and readable.

Is data annotation client side validation?

As per MSDN, the Data Annotations attributes cause MVC to provide both client and server validation checks with no additional coding required by you. The Data Annotations attributes can be used with the Entity Data Model (EDM), LINQ to SQL, and other data models.

What are data annotations?

Data annotation is the categorization and labeling of data for AI applications. Training data must be properly categorized and annotated for a specific use case. With high-quality, human-powered data annotation, companies can build and improve AI implementations.

What is fluent validation in .NET core?

Fluent Validation is a free to use . NET validation library that helps you make your validations clean, easy to create, and maintain. It even works on external models that you don't have access to, with ease. With this library, you can separate the model classes from the validation logic like it is supposed to be.


I prefer Fluent Validation:

  1. It gives me far better control of my validation rules
  2. Doing conditional validation on different properties is so much easier compared to Data Annotations
  3. It separates the validation from my view models
  4. Unit testing is far easier compared to Data Annotations
  5. It has excellent client side validation support for most standard validation rules

I clearly prefer Data Annotations because ...

  1. all validation rules can be configured in one place in code (within the model metadata class) and don't need to be repeated anywhere else.
  2. there is excellent support for client side validation (again – without repetition of validation rules!) when using Data Annotation attributes.
  3. Data Annotation attributes can be tested to ensure they're there.
  4. there are nice additional validation attributes created by the community (e.g. Data Annotations Extensions).