AutoMapper: Does Map <A,B> give <B,A>?

asp.net-mvc, automapper

Solution

No. you must create two way mapping. A good helper method for two way mapping could be :

 protected virtual void ViceVersa<T1, T2>()
        {
            Mapper.CreateMap<T1, T2>();
            Mapper.CreateMap<T2, T1>();
        }

then use it like this :

ViceVersa<T1, T2>();

Problem

Using Automapper I create a simple map: ``` Mapper.CreateMap<MyCustomerDTO, YourCustomerDTO>() ``` I often need to go the other way too. Do I need to also create the mapping the other way, or will Automapper infer it based on the above mapping? ``` Mapper.CreateMap<YourCustomerDTO, MyCustomerDTO>() //Needed? ```

Original source

Related problems