我能够创建成功的映射,但是只有一个父根类的列表类被映射。在下面的代码中,只有List Designation类失败,而List Customfield类失败。
映射:`
cfg.CreateMap<Emp,Designation>()
.ForMember(a => a.desigs, b => b.ResolveUsing(c => c.designations));
cfg.CreateMap<Emp, Employment>()
.ForMember(a => a.role, b => b.ResolveUsing(c => c..firstname));
cfg.CreateMap<RootObjectSource, RootObjectDest>()
.ForMember(a => a.Customfield, b => b.ResolveUsing(c => c.Emp));
cfg.CreateMap<Emp, Customfield>()
.ForMember(x => x.Customfield, y => y.MapFrom(x => x.Id));
源类:
public class RootObjectSource
{
public List<Emp> employments{ get; set; }
}
public class Emp
{
public string Id{get; set;}
public string Firstname{get; set;}
public string Lastname{get; set;}
public List<Desig> Desigs {get; set;}
}
public class Desig
{
public string role{ get; set; }
public string salary{ get; set; }
}
Destination classes:
public class RootObjectDest
{
public string principal{ get; set; }
public List<Designation> designations{ get; set; }
public List<Customfield> Customfield { get; set; }
}
public class Designation
{
public List<Employment> employment { get; set; }
public string role{ get; set; }
public string salary{ get; set; }
}
public class Employment
{
public string Firstname{ get; set; }
public string Lastname{ get; set; }
}
public class Customfield
{
public string stringfield{ get; set; }
}
我们需要映射目标类别的所有列表类别