Using AutoMapper to unflatten a DTO

前端 未结 7 954
执念已碎
执念已碎 2020-11-28 07:52

I\'ve been trying to use AutoMapper to save some time going from my DTOs to my domain objects, but I\'m having trouble configuring the map so that it works, and I\'m beginni

7条回答
  •  旧时难觅i
    2020-11-28 08:36

    Can't post a comment, so posting an answer. I guess there were some changes in AutoMapper implementation so answer https://stackoverflow.com/a/5154321/2164198 proposed by HansoS is no longer compilable. Though there is another method that can be used in such scenarios - ResolveUsing:

    Mapper.CreateMap()
        .ForMember(dest => dest.Address, opt => opt.ResolveUsing( src => { return new Address() {Address1 = src.Address, City = src.City, State = src.State }; }))
    

提交回复
热议问题