0

I am trying to map one nested object to another like the below example. I can easily map BobAge to JimAge etc. But how do I map Bobs Collection to Jims collection. This can go n levels deep. Thanks very much

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));
Larry R
  • 43
  • 6
  • Sorry, for me it's working without an issue when I take your code example. Please give an actual example of what's not working – grek40 Aug 10 '18 at 14:23
  • See https://dotnetfiddle.net/aL7Ru6 for my test – grek40 Aug 10 '18 at 14:25
  • Thanks for the reply. Basically I made a stupid mistake and Bobs was a single Bob and not a collection. Just completely missed it. – Larry R Aug 10 '18 at 14:45
  • Ok, it can happen, no problem. Voting to close, since this kind of error is not really likely to help resolving similar problems. – grek40 Aug 12 '18 at 17:04

0 Answers0