Do i need to create automapper createmap both ways?

BlueChippy picture BlueChippy · May 31, 2011 · Viewed 15.1k times · Source

This might be a stupid question! (n00b to AutoMapper and time-short!)

I want to use AutoMapper to map from EF4 entities to ViewModel classes.

1) If I call

CreateMap<ModelClass, ViewModelClass>()

then do I also need to call

CreateMap<ViewModelClass, ModelClass>()

to perform the reverse?

2) If two classes have the same property names, then do I need a CreateMap statement at all, or is this just for "specific/custom" mappings?

Answer

Ivan Zlatev picture Ivan Zlatev · Jul 26, 2012

For the info of the people who stumble upon this question. There appears to be now a built-in way to achieve a reverse mapping by adding a .ReverseMap() call at the end of your CreateMap() configuration chain.