Skip to content
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

Update on a single record caused cascade update on entire table, setting all foreign key fields to NULL when upgrading from 3.0 to 7.0 #35595

Open
stepheneire opened this issue Feb 6, 2025 · 1 comment

Comments

@stepheneire
Copy link

Bug description

Hi Team,

Recently when updating from EF Core 3.0 to EF Core 7.0 we discovered a bug that ended up setting millions for foreign key values to NULL. We discovered that a previously supported strategy of disabling the reverse foreign key collections is no longer supported but does not return a runtime error, which it should. Below is the code that set all the foreign keys to NULL.

Your code

var firearm = _dbContext.Firearms
                .Include(x => x.MakeNav)
                .First(x => x.Id == 1);

            firearm.FirStatId = 1;
                
            await _dbContext.SaveChangesAsync(cancellationToken); // This set all the Makes to NULL

This was the strategy we previously used (.Net 3.0) to disable the reverse foreign key collections.
            entity.HasOne(d => d.MakeNav)
                .WithOne()
                .HasForeignKey<Firearms>(d => d.MakeCode)
                .HasConstraintName("FIREARM_FIREARM_MAKE_FK");

Stack traces


Verbose output


EF Core version

7.0.0

Database provider

Oracle.EntityFrameworkCore

Target framework

.NET 8

Operating system

No response

IDE

No response

@AndriySvyryd
Copy link
Member

Can you also include the referenced types and share a small runnable console project?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants