I have the following abstract classes
public abstract class BaseClass
{
public int NumberProperty { get; set; }
}
public abstract class BaseClass_DTO
{
public int NumberProperty { get; set; }
public string NumberPropertyAsString { get; set; }
}
and the following concrete class
public class ConcreteA : BaseClass
{
public string StringProperty { get; set; }
}
public class ConcreteA_DTO : BaseClass_DTO
{
public string StringProperty { get; set; }
}
And this is the Map
Mapper.Initialize( cfg => {
cfg.CreateMap<BaseClass, BaseClass_DTO>()
.ForMember( p => p.NumberPropertyAsString, opt => opt.MapFrom( x => x.NumberProperty.ToString() ) );
cfg.CreateMap<ConcreteA, ConcreteA_DTO>()
.IncludeBase<BaseClass, BaseClass_DTO>()
.ReverseMap();
} );
Mapper.AssertConfigurationIsValid();
The code says that the configuration is not valid because of
Unmapped members were found. Review the types and members below.
Add a custom mapping expression, ignore, add a custom resolver, or modify the source/destination type
=============================================================================
ConcreteA_DTO -> ConcreteA (Source member list)
Temporary.Test.ConcreteA_DTO -> Temporary.Test.ConcreteA (Source member list)
Unmapped properties:
NumberPropertyAsString
The error happens because of the ReverseMap()
call. How do I set the reverse map to ignore the member without duplicating the Map?