-
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
Child entities not persisting when using AddRangeAsync and SaveChangesAsync #7298
Comments
I too face same issue while adding enity with child collection using AddRangeAsync with SaveChangesAsync |
Note for triage: looks like async Add methods are, at least sometimes, only acting on a single object. @cdarrigo @mkprajeen You almost certainly don't need to use the async methods for Add/AddRange. They provide no benefit over the sync versions except when using the specialized sequence value generator. (It would be great to know if you are actually using that value generator.) |
It works fine when I changed to AddRange instead of AddRangeAsync. thanks ajcvickers |
@divega @rowanmiller Should this also go in 1.1.1? AddAsync first shipped in 1.1. |
To me it seems like a serious enough issue to warrant a patch. |
Talked to @divega and moving. |
Justification: The behavior of Add and AddAsync should be the same. The async versions not doing graph behavior is a copy/paste error. |
Issue #7298 This requires quite a lot of new async code because all the graph traversal and processing code now needs async paths.
Issue #7298 This is a lower-risk fix replacing #7430. The fix is to call the non-async methods. There is an extremely low probability that any real-world code is making database calls in the async methods combined with an even lower probability that making those calls synchronously would cause issues, so this fix is low-risk and does not have binary-compat issues.
This patch bug is approved. Please use the normal code review process w/ a PR and make sure the fix is in the correct branch, then close the bug and mark it as done. |
Issue #7298 This is a lower-risk fix replacing #7430. The fix is to call the non-async methods. There is an extremely low probability that any real-world code is making database calls in the async methods combined with an even lower probability that making those calls synchronously would cause issues, so this fix is low-risk and does not have binary-compat issues.
Issue #7298 This is a lower-risk fix replacing #7430. The fix is to call the non-async methods. There is an extremely low probability that any real-world code is making database calls in the async methods combined with an even lower probability that making those calls synchronously would cause issues, so this fix is low-risk and does not have binary-compat issues.
✅ Verified |
Attempting to add a graph of entities where there is a 1:m relationship (parent: children) using the AddRangeAsync and Savechanges Async method will prevent the children from being persisted to the DB.
In the code below, the a collection of StoreProductEntity (Parent) are being persisted in the DBContext . Each StoreProductEntity has an IList (child). After calling AddRangeAsync() and SaveChangesAsync(), only the parent entities are persisted, the children are not.
This is different behavior than the corresponding synchronous methods, AddRange() and SaveChanges(), where in the entire graph (parent and children) are persisted to the DB.
Further technical details
EF Core version: 1.1
Database Provider: Microsoft.EntityFrameworkCore.SqlServer
Operating system: Win 10
IDE: Visual Studio 2015
The text was updated successfully, but these errors were encountered: