It appears to be a breaking change in how polymorphic collections mapped between versions 3.3.1 and 4.0.0 and greater.
I'm attempting to map the following list:
var entities = new List<BaseEntity>
{
new ChildEntity<int> {Id = 0, ValueOne = 1, ValueTwo = 2},
new ChildEntity<string> {Id = 0, ValueOne = "One", ValueTwo = "Two"}
};
var dtos = Mapper.Map<List<BaseDto>>(entities);
The mapping I'm using is:
Mapper.CreateMap<BaseEntity, BaseDto>()
.Include(typeof(ChildEntity<>), typeof(ChildDto<>));
Mapper.CreateMap<ChildEntity<int>, ChildDto<int>>();
Mapper.CreateMap<ChildEntity<string>, ChildDto<string>>();Version 3.3.1 correctly maps a polymorphic entity collection to a polymorphic DTO collection:
Assert.IsType(typeof(ChildDto<int>), dtos[0]);
Assert.IsType(typeof(ChildDto<string>), dtos[1]);
Version 4 maps to a collection of base DTOs:
Assert.IsType(typeof(ChildDto<int>), dtos[0]); // Fails
Assert.IsType(typeof(BaseDto), dtos[0]); //SucceedsIs it by design? How the correct mapping would look like?
Here is the gist:
https://gist.github.com/anonymous/871fa2410d242436fe4c