I've been told the principal of DRY in Asp.Net MVC is very important. I've also been told that part of adhering to this is not to repeat entity property attributes such as [Required] and [Display(Name="Shuttle Name")] in the ViewModel where possible.
I've also been told that separation between data, business and presentation layers is important. So I’m wondering why an attribute such as [Display] is on an entity in my ProjectName.Entity project. I love the idea of the data layer not having a whiff of the presentation layer’s existence. I would personally prefer to have no display info in my Data layer and no Data entities directly mapped to controls in my Presentation layer.
eg. Use a simple ViewModel which contains the private Shuttle entity property and public properties for any of its properties that require displaying or editing:
private readonly Shuttle shuttle;
public ShuttleViewModel() { this.shuttle = new Shuttle(); }
public ShuttleViewModel(Shuttle shuttle)
{
this.shuttle = shuttle;
}
[Required]
[Display(Name = "Shuttle Name")]
public string ShuttleName
{
get { return this.shuttle.Name; }
set { shuttle.Name = value; }
}
I realise that this may be repeating attributes in the ViewModel that are already in the Entity class and mapping data manually but from experience I have found that it Works Every Time. I have also seen some horribly non-intuitive exceptions thrown when a complex entity is uber-mapped to a ViewModel. So I would love some feedback on DRY vs WET.