Just a quick Q, Is the Fluent API is replaceable for Data Annotations in term of features?
What the features in Data Annotations that is not included in Fluent API?
I want to use Fluent API because of Separation of Concern (between my model & persistence), convention over configuration (mapping defined in one place DbContext.OnModelCreating() but not at every model property) and I want to use VS 2010 Layer Validation to make sure my POCO classes will never have dependencies to EF, but what I miss if I totally remove Data Annotation from my source?
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.LabelForand@Html.EditorForby 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 thinkMaxLengthis 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).