title: ASP.Net Web API Validation Attributes on DTO?
body: <p>I'm using ASP.Net Web API and the Code First Entity Framework and from what I've read you should typically be exposing DTO objects rather than the entity objects directly in your action methods (according to <a href="http://www.asp.net/web-api/overview/data/using-web-api-with-entity-framework/part-5">http://www.asp.net/web-api/overview/data/using-web-api-with-entity-framework/part-5</a>).</p>
  
  <p>So in one case I'm working on, to avoid the problem of "over-posting" as described in the link above I've created a DTO object with almost all the same properties as the model object. What I'm wondering however is do I need to duplicate all the same sets of validation attributes (eg. [Required], [Range(N,M)], etc. for both the DTO and model properties? Initially I was hoping not to (to avoid duplication) but you need the validation attributes on the DTO if you want to leverage the binding validation (ie. ModelState.IsValid) and on the main model if you want your database to be created with the appropriate constraints ([Required] -> not null, etc.)</p>
  
  <p>Is there no better way?</p>
  
  <p>Also, are there some attributes that Entity does use but the model binding validation does not use? For example, while [Range(n,m)] will clearly affect validation on some client input, does entity care about it at all (it doesn't seem to affect the created DB schema from what I can tell?)</p>