Mapper.AssertConfigurationIsValid();
var s = new Source() { Id = 2, Amount = 10M, Text = "foo" };
var d1 = Mapper.Map(s);
var d2 = Mapper.Map(s);
See Mapping inheritance on AutoMapper wiki.
UPDATE: Here is full code of classes which works as it should.
public class Source
{
public int Id { get; set; }
public string Text { get; set; }
public decimal Amount { get; set; }
}
public class DestinationBase
{
public int Id { get; set; }
}
public class DestinationDerived1 : DestinationBase
{
public string Name { get; set; }
public decimal Value2 { get; set; }
}
public class DestinationDerived2 : DestinationBase
{
public decimal Value { get; set; }
}
UPDATE (workaround of AutoMapper bug):
public static class Extensions
{
public static IMappingExpression MapBase(
this IMappingExpression mapping)
where TDestination: DestinationBase
{
// all base class mappings goes here
return mapping.ForMember(d => d.Test3, e => e.MapFrom(s => s.Test));
}
}