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
}
Я хотел бы сопоставить классы источника/childsource классам dto и игнорировать свойство GrandChildSources.Игнорировать ребенка второго уровня с помощью automapper
Я попытался использовать 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(); });
Получение ошибки "конфигурации Missing типа карты или неподдерживаемый отображение для GrandChildSource"
PS: LazyLoadingEnabled установлено значение True. Я решил проигнорировать свойство GrandChildSources после получения исключения переполнения стека, поскольку он получил круговую ссылку.
Вы делаете одностороннее или двустороннее сопоставление? –
Если я правильно понимаю, я думаю, что это одностороннее сопоставление – Jack