Is there any way to get this to work? Here's a simplified/contrived illustration of my issue (Pardon my wordy VB):
Domain Model Classes
Public Class Car
Public Property Id As Integer
Public Property Seats As IEnumerable(Of Seat)
End Class
Public MustInherit Class Seat
End Class
Public Class StandardSeat
Inherits Seat
Public Property Manufacturer As String
End Class
Public Class CustomSeat
Inherits Seat
Public Property Installer As String
End Class
View Model Classes
Public Class CarModel
Public Property Id As String
Public Property Seats As IEnumerable(Of SeatModel)
End Class
Public Class SeatModel
Public Property Manufacturer As String
Public Property Installer As String
End Class
Mapping and Test Code
<Test()> Public Sub Test()
Mapper.CreateMap(Of Car, CarModel)()
Mapper.CreateMap(Of Seat, SeatModel)() _
.ForMember("Manufacturer", Sub(cfg) cfg.Ignore()) _
.ForMember("Installer", Sub(cfg) cfg.Ignore())
Mapper.CreateMap(Of StandardSeat, SeatModel)() _
.ForMember("Installer", Sub(cfg) cfg.Ignore())
Mapper.CreateMap(Of CustomSeat, SeatModel)() _
.ForMember("Manufacturer", Sub(cfg) cfg.Ignore())
Mapper.AssertConfigurationIsValid()
Dim car As New Car With {.Id = 4}
car.Seats = New Seat() {
New StandardSeat With {.Manufacturer = "Honda"},
New CustomSeat With {.Installer = "Napa"}}
Dim model = Mapper.Map(Of Car, CarModel)(car)
model.Id.ShouldEqual("4")
model.Seats.Count().ShouldEqual(2)
' These next two assertions fail.
model.Seats.First().Manufacturer.ShouldEqual("Honda")
model.Seats.Last().Installer.ShouldEqual("Napa")
End Sub