v4.2 から AutoMapper 5.1 にアップグレードしようとすると、実行時にコレクションがマッピングされないことがわかります。ソース オブジェクトにはコレクション内のアイテムがありますが、マッピングされた宛先プロパティは空です。
4.2 では、すべてが同じマッピング構成で期待どおりに機能しました (CreateMap() ctor の MemberList.None を保存します)。
私はそのようなDTOを持っています
public class GeographicEntity
{
...
}
public class County : GeographicEntity
{
...
}
public class State : GeographicEntity
{
public List<County> Counties { get; } = new List<County>();
}
そして、そのようなビューモデル
public class GeographicEntityViewModel
{
...
}
public class CountyViewModel : GeographicEntityViewModel
{
...
}
public class StateViewModel : GeographicEntityViewModel
{
public List<CountyViewModel> Counties { get; } = new List<CountyViewModel>();
}
そしてマッピング確認はこんな感じ
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<> 呼び出しの後、ソース オブジェクトの .Counties コレクションにアイテムが含まれていても、StateViewModel の Counties コレクションは空 (0 アイテムのリスト) です。
var st = new State()
... (initialize the state, including the .Counties list)
var stateViewModel = Mapper.Map<StateViewModel>(st);
手がかりをいただければ幸いです。