AutoMapper 6.1.0 released
See the release notes:
As with all of our dot releases, the 6.0 release broke some APIs, and the dot release added a number of new features. The big features for 6.1.0 include those for reverse-mapping support. First, we detect cycles in mapping classes to automatically preserve references.
Much larger however is unflattening. For reverse mapping, we can now unflatten into a richer model:
public class Order {
public decimal Total { get; set; }
public Customer Customer { get; set; }
}
public class Customer {
public string Name { get; set; }
}
We can flatten this into a DTO:
public class OrderDto {
public decimal Total { get; set; }
public string CustomerName { get; set; }
}
We can map both directions, including unflattening:
Mapper.Initialize(cfg => {
cfg.CreateMap<Order, OrderDto>()
.ReverseMap();
});
By calling ReverseMap
, AutoMapper creates a reverse mapping configuration that includes unflattening:
var customer = new Customer {
Name = "Bob"
};
var order = new Order {
Customer = customer,
Total = 15.8m
};
var orderDto = Mapper.Map<Order, OrderDto>(order);
orderDto.CustomerName = "Joe";
Mapper.Map(orderDto, order);
order.Customer.Name.ShouldEqual("Joe");
Dogs and cats living together! We now have unflattening.
Enjoy!