How to create a mapping to a primitive type with AutoMapper.
Posted on: 2012-11-30
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.
Mapper .CreateMap<ComplexType, bool>() .ConvertUsing(f=>f.ID);
Mapper .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.