Replies: 1 comment 2 replies
-
ReverseMap is designed for simple scenarios. Might I suggest not using AutoMapper if the behavior is unexpected and difficult to change? Mapping into more complex objects will be inherently more complex so I would avoid it. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have recently had some issues where I was not expecting ReverseMap to also create unflattening automatically because of lack of experience with automapper. When I finally found out what was going on I looked for ways to fix it but I was a bit disappointed. There are currently two ways to do this:
.ForMember(dest => dest.Foo, opt => opt.MapFrom(src => src.Alpha!.Bravo!.Charlie.Delta))
and then.ForPath(dest => dest.Alpha!.Bravo!.Charlie.Delta, opt => opt.Ignore())
This is quite verbose and if the path ever changes you will need to fix it in two places.
Instead I would like to propose a third option. Simply adding an optional boolean parameter into MapFrom that if set to false would prevent unflattening. Something like this:
P.S.: The problem this caused to me was that a value I modified in the source (Delta in this example) was getting overwritten during mapping by copies of the original value from objects with the flattened parameters. This made it impossible to change the Delta variable as long as one or more objects containing the flattening were present.
Beta Was this translation helpful? Give feedback.
All reactions