-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Batched query breaks after upgrade to 7.0 - The UPDATE statement conflicted with the FOREIGN KEY constraint #29562
Comments
Possibly related to #29356, but that looks like it was already closed and is included in 7.0 GA? |
@cornem are you able to submit a minimal code sample which reproduces the error? |
@roji I've been trying that for the last few hours. If I reduce the source code (it's a complex data context with dozens of cross-referenced tables) to about three entities, the error occurs every time I run it against a copy of the database with actual production data. When I copy the same data out of the original database to a new database with a simple structure, the problem goes away. Also downgrading So it must be something in v7 that's triggering the error, I'm just not able yet to isolate exactly how to reproduce it. |
@cornem thanks for the effort you're putting into this - it's not suprising that specific data is needed in the database in order to trigger this. Is it an option for you to send the data along with the code sample (hopefully reducing it to a minimum before doing so)? You can share it via my email (on my github profile). |
@roji I've been trying; but even then I run into the strange phenomenon that the issue somehow gets resolved.
Not sure if that helps to narrow down what's going on, but I'll keep trying to come up with a reproducible sample 😅 |
@cornem thanks again for spending time on this - it's unfortunate it's so difficult. I'll try to to inspect the code today, but a repro would obviously be the best way forward. The moment you get anything reliable together, please feel free to send it to me. |
I've emailed you a sample that should fail under |
Thanks @cornem, I'll look into it. |
Duplicate of #29502 |
@cornem thanks again for the precise repro (I wish all users submitted such repros). This turned out to be a duplicate of #29502 - when running against the commit of the fix, the error no longer occurs (but does one commit before). The fix has already been merged into main (for 8.0), and a PR is out for backporting it to 7.0.x as well (#29590). Can you try running with the latest daily build (docs) and confirm that the issue goes away for you? Unfortunately, it may take quite some time for a 7.0 patch version to come out with the fix; in the meantime you can either use a 8.0 daily build (which should be fine - almost identical to 7.0.0), or add modelBuilder.Entity<Delivery>().ToTable(t => t.HasTrigger("foo")); |
Thanks for your efforts @roji and glad to hear the issue was already known and possibly fixed. I've tried your suggestions:
|
@cornem see #29539 (comment) for how to get the actual latest 8.0 build (or daily build docs aren't yet up to date for 8.000). Can you try with 8.0.0-alpha.1.22567.1 or above and report whether that helps? |
After updating the |
Thanks for confirming! |
After upgrading to version 7.0 of EntityFramework, we are encountering an error. The error thrown is
The UPDATE statement conflicted with the FOREIGN KEY constraint
.Minimal extract from actual code:
This works OK as long as there are only a few
Delivery
entities to insert, however, after 42 entities, EF creates multiple inserts, and that's when it apparently goes wrong. When it subsequently tries to update thePackingSlip
entities to set theDeliveryId
reference, there is now an incorrect reference (see@p651
):Include provider and version information
EF Core version: 7.0.0
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: net7.0
Operating system: Windows 11
IDE: Visual Studio 2022 17.4
The text was updated successfully, but these errors were encountered: