We are trying to map an object - a Tridion Outbound Email Contact - which has a custom dictionary type property with an internal constructor - ExtendedDetailCollection
It's fine mapping from the object onto a Viewmodel
Mapper.CreateMap<Contact,ContactViewModel>()
.ForMember(x=>x.Name, m=>m.MapFrom(x=>x.ExtendedDetails["Name"].StringValue))
but the other way does not work
We have tried:
Mapper.CreateMap<ContactViewModel,Contact>()
.ForMember(x=>x.ExtendedDetails["Name"].Value, m => m.MapFrom(x=>x.Name));
but that throws a runtime exception.
Edit: The message of the exception is:
AutoMapper.AutoMapperConfigurationException : Custom configuration for members is only supported for top-level individual members on a type.
We have also tried the various type converters and value resolvers but none allow us to get at the object being mapped to, which is what we need to get access to in order to map the ExtendedDetails object.
Mapper.CreateMap<ContactViewModel,Contact>()
.ForMember(x=>x.ExtendedDetails, m => ????);
Is there a pattern for this or is it easier just to use a static method?
If ExtendedDetails is a class you need to createMap for this class and then individual property like Name of the class.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With