Using AutoMapper to unflatten a DTO

前端 未结 7 955
执念已碎
执念已碎 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条回答
  •  情书的邮戳
    2020-11-28 08:36

    This might be late but you can solve this by using lambda expressions to create the object like this:

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

提交回复
热议问题