-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mapping to existing object of same type returns the source instead of modifying the destination #656
Comments
While investigating the issue, I noticed it occurs only if the source and destination type are the same. If they're different, it works as expected. |
OK, I think I know what's going on; if there is no map defined for |
@jbogard, can you please explain why you closed this issue? Is the current behavior by design? |
Yep - the assignable mapper is about assigning one object to another. If you want to override that, use CreateMap to explicitly tell AutoMapper "I intend to use the mapping conventions to go from one side to the other". |
OK, thanks |
Ok, so to use map to auto-assign same properties on destination object of type A from source type A, I can create a profile :
But imagine that I want to be able to use this on my 100 classes likewise. I'll get something like :
Is there another "state of the Automapper art" way of doing it ? For instance in the |
It's easy to create all those default maps using reflection, Assembly.GetTypes or smth similar. |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
EDIT: actually, the problem is not related to
CreateMissingTypeMaps
; see comments belowJust noticed a bug where
CreateMissingTypeMaps = true
has no effect when you pass an existing destination object toMapper.Map
. Here's a quick repro using LinqPad:Mapping to a new instance with
Mapper.Map<Foo>(foo1)
works as expected.Also, if I explicitly create the map for
Foo -> Foo
, then the map forBar -> Bar
is correctly created, so it seems the problem only affects the root of the mapping.Another issue (perhaps unrelated) that bothers me is that the mapping fails silently... the destination object is left untouched, and
Mapper.Map
just returns the source object (it returns the destination object when the mapping succeeds). Shouldn't it throw an exception?The text was updated successfully, but these errors were encountered: