I wanted to know this is because I want my POCO class totally isolated from EF (my repository and UoW pattern make kt possible to move to NHibernate).
Fluent API > Data Annotations, that is Fluent API has more features than Data Annotations and useful to map table and create relationships. However Fluent API does not have nice label and validation for @Html.LabelFor
and @Html.EditorFor
by using [Display(Name:=...)]
, [DisplayFormat(DataFormatString=...)]
and [Required(ErrorMessage=...)]
. This is what making me headache.
Now found the idea that:
Uses Fluent API in Data layer so my model really POCO class (POCO project) and the dll can be use in WCF and other project which will subscribe to this service.
Uses Data Annotation for ViewModel. Since this is only within UI layer and ViewModel never shared to other project except for MVC View, I dont mind to have Data Annotation attributes.
Redo the constrain created in (1) into (2) like [Required]
and [MaxLength]
. I found some people said it is worth to repeat and volatile the DRY principle since ViewModel and domain model should be separated and does not related to each other even though I think MaxLength
is some how related (just a small repeat and it should be ok for n-tier architecture + I can use static class and const to make the length the same for both side).