I have two classes that are displayed. The source class has a DateTime property that maps to a target property of type long ( DateTime.Ticks ), respectively UpdateDt and UpdateDtTicks .
When I use Automapper to map these two classes, my UpdateDtTicks property automatically gets the value from the UpdateDt property, even if the property names do not match, and I have not explicitly set the mapping for this property.
Is Automapper automatically setting a property because property names differ only at the end? If not, then why is this happening because this is unexpected behavior.
See code below:
static void Main(string[] args) { Configuration.Configure(); var person = new OrderDto { OrderId = 999, MyDate = new DateTime(2015, 1, 1, 4, 5, 6) }; var orderModel = Mapper.Map<OrderModel>(person); Console.WriteLine(new DateTime(orderModel.MyDateTicks.Value)); Console.ReadLine(); } public class OrderDto { public int OrderId { get; set; } public DateTime MyDate { get; set; } } public class OrderModel { public int OrderId { get; set; } public long? MyDateTicks { get; set; } } public class Configuration { public static void Configure() { Mapper.CreateMap<OrderDto, OrderModel>(); } }
Result in the console:

And the watch:

source share