我正在尝试将一个嵌套对象映射到另一个嵌套对象,如以下示例所示。我可以轻松地将BobAge映射到JimAge等。但是如何将Bobs Collection映射到Jims集合。这可以深入n个层次。非常感谢
public class Bob
{
public int BobAge { get; set; }
public string BobName { get; set; }
public List<Bob> Bobs { get; set; }
}
public class Jim
{
public int JimAge { get; set; }
public string JimName { get; set; }
public List<Jim> Jims { get; set; }
}
cfg.CreateMap<Bob, Jim>()
.ForMember(d => d.JimAge, opt => opt.MapFrom(src => src.BobAge))
.ForMember(d => d.JimName, opt => opt.MapFrom(src => src.BobName))
.ForMember(d => d.Jims, opt => opt.MapFrom(src => src.Bobs));