Do i need to create automapper createmap both ways?
asp.net-mvc-3, automapper, model, viewmodel
Solution
In AutoMapper you have a Source type and a Destination type. So you will be able to map between this Source type and Destination type only if you have a corresponding CreateMap. So to answer your questions:
- You don't need to define the reverse mapping. You have to do it only if you intend to map back.
- Yes, you need to call CreateMap to indicate that those types are mappable otherwise an exception will be thrown when you call `Map<TSource, TDest>` telling you that a mapping doesn't exist between the source and destination type.
Problem
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?