I\'m trying to use AutoMapper to flatten multiple levels of arrays.
Consider the following source classes:
class X {
public string A { get; set;
Try this mapper,
Mapper.CreateMap();
Mapper.CreateMap();
Mapper.CreateMap()
.ForMember(destination => destination.A, options => options.MapFrom(source => source.A)).IgnoreAllNonExisting()
.ForMember(destination => destination.C, options => options.MapFrom(source => Mapper.Map, IEnumerable>(source.B).FirstOrDefault().C))
.ForMember(destination => destination.E, options => options.MapFrom(source => Mapper.Map, IEnumerable>(source.B.SelectMany(d => d.D)).FirstOrDefault().E))
.ForMember(destination => destination.F, options => options.MapFrom(source => Mapper.Map, IEnumerable>(source.B.SelectMany(d => d.D)).FirstOrDefault().F));
var result = Mapper.Map, IEnumerable>(arrayOfX);