There are two classes:

Class A { public string someField {get; set;} public List<SomeOneClass> listClassA {get; set;} } Class B { public string someField {get; set;} public List<SomeOtherClass> listClassB {get; set;} } 

There is an object of type A

 A source = new A(); 

I try to set mapping using Automapper classes A and B like this:

  Mapper.Initialize(cfg => cfg.CreateMap<A, B>() .ForMember(des => des.listClassA, src => src.MapFrom( s => s.listClassB))); 

but mapping for sheets doesn't work that way. Gentlemen, what's the mistake?

  • one
    Read ? - andreycha
  • It's my pleasure. You can post it as an answer, and then accept it. - andreycha
  • For some reason I have no opportunity to mark your comment as an answer. I can only vote for him, as for useful - Dmitriy
  • I mean that you can post your comment with the code as an answer :). - andreycha

1 answer 1

Andreycha, thank you very much. This article read, but apparently not carefully.

 Mapper.Initialize(cfg => cfg.CreateMap<Src, OMAltRight>()); Mapper.CreateMap<A, B>(); var res = Mapper.Map<List<A>, List<B>>(source.documents); B desc = Mapper.Map<A, B>(source); B.listClassB = res;