How to create a mapping to a primitive type with AutoMapper.
Posted on: November 30, 2012
If you want to map one of your complex object to a primitive you cannot use the ForMember method of Automapper to do it. Instead, you have to use the ConvertUsing.
Here is a case of ComplexType which reprensent a boolean value.
1Mapper .CreateMap<ComplexType, bool>() .ConvertUsing(f=>f.ID);23Mapper .CreateMap<bool, ComplexType>() .ConvertUsing(f => new ComplexType(f));
This is usefull if you have view models that represent primitive data and you want them to be represented into a view model object.