-
Notifications
You must be signed in to change notification settings - Fork 54
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
destination collection is cleared when mapping collection #114
Comments
I can't see that you configure the collection mapping for the entity. If you try to register the equality comparison when you register the type map like the following. Then AutoMapper.Collection knows how the object should be compared. If this step is omitted the standard collection mapping from AutoMapping is used.
|
when I want to map in my action I got this error:
the action code as follows:
and the JSON that I'm sending in Postman is as follows and I got the above error (Model table has two records with Id 1 and 2 and Make table has one record with Id 1):
but if I omit the Id of table Model in JSON, Automapper.Collection removes all records on table Model and save the records again.. |
You need to do equality comparison on the items inside the collections. Model and Models. (I'm asusming they are two distinct classes) Also if it's a misspelled and they are the same class this might still work, although it's not an officially supported case for AutoMapper. Recommendation would be to make a ModelDto and map to that. |
It's working now. Many Thanks. |
I have two models that have a one to many relation:
and the DTO as follows:
I'm using Automapper.Collection to map DTO in update operation:
the issue is I don't know why Automapper.Collection first clears destination collection and then again add new ones, no matter entities in source collection are new, removed or updated.
The text was updated successfully, but these errors were encountered: