views:

279

answers:

2

A short while ago I'm sure I read that is was possible to use AutoMapper to map the validation attributes from the domain model to the view model, i can't find that post any more though!

Has anybody seen any code or know if it would be possible to do this? This would give the added benefit of not repeating validation in both ViewModel + Models.

Paul

A: 

Phil Haack did a blog post about this. Also, check out this video.

Bradley Mountford
I have seen these, the MetadataType option doesn't work for me because on my ViewModel I only have a subset of properties from my domain model. I get an exception if I don't include all properties from the MetaData class in my ViewModel...otherwise this would be perfect.
Paul Hinett
A: 

No, via automapper it's not possible, probably some reflection.emit gurus could help ya
look here: http://stackoverflow.com/questions/3037805/copy-an-attribute-of-a-property-from-one-instance-to-another-instance-of-a-diffe

Omu