-
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
ValueGenerator doesn't use NextAsync for the added object by the entity relation after SaveChangesAsync #30936
Comments
This is currently by-design. If async value generation is needed, then Note for triage: with HiLo becoming more useful since EF Core 7, async value gen is likely to get more use. While the general case can't be changed, we could re-introduce |
One additional radical/spicy thought: we could also move value generation to SaveChanges-time, rather than doing it at Add-time. The main advantage here is that we'd be able to obsolete AddAsync, which seems to cause quite a bit of confusion (and is indeed rarely needed). This would also align client-side value generation to happen at the same time as database-generated, which would make our behavior a bit more consistent. Of course, this would mean users need to wait until SaveChanges before they can copy out the generated property (again, just like database-generated). This is related to #30753, where we may want to switch to server-generated GUIDs by default (it represents the same minor breaking change). |
@roji One of the original motivations for Hi/Lo was that it generated real IDs as soon as the entity is tracked--same reason for client-side GUIDs. EF6 could never do this, and it was a frequent complaint. We could create a HiLo generator which has the characteristics that you like while not generating IDs until SaveChanges. (i.e. one extra round trip ever x number of calls to SaveChanges.) That would be much simpler in lots of places, but wouldn't match one of the main reasons for doing it in the first place. |
You're saying that many people complained about not being able to get the real ID before calling SaveChanges? That strikes me as a bit odd, but in that case yeah, the current behavior makes more sense. |
Duplicate of #30957 |
File a bug
When I have added an entity by the inner relation, without invoking the AddAsync method. After SaveChangesAsync my attached ValueGenerator doesn't use the override NextAsync method to generate async value, instead of it uses sync method.
Include your code
Include stack traces
NONE
Include verbose output
it's caused by:
Include provider and version information
EF Core version:
Database provider: Npgsql.EntityFrameworkCore.PostgreSQL
Target framework: .NET 6.0 / EF 6.0.6
Operating system: Mac os
The text was updated successfully, but these errors were encountered: