I'm creating an MVC3 application with EF4 using POCOs. I've added validation attributes to my EF entities. Now, as I'm building the views, I want to use a view model (and perhaps use AutoMapper to fill them).
The problem that I have run into is that I have to redefine my validation attributes on my view model which violates the DRY principal. For example, if I decide to change the size of a field, I have to change the MaxLength attribute on both the POCO and any view models that use it.
Is there some tricky way I can map the validation rules from my POCOs to my view model?
I too struggle with this, and I agree that it violates DRY. I posted a recent question about this Here and got quite a bit of pushback.
You can't ever get perfect DRY in any real world application. Sometimes you get more good out of violating a principle than by trying to stick to it blindly.
EDIT:
One might also consider that DRY can violate the Single Responsibility Principle (SRP). By reusing similar code, you are now causing the code to do more than one thing. If you think about the fact that data models and view models have different purposes, and thus different responsibilities... combing them into a single model violates SRP. That is, by making your data model also be a view model, that's two different responsibilities.
Now, one can think of a number of ways to potentially try and reconcile SRP with DRY in this regard, but at some point you have to weigh the benefits from the cost.