I use ASP.Net Web API and First Entity Framework, and from what I read, you should usually show DTO objects and not entity objects directly in your action methods (according to http://www.asp.net/web -api / overview / data / using-web-api-with-entity-framework / part-5 ).
So, in one case that I am working on to avoid the βoversubscriptionβ problem, as described in the link above, I created a DTO object with almost all of the same properties as the model object. However, I wonder if I need to duplicate all the same sets of validation attributes (for example, [Required], [Range (N, M)], etc. For DTO and model properties? Initially, I was hoping (to avoid duplication ), but you need DTO check attributes if you want to use a binding check (for example, ModelState.IsValid) and the main model if you want your database to be created with the appropriate restrictions ([Required] β not null, etc. d.)
Is there a better way?
Also, are there some attributes that Entity uses, but not model binding verification? For example, while [Range (n, m)] will explicitly affect validation on any client input, does it even take care of it at all (this does not seem to affect the created database schema from what I can to tell?)
source share