-
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
Call to change tracker changes unchanged many to many relationship to deleted #26831
Comments
@luizfbicalho This line: left.Rights = new List<Right>(); removes all the existing entities from Rights, but requires change detection to happen. See Change Detection. It's possible that improving local detect changes when |
This issue I managed to use the change detection to reproduce another problem that I have I have an extension on the Newtonsoft.Json to read from the json properties and load the correct entities from the database, this way when I finish loading the entity, it's clear for EF what I have to change. The problem with the many to many relationship is that I can't refresh them, and it's weird, because I could imagine two scenarios.
But my problem is that It end up as deleted. |
Is there anything that I can do to spped things up in this issue? |
I have one update in some entities
I clear a list of entities , then I update it with the new entities (in this examples the new list has the same old entities)
If I call context.ChangeTracker.Entries(); after the list list clear, and before the new entities added, I get that the relationship is deleted
Left {Id: 111} Modified
Right {Id: 151} Unchanged
Right {Id: 152} Unchanged
Right {Id: 153} Unchanged
LeftRight (Dictionary<string, object>) {LeftsId: 111, RightsId: 151} Deleted FK {LeftsId: 111} FK {RightsId: 151}
LeftRight (Dictionary<string, object>) {LeftsId: 111, RightsId: 152} Deleted FK {LeftsId: 111} FK {RightsId: 152}
LeftRight (Dictionary<string, object>) {LeftsId: 111, RightsId: 153} Deleted FK {LeftsId: 111} FK {RightsId: 153}
If I don't call the context.ChangeTracker.Entries(); the result is this
Left {Id: 114} Modified
Right {Id: 155} Unchanged
Right {Id: 156} Unchanged
Right {Id: 157} Unchanged
LeftRight (Dictionary<string, object>) {LeftsId: 114, RightsId: 155} Unchanged FK {LeftsId: 114} FK {RightsId: 155}
LeftRight (Dictionary<string, object>) {LeftsId: 114, RightsId: 156} Unchanged FK {LeftsId: 114} FK {RightsId: 156}
LeftRight (Dictionary<string, object>) {LeftsId: 114, RightsId: 157} Unchanged FK {LeftsId: 114} FK {RightsId: 157}
Include provider and version information
EF Core version: 6.0
Database provider: (Microsoft.EntityFrameworkCore.SqlServer)
Target framework: ( .NET 6.0)
Operating system: Windows 10
IDE: (e.g. Visual Studio 2022 Version 17.1.0 Preview 1.1)
The text was updated successfully, but these errors were encountered: