Sometimes you need to grab a value from a relations table, as in this case the sortorder of the specific relation between a "list" and an "item".
Using Automapper i have always had issues with this and usually just been lazy and mapped the other properties manually or used the AfterMap feature.
But today i found out about the IncludeMembers method. It's super simple and you just include the inner property and automapper will treat it just like it's "merged" with the actual source.
CreateMap<ListItemRelation, ItemForCustomList>()
.IncludeMembers(s => s.Item)
.ForMember(dest => dest.SortOrder, o => o.MapFrom(src => src.Sortorder)));
Top comments (0)