In my application I have my Model structure decorated with DataAnnotations. This helps with my validation perfectly, however I'm not sure how to have those DataAnnotations persist down to my ViewModels without double entry.
Basically I'm lazy, and I'm trying to keep it as DRY as possible.
class User
{
[Required]
public string FirstName {get; set; }
[Required]
public string LastName {get; set; }
public datetime RegistrationDate {get; }
}
class CreateUserViewModel
{
public string FirstName {get; set; }
public string LastName {get; set; }
}
The first class never gets used by the View, however it contains all of the DataAnnotations required by the application. The second class is always used by the CreateUser View, but I don't want to have to reapply the DataAnnotations. Is this possible? If so, how?