Mapping Child Collections using AutoMapper

左心房为你撑大大i 提交于 2019-12-04 18:19:40

When creating the maps you can use a method and that method can do pretty much anything. For example:

public void MapStuff()
{
    Mapper.CreateMap<StoreDTO, Store>()
        .ForMember(dest => dest.Location, opt => opt.MapFrom(source => DoMyCleverMagic(source)));
}

private ReturnType DoMyCleverMagic(Location source)
{
    //Now you can do what the hell you like. 
    //Make sure to return whatever type is set in the destination
}

Using this method you could pass it an Id in the StoreDTO and it can instantiate a location :)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!