I can't recreate this directly as it is missing some information (such as the concrete class for the IDataRecord
interface, the content of theDataReader
, etc). However the first check would be to ensure your mapping is correct. Do you test it with AssertConfigurationIsValid
?
For example, if you have the following AutoMapper profile:
public class MyProfile : Profile
{
public override string ProfileName
{
get
{
return "MyProfile";
}
}
protected override void Configure()
{
CreateMap<IDataRecord, Address>()
.ForMember(
target => target.Latitude,
opt => opt.MapFrom(
record => GetDoubleFrom(record, "Latitude", 0)))
.ForMember(
target => target.Longitude,
opt => opt.MapFrom(
record => GetDoubleFrom(record, "Longitude", 0)));
CreateMap<IDataRecord, PhoneNumber>()
.ForMember(
target => target.Extension,
opt => opt.MapFrom(
record => GetStringFrom(record, "Extension", string.Empty)))
.ForMember(
target => target.Number,
opt => opt.MapFrom(
record => GetStringFrom(record, "PhoneNumber", string.Empty)));
CreateMap<IDataRecord, Order>()
.ForMember(
target => target.Address,
opt => opt.ResolveUsing(
record => Mapper.Map<IDataRecord, Address>(record)))
.ForMember(
target => target.PhoneNumber,
opt => opt.ResolveUsing(
record => Mapper.Map<IDataRecord, PhoneNumber>(record)));
}
}
Will this Unit Test pass?
[Test]
public void AutoMapper_Configuration_IsValid()
{
Mapper.Initialize(m => m.AddProfile<MyProfile>());
Mapper.AssertConfigurationIsValid();
}
UPDATE
Can you try
CreateMap<IDataRecord, Order>()
.ForMember(
target => target.Address,
opt => opt.MapFrom(record => Mapper.Map<IDataRecord, Address>(record)))
.ForMember(
target => target.PhoneNumber,
opt => opt.MapFrom(record => Mapper.Map<IDataRecord, PhoneNumber>(record)));