Replies: 1 comment 2 replies
-
AutoMapper is not a cloning library. It is not designed to do so. Do not use AutoMapper to clone objects, pick another approach. |
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
Uh oh!
There was an error while loading. Please reload this page.
-
I want to do a deep copy of an object. I expected that when I map object it will return me new instance but on my surprise it returned object by reference.
In my profile file I have:
CreateMap<TrainingSetDto, TrainingSetDto>()
and in the code I wanted to use mapping like this (
_mapper
variable is from DI):var shouldBeCopy= _mapper.Map<TrainingSetDto>(trainingSet);
How to achieve my wanted result to get new instance with same properties ? E.g. on this
blog https://jshowers.com/create-deep-copies-of-object-in-c-using-automapper/
was mentioned that static call
Mapper.Map<Person>(originalPerson);
is the way how to do so. But these static methods are not there anymore. Could you please point me to the right direction ?Thank you.
Beta Was this translation helpful? Give feedback.
All reactions