-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Navigation Collection Cleared after first SaveChanges #16483
Comments
@fromberg100 The update method does this:
If that's not your intention, then that might be the issue. Otherwise, please post a small, runnable project/solution or complete code listing that demonstrates the behavior you are seeing. |
I was not clearing the collection, however, I tried and also got the same results. I missed to include that I override Equals:
When I do not override Equals, then it works ok. I believe this is related to issue #16161 |
@fromberg100 Please post a small, runnable project/solution or complete code listing that demonstrates the behavior you are seeing. |
please find solution enclosed. Please read carefully the comments I wrote specifically on top of method SetSameChildren on file Program.cs (line no. 52) If there is anything unclear, please let me know. |
@fromberg100 Confirmed this is a duplicate of #16161. However, note that defining |
Hi,
I am having an issue when updating a collection of an existing entity. Everything is OK when I call _dbContext.SaveChanges() the first time.
Before calling SaveChanges(), all items in collection are marked as EntityState.Added which is Ok, and when I call SaveChanges() the items are inserted into the database.
But after that, the navigation collection is cleared and its items are marked as EntityState.Deleted, and if I call SaveChanges() again they are deleted from the database.
See structure below (simplified):
The update method is as follows:
Am I doing something wrong?
The text was updated successfully, but these errors were encountered: