A workaround for the removed ForAllOtherMembers(opt => opt.Ignore()) #3911
wertzui
started this conversation in
Show and tell
Replies: 2 comments 2 replies
-
@wertzui Can you please explain why your solution doesn't work with EntityFramework? Would it work in ef core? |
Beta Was this translation helpful? Give feedback.
2 replies
-
In my case it threw null reference while assigning the first member.
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
As already described in #3833 ForAllOtherMembers was removed in the recent version of AutoMapper.
I too was relying on it to map only specific properties of a source into an existing destination object.
@jakubfijalkowski made a great example in that discussion:
So instead of listing every wanted member with
ForMember
and ignoring the rest withForAllOtherMembers
, it is possible to achieve a similar outcome using this code:It is not much harder to write and you can keep your existing code that looks like this
I know that is does not work together with EntityFramework, or anything else that relies on analyzing the expressions.
However for simple scenarios this might save some people rewriting their business code.
Beta Was this translation helpful? Give feedback.
All reactions