Пытается обновить до AutoMapper 5.1 из v4.2 и обнаруживаю, что коллекция не отображается во время выполнения - исходный объект имеет элементы в коллекции, но свойство назначения сопоставления пуст.Вложенные коллекции, не работающие в AutoMapper 5.1
Под 4.2, все работало точно так, как ожидается, с одной и той же конфигурации отображения (за исключением MemberList.None в() CTOR CreateMap)
меня DTOs как так
public class GeographicEntity
{
...
}
public class County : GeographicEntity
{
...
}
public class State : GeographicEntity
{
public List<County> Counties { get; } = new List<County>();
}
И ViewModels как так
public class GeographicEntityViewModel
{
...
}
public class CountyViewModel : GeographicEntityViewModel
{
...
}
public class StateViewModel : GeographicEntityViewModel
{
public List<CountyViewModel> Counties { get; } = new List<CountyViewModel>();
}
и подтверждение Mapping как так
Mapper.Initialize(configuration =>
{
configuration.CreateMap<GeographicEntity, GeographicEntityViewModel>(MemberList.None);
configuration.CreateMap<County, CountyViewModel>(MemberList.None)
.IncludeBase<GeographicEntity, GeographicEntityViewModel>();
configuration.CreateMap<State, StateViewModel>(MemberList.None)
.IncludeBase<GeographicEntity, GeographicEntityViewModel>();
});
После вызова> Mapper.Map <, коллекция уездах StateViewModel пуст (список с 0 пунктов), даже если исходный объект имеет элементы в своей коллекции .Counties:
var st = new State()
... (initialize the state, including the .Counties list)
var stateViewModel = Mapper.Map<StateViewModel>(st);
Все ключи будет оценена!