You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While I was trying to find a solution to issue #3129, I came across two related problems.
I spent a couple hours looking at the AutoMapper code and found no easy way to fix.
I guess it needs a little more work and insight and I could use some help.
Basically there are 3 things, that need a fix:
ReverseMap() works in combination with MapFrom(...expression...), but doesn't with MapFrom(...sourceMemberName...).
I spotted the problem, basically the implementation(s) of IPropertyMapConfiguration.Reverse() do
not support the case without a source expression.
The issue Attribute-based Reverse Mapping with SourceMember does not work #3129 addresses that the reverse mapping does not work properly when using the AutoMapAttribute together with the SourceMemberAttribute. There are two reasons. One reason is the problem 1, which I just stated and the next one is, that AutoMapper handles the SourceMemberAttribute's after the reverse mapping has been created.
If I switch the order, all unit tests run through, so I guess it comes down to fixing problem 1.
When creating a ReverseMap() with MapFrom(...expression...) on a destination member and if there is a source property with the same name as the destination property, it will get reverse mapped aswell. So a ClientDto with Id = 10 will reverse map to a Client with Id = 10 and LocalId = 10. I do not expect that, because it should be a 1 to 1 mapping, right?
To fix that we would need some Ignore() for the reverse mapping, when using MapFrom.
I don't have a solution, yet.
While I was trying to find a solution to issue #3129, I came across two related problems.
I spent a couple hours looking at the AutoMapper code and found no easy way to fix.
I guess it needs a little more work and insight and I could use some help.
Basically there are 3 things, that need a fix:
ReverseMap()works in combination withMapFrom(...expression...), but doesn't withMapFrom(...sourceMemberName...).So this works as expected:
But this does not work:
I spotted the problem, basically the implementation(s) of IPropertyMapConfiguration.Reverse() do
not support the case without a source expression.
The issue Attribute-based Reverse Mapping with SourceMember does not work #3129 addresses that the reverse mapping does not work properly when using the AutoMapAttribute together with the SourceMemberAttribute. There are two reasons. One reason is the problem 1, which I just stated and the next one is, that AutoMapper handles the SourceMemberAttribute's after the reverse mapping has been created.
If I switch the order, all unit tests run through, so I guess it comes down to fixing problem 1.
When creating a
ReverseMap()withMapFrom(...expression...)on a destination member and if there is a source property with the same name as the destination property, it will get reverse mapped aswell. So a ClientDto with Id = 10 will reverse map to a Client with Id = 10 and LocalId = 10. I do not expect that, because it should be a 1 to 1 mapping, right?To fix that we would need some Ignore() for the reverse mapping, when using MapFrom.
I don't have a solution, yet.
So here are the classes: