MapTo icon indicating copy to clipboard operation
MapTo copied to clipboard

ReverseMap() capability

Open alandotic opened this issue 3 years ago • 1 comments

Hi , I was using automapper to map my DTO with my Entity in my project, bumped into this and decided to give it a try. Normally once i defined my DTO i can use .ReverseMap() to handle the reverse mapping case as state here https://docs.automapper.org/en/stable/Reverse-Mapping-and-Unflattening.html

using back the example in README

var user = new User(id: 10) { FirstName = "John", LastName = "Doe" };

var vm = user.ToUserViewModel(); // A generated extension method for User class.

var newUser = User.fromViewModel(vm)

is that possible to be done?

alandotic avatar Jul 06 '21 04:07 alandotic

It is definitely possible. It isn't supported yet because of the current implementation of the MappingContext, which is responsible for handling cyclic references. Currently, It has limited capabilities and only supports partial types that are annotated with MapFromAttribute. Still, I am planning to make it more generic and add support for handling external types. Once it's done, adding ReverseMap functionality should be fairly straightforward.

mrtaikandi avatar Jul 11 '21 17:07 mrtaikandi