0

I have 2 classes i'm trying to map namely

1) Entity 2) DTO

I'm trying to map Entity.Foo to DTO.Child.Foo

Obviously the below will not work, how do I achieve this. I need to create a new instance of Child and then attach that to the Mapper and then set the Foo property but my AutoMapper skills are not that good!

Mapper.CreateMap<Entity, DTO>()
 .ForMember("Child.Foo", m => m.MapFrom(entity => entity.Foo))
Gilles 'SO- stop being evil'
  • 104,111
  • 38
  • 209
  • 254
user1054637
  • 695
  • 11
  • 28

1 Answers1

2
Mapper.CreateMap<Entity, DTO>()
    .ForMember(d => d.Foo, 
        o => o.ResolveUsing(s => new DTO.Child { Foo = s.Foo }))

// comment

AndrewR
  • 162
  • 1
  • 8
danludwig
  • 46,965
  • 25
  • 159
  • 237