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 と Ignore を使用してみましたが、機能していないようです。
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 プロパティを無視することにしました。