2
public class Source
{
public ChildSource ChildSource { get; set; }
//some other properties
}
public class ChildSource
{
public List<GrandChildSource> GrandChildSources { get; set; }
//some other properties
}
public class GrandChildSource
{
Public ChildSource ChildSource { get; set; }
//some other properties
}
And Dto classes:
public class SourceDto
{
public ChildSourceDto ChildSource { get; set; }
//some other properties
}
public class ChildSourceDto
{
public List<GrandChildSourceDto> GrandChildSources { get; set; }
//some other properties
}
public class GrandChildSourceDto
{
Public ChildSourceDto ChildSource { get; set; }
//some other properties
}
我想將source/childsource類映射到dto類並忽略GrandChildSources屬性。忽略使用自動映射器的二級兒童
我已經嘗試使用UseDestinationValue和忽略,但它似乎不工作。
Mapper.CreateMap<Source, SourceDto>()
.ForMember(dest => dest.ChildSource, opt => { opt.UseDestinationValue(); opt.Ignore(); })
.AfterMap((source, destination) => Mapper.Map(source.ChildSource, destination.ChildSource));
Mapper.CreateMap<ChildSource, ChildSourceDto>()
.ForMember(d => d.GrandChildSources, opt => { opt.UseDestinationValue(); opt.Ignore(); });
獲得錯誤 「缺失型地圖配置或不支持的映射GrandChildSource」
PS:LazyLoadingEnabled設置爲True。我得到堆棧溢出異常後,我決定忽略GrandChildSources屬性,因爲它有循環引用。
你在做單向或雙向映射嗎? –
如果我理解正確,我認爲它是單向映射 – Jack