I'd like to create an xml snippet from an entity using AutoMapper. Something along the lines of this:
public class SourceEntity
{
public int MasterId { get; set; }
}
public class MappingProfile : Profile
{
public MappingProfile()
{
CreateMap<SourceEntity, XElement>()
.ForMember(
dest => dest.Element("Asset.ID"),
options => options.MapFrom(x => x.MasterId));
}
}
When I instantiate the mapper like this:
var config = new MapperConfiguration(
cfg => { cfg.AddProfile(new MappingProfile()); });
var mapper = config.CreateMapper();
I get this error:
OneTimeSetUp: AutoMapper.AutoMapperConfigurationException : Custom configuration for members is only supported for top-level individual members on a type.
I'm ultimately trying to create an XElement like this:
XElement retVal = new XElement("Asset",
new XElement("ID", src.MasterId)
);
With a .ToString() returning this:
<Asset><ID>789</ID></Asset>