It is easy to add validation e.g. RequiredAttribute
as attributes dev time:
[Required, StringLength(100)]
public string Title {get; set;}
But what if my model is an entity (part of EF Core model, described with fluent EF Core API) and I want to extract validation information from EF Core model at run-time (requried, string length, custom annotations)? How to add the validation rules for Title
field (and do not decorate entity with attributes , that means to avoid validation information duplication)?
I could try to add attributes using reflection to each instance and this could work, but I just search for the alternative validation API. Is it really absent?
I of course can through away the standard validation, create my own validation functions and load errors to ModelState
but then I loose the jquery-validation-unobtrusive
client side validation configuration.