Automapper, mapping to a complex object

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))

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

//评论

链接地址: http://www.djcxy.com/p/37380.html

上一篇: AutoMapper:MapFrom和ResolveUsing有什么区别?

下一篇: 自动映射器,映射到一个复杂的对象