-
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
Working with Disconnected Graphs #5092
Comments
We have a similar problem, when we try to add a new child to parent. When calling DbContext.Update(entity) we get a DbUpdateConcurrencyException with message "Database operation expected to affect 1 row(s) but actually affected 0 row(s). Data may have been modified or deleted since entities were loaded." Is this behavior intended or a bug? Simple code below in a txt-file: |
EF Core 1.0 actually includes a new method on the
We agree that there would be value in including more of a "turnkey" API in EF Core for handling disconnected graphs, but this is one of those things that are often easier to handle at the application level by leveraging knowledge specific to each model. Handling disconnected graphs in an automatic way for any application would poise additional challenges and design choices which we haven't tackled yet. A few examples:
|
For triage: Clearing up milestone and labels to bring this issue back to triage. Originally my plan was to respond to customers with some additional details and close this issue a duplicate of a backlog issue issue, but I haven't been able to find an existing issue for a turnkey solution for disconnected graphs. |
Opened #5536 to track a turn-key solution |
It would be nice if the Entity Framework Core 1.0 API providing a better level of support for the disconnected graph scenario (i.e. where changes are made on a web client and the results posted back to the server where the context is not aware of the changes to the state of the world). The current API provides two methods, one called Attach which by default adds the whole tree in an "Unchanged" state and one called Update which by default adds the whole tree in a "Modified" state. As I understand it - the intention for the first is that the user builds up the state of the world manually by setting the status of entities manually, and the second marks everything within the graph as modified updating or adding any missing entries.
However, to my mind, this misses the case where the disconnected client has removed entities. In the case where you have a Parent and some Children, and one of those children are removed (but not assigned any other parent) - is ignored because it is not a part of the graph. Therefore, when the client removes a child from the parent - it is left to the developer to work this change out.
If such a scenario could be avoided by a further API method (Merge?), or perhaps by changing Update to include this scenario - this would be fantastic. There would be cost to this as it would involve a trip to the database and comparison to be made to the current DB state compared to the state of the tree. GraphDiff supports this by labelling properties as either Associated or Owned to work out the state of a graph.
The (very basic) code below shows a simple example where a child has been removed and the DbContext Update method did not do quite what I had expected it would do.
The text was updated successfully, but these errors were encountered: