Description
Bug description
A relationship between the parent and child is defined with a "OnDelete(DeleteBehavior.NoAction)" configuration to prevent a cascade delete. We want to keep the child if the parent is deleted.
modelBuilder.Entity<Parent>()
.HasMany(c => c.Children)
.WithOne()
.IsRequired()
.OnDelete(DeleteBehavior.NoAction);
The child can be removed from one parent and added to another, but when the changes are saved an exception is thrown.
fromParent.Children.Remove(child);
toParent.Children.Add(child);
await _context.SaveChangesAsync();
System.InvalidOperationException: The association between entity types 'Parent' and 'Child' has been severed, but the relationship is either marked as required or is implicitly required because the foreign key is not nullable. If the dependent/child entity should be deleted when a required relationship is severed, configure the relationship to use cascade deletes. Consider using 'DbContextOptionsBuilder.EnableSensitiveDataLogging' to see the key values.
A workaround is to use DeleteBehavior.ClientCascade instead of DeleteBehavior.NoAction.
Your code
A solution with a test that reproduces the issue can be found here: https://github.com/richard1927/ef-child-to-parent-error
Here is the code from that solution
public class Child
{
public int Id { get; set; }
public string Name { get; set; }
}
public class Parent
{
public int Id { get; set; }
public required string Name { get; set; }
public ICollection<Child> Children { get; set; } = new List<Child>();
}
public class ReproContext(DbContextOptions<ReproContext> options) : DbContext(options)
{
public DbSet<Parent> Parents { get; set; }
public DbSet<Child> Children { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Parent>()
.HasMany(c => c.Children)
.WithOne()
.IsRequired()
.OnDelete(DeleteBehavior.NoAction);
}
}
[Collection("SqlServer collection")]
public class ReproTest
{
private readonly ReproContext _context;
public ReproTest(SqlServerContainerFixture fixture)
{
var options = new DbContextOptionsBuilder<ReproContext>()
.UseSqlServer(fixture.GetConnectionString())
.Options;
_context = new ReproContext(options);
}
[Fact]
public async Task Test()
{
// Arrange
var fromParent = new Parent{Id = 1, Name = "From"};
_context.Parents.Add(fromParent);
var toParent = new Parent{Id = 2, Name = "To"};
_context.Parents.Add(toParent);
var child = new Child{Id = 3, Name = "Child"};
fromParent.Children.Add(child);
_context.Children.Add(child);
await _context.SaveChangesAsync();
// Act
fromParent.Children.Remove(child);
toParent.Children.Add(child);
await _context.SaveChangesAsync();
}
}
public class SqlServerContainerFixture : IAsyncLifetime
{
private readonly MsSqlContainer _msSqlContainer = new MsSqlBuilder().Build();
public async Task InitializeAsync()
{
await _msSqlContainer.StartAsync();
await using var connection = new SqlConnection(_msSqlContainer.GetConnectionString());
await connection.OpenAsync();
const string createTablesCommand = """
CREATE TABLE Parents (
Id INT PRIMARY KEY,
Name NVARCHAR(100)
);
CREATE TABLE Children (
Id INT PRIMARY KEY,
ParentId INT,
Name NVARCHAR(100),
FOREIGN KEY (ParentId) REFERENCES Parents(Id)
);
""";
await using var command = new SqlCommand(createTablesCommand, connection);
await command.ExecuteNonQueryAsync();
}
public async Task DisposeAsync()
{
await _msSqlContainer.DisposeAsync();
}
public string GetConnectionString()
{
return _msSqlContainer.GetConnectionString();
}
}
[CollectionDefinition("SqlServer collection")]
public class SqlServerCollection : ICollectionFixture<SqlServerContainerFixture> { }
Stack traces
System.InvalidOperationException: The association between entity types 'Parent' and 'Child' has been severed, but the relationship is either marked as required or is implicitly required because the foreign key is not nullable. If the dependent/child entity should be deleted when a required relationship is severed, configure the relationship to use cascade deletes. Consider using 'DbContextOptionsBuilder.EnableSensitiveDataLogging' to see the key values.
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry.HandleConceptualNulls(Boolean sensitiveLoggingEnabled, Boolean force, Boolean isCascadeDelete)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry.HandleNullForeignKey(IProperty property, Boolean setModified, Boolean isCascadeDelete)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry.SetProperty(IPropertyBase propertyBase, Object value, Boolean isMaterialization, Boolean setModified, Boolean isCascadeDelete, CurrentValueType valueType)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry.SetProperty(IPropertyBase propertyBase, Object value, Boolean isMaterialization, Boolean setModified, Boolean isCascadeDelete)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry.set_Item(IPropertyBase propertyBase, Object value)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.NavigationFixer.ConditionallyNullForeignKeyProperties(InternalEntityEntry dependentEntry, InternalEntityEntry principalEntry, IForeignKey foreignKey)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.NavigationFixer.NavigationCollectionChanged(InternalEntityEntry entry, INavigationBase navigationBase, IEnumerable`1 added, IEnumerable`1 removed)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntryNotifier.NavigationCollectionChanged(InternalEntityEntry entry, INavigationBase navigationBase, IEnumerable`1 added, IEnumerable`1 removed)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.ChangeDetector.DetectNavigationChange(InternalEntityEntry entry, INavigationBase navigationBase)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.ChangeDetector.LocalDetectChanges(InternalEntityEntry entry)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.ChangeDetector.DetectChanges(IStateManager stateManager)
at Microsoft.EntityFrameworkCore.ChangeTracking.ChangeTracker.DetectChanges()
at Microsoft.EntityFrameworkCore.DbContext.TryDetectChanges()
at Microsoft.EntityFrameworkCore.DbContext.SaveChangesAsync(Boolean acceptAllChangesOnSuccess, CancellationToken cancellationToken)
at error_repro.ReproTest.Test() in C:\Users\richard.dungal\Documents\Dev\richard1927\ef-child-to-parent-error\error-repro\ReproTest.cs:line 43
Verbose output
PS C:\Users\richard.dungal\Documents\Dev\richard1927\ef-child-to-parent-error> dotnet test -l "console;verbosity=detailed"
Restore complete (0.5s)
error-repro succeeded with 1 warning(s) (3.9s) → error-repro\bin\Debug\net9.0\error-repro.dll
C:\Users\richard.dungal\Documents\Dev\richard1927\ef-child-to-parent-error\error-repro\Child.cs(7,19): warning CS8618: Non-nullable property 'Name' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
A total of 1 test files matched the specified pattern.
C:\Users\richard.dungal\Documents\Dev\richard1927\ef-child-to-parent-error\error-repro\bin\Debug\net9.0\error-repro.dll
[xUnit.net 00:00:00.00] xUnit.net VSTest Adapter v2.8.2+699d445a1a (64-bit .NET 9.0.4)
[xUnit.net 00:00:00.00] xUnit.net VSTest Adapter v2.8.2+699d445a1a (64-bit .NET 9.0.4)
[xUnit.net 00:00:00.06] Discovering: error-repro
[xUnit.net 00:00:00.06] Discovering: error-repro
[xUnit.net 00:00:00.09] Discovered: error-repro
[xUnit.net 00:00:00.09] Discovered: error-repro
[xUnit.net 00:00:00.09] Starting: error-repro
[xUnit.net 00:00:00.09] Starting: error-repro
[testcontainers.org 00:00:00.09] Connected to Docker:
[testcontainers.org 00:00:00.09] Connected to Docker:
Host: npipe://./pipe/docker_engine
Host: npipe://./pipe/docker_engine
Server Version: 28.0.1
Server Version: 28.0.1
Kernel Version: 5.15.167.4-microsoft-standard-WSL2
Kernel Version: 5.15.167.4-microsoft-standard-WSL2
API Version: 1.48
API Version: 1.48
Operating System: Docker Desktop
Operating System: Docker Desktop
Total Memory: 31.19 GB
Total Memory: 31.19 GB
Labels:
Labels:
com.docker.desktop.address=npipe://\\.\pipe\docker_cli
com.docker.desktop.address=npipe://\\.\pipe\docker_cli
[testcontainers.org 00:00:00.29] Docker container f5819f12d5e2 created
[testcontainers.org 00:00:00.29] Docker container f5819f12d5e2 created
[testcontainers.org 00:00:00.34] Start Docker container f5819f12d5e2
[testcontainers.org 00:00:00.34] Start Docker container f5819f12d5e2
[testcontainers.org 00:00:01.61] Wait for Docker container f5819f12d5e2 to complete readiness checks
[testcontainers.org 00:00:01.61] Wait for Docker container f5819f12d5e2 to complete readiness checks
[testcontainers.org 00:00:01.62] Docker container f5819f12d5e2 ready
[testcontainers.org 00:00:01.62] Docker container f5819f12d5e2 ready
[testcontainers.org 00:00:01.86] Docker container a27a2dbd6fba created
[testcontainers.org 00:00:01.86] Docker container a27a2dbd6fba created
[testcontainers.org 00:00:01.88] Start Docker container a27a2dbd6fba
[testcontainers.org 00:00:01.88] Start Docker container a27a2dbd6fba
[testcontainers.org 00:00:03.12] Wait for Docker container a27a2dbd6fba to complete readiness checks
[testcontainers.org 00:00:03.12] Wait for Docker container a27a2dbd6fba to complete readiness checks
[testcontainers.org 00:00:03.14] Execute "/bin/sh -c find /opt/mssql-tools*/bin/sqlcmd -type f -print -quit" at Docker container a27a2dbd6fba
[testcontainers.org 00:00:03.14] Execute "/bin/sh -c find /opt/mssql-tools*/bin/sqlcmd -type f -print -quit" at Docker container a27a2dbd6fba
[testcontainers.org 00:00:03.23] Execute "/opt/mssql-tools18/bin/sqlcmd -C -Q SELECT 1;" at Docker container a27a2dbd6fba
[testcontainers.org 00:00:03.23] Execute "/opt/mssql-tools18/bin/sqlcmd -C -Q SELECT 1;" at Docker container a27a2dbd6fba
[testcontainers.org 00:00:11.83] Execute "/opt/mssql-tools18/bin/sqlcmd -C -Q SELECT 1;" at Docker container a27a2dbd6fba
[testcontainers.org 00:00:11.83] Execute "/opt/mssql-tools18/bin/sqlcmd -C -Q SELECT 1;" at Docker container a27a2dbd6fba
[testcontainers.org 00:00:11.90] Docker container a27a2dbd6fba ready
[testcontainers.org 00:00:11.90] Docker container a27a2dbd6fba ready
[xUnit.net 00:00:15.62] error_repro.ReproTest.Test [FAIL]
[xUnit.net 00:00:15.62] error_repro.ReproTest.Test [FAIL]
[xUnit.net 00:00:15.63] System.InvalidOperationException : The association between entity types 'Parent' and 'Child' has been severed, but the relationship is either marked as required or is implicitly required because the foreign key is not nullable. If the dependent/child entity should be deleted when a required relationship is severed, configure the relationship to use cascade deletes. Consider using 'DbContextOptionsBuilder.EnableSensitiveDataLogging' to see the key values.
[xUnit.net 00:00:15.63] System.InvalidOperationException : The association between entity types 'Parent' and 'Child' has been severed, but the relationship is either marked as required or is implicitly required because the foreign key is not nullable. If the dependent/child entity should be deleted when a required relationship is severed, configure the relationship to use cascade deletes. Consider using 'DbContextOptionsBuilder.EnableSensitiveDataLogging' to see the key values.
[xUnit.net 00:00:15.63] Stack Trace:
[xUnit.net 00:00:15.63] Stack Trace:
[xUnit.net 00:00:15.63] at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry.HandleConceptualNulls(Boolean sensitiveLoggingEnabled, Boolean force, Boolean isCascadeDelete)
[xUnit.net 00:00:15.63] at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry.HandleConceptualNulls(Boolean sensitiveLoggingEnabled, Boolean force, Boolean isCascadeDelete)
[xUnit.net 00:00:15.63] at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry.HandleNullForeignKey(IProperty property, Boolean setModified, Boolean isCascadeDelete)
[xUnit.net 00:00:15.63] at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry.HandleNullForeignKey(IProperty property, Boolean setModified, Boolean isCascadeDelete)
[xUnit.net 00:00:15.63] at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry.SetProperty(IPropertyBase propertyBase, Object value, Boolean isMaterialization, Boolean setModified, Boolean isCascadeDelete, CurrentValueType valueType)
[xUnit.net 00:00:15.63] at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry.SetProperty(IPropertyBase propertyBase, Object value, Boolean isMaterialization, Boolean setModified, Boolean isCascadeDelete, CurrentValueType valueType)
[xUnit.net 00:00:15.63] at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry.SetProperty(IPropertyBase propertyBase, Object value, Boolean isMaterialization, Boolean setModified, Boolean isCascadeDelete)
[xUnit.net 00:00:15.63] at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry.SetProperty(IPropertyBase propertyBase, Object value, Boolean isMaterialization, Boolean setModified, Boolean isCascadeDelete)
[xUnit.net 00:00:15.63] at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry.set_Item(IPropertyBase propertyBase, Object value)
[xUnit.net 00:00:15.63] at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry.set_Item(IPropertyBase propertyBase, Object value)
[xUnit.net 00:00:15.63] at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.NavigationFixer.ConditionallyNullForeignKeyProperties(InternalEntityEntry dependentEntry, InternalEntityEntry principalEntry, IForeignKey foreignKey)
[xUnit.net 00:00:15.63] at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.NavigationFixer.ConditionallyNullForeignKeyProperties(InternalEntityEntry dependentEntry, InternalEntityEntry principalEntry, IForeignKey foreignKey)
[xUnit.net 00:00:15.63] at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.NavigationFixer.NavigationCollectionChanged(InternalEntityEntry entry, INavigationBase navigationBase, IEnumerable`1 added, IEnumerable`1 removed)
[xUnit.net 00:00:15.63] at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.NavigationFixer.NavigationCollectionChanged(InternalEntityEntry entry, INavigationBase navigationBase, IEnumerable`1 added, IEnumerable`1 removed)
[xUnit.net 00:00:15.63] at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntryNotifier.NavigationCollectionChanged(InternalEntityEntry entry, INavigationBase navigationBase, IEnumerable`1 added, IEnumerable`1 removed)
[xUnit.net 00:00:15.63] at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntryNotifier.NavigationCollectionChanged(InternalEntityEntry entry, INavigationBase navigationBase, IEnumerable`1 added, IEnumerable`1 removed)
[xUnit.net 00:00:15.63] at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.ChangeDetector.DetectNavigationChange(InternalEntityEntry entry, INavigationBase navigationBase)
[xUnit.net 00:00:15.63] at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.ChangeDetector.DetectNavigationChange(InternalEntityEntry entry, INavigationBase navigationBase)
[xUnit.net 00:00:15.63] at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.ChangeDetector.LocalDetectChanges(InternalEntityEntry entry)
[xUnit.net 00:00:15.63] at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.ChangeDetector.LocalDetectChanges(InternalEntityEntry entry)
[xUnit.net 00:00:15.63] at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.ChangeDetector.DetectChanges(IStateManager stateManager)
[xUnit.net 00:00:15.63] at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.ChangeDetector.DetectChanges(IStateManager stateManager)
[xUnit.net 00:00:15.63] at Microsoft.EntityFrameworkCore.ChangeTracking.ChangeTracker.DetectChanges()
[xUnit.net 00:00:15.63] at Microsoft.EntityFrameworkCore.ChangeTracking.ChangeTracker.DetectChanges()
[xUnit.net 00:00:15.63] at Microsoft.EntityFrameworkCore.DbContext.TryDetectChanges()
[xUnit.net 00:00:15.63] at Microsoft.EntityFrameworkCore.DbContext.TryDetectChanges()
[xUnit.net 00:00:15.63] at Microsoft.EntityFrameworkCore.DbContext.SaveChangesAsync(Boolean acceptAllChangesOnSuccess, CancellationToken cancellationToken)
[xUnit.net 00:00:15.63] at Microsoft.EntityFrameworkCore.DbContext.SaveChangesAsync(Boolean acceptAllChangesOnSuccess, CancellationToken cancellationToken)
[xUnit.net 00:00:15.64] C:\Users\richard.dungal\Documents\Dev\richard1927\ef-child-to-parent-error\error-repro\ReproTest.cs(43,0): at error_repro.ReproTest.Test()
[xUnit.net 00:00:15.64] C:\Users\richard.dungal\Documents\Dev\richard1927\ef-child-to-parent-error\error-repro\ReproTest.cs(43,0): at error_repro.ReproTest.Test()
[xUnit.net 00:00:15.64] --- End of stack trace from previous location ---
[xUnit.net 00:00:15.64] --- End of stack trace from previous location ---
[testcontainers.org 00:00:15.42] Delete Docker container a27a2dbd6fba
[testcontainers.org 00:00:15.42] Delete Docker container a27a2dbd6fba
Failed error_repro.ReproTest.Test [2 s]
Error Message:
System.InvalidOperationException : The association between entity types 'Parent' and 'Child' has been severed, but the relationship is either marked as required or is implicitly required because the foreign key is not nullable. If the dependent/child entity should be deleted when a required relationship is severed, configure the relationship to use cascade deletes. Consider using 'DbContextOptionsBuilder.EnableSensitiveDataLogging' to see the key values.
Stack Trace:
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry.HandleConceptualNulls(Boolean sensitiveLoggingEnabled, Boolean force, Boolean isCascadeDelete)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry.HandleNullForeignKey(IProperty property, Boolean setModified, Boolean isCascadeDelete)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry.SetProperty(IPropertyBase propertyBase, Object value, Boolean isMaterialization, Boolean setModified, Boolean isCascadeDelete, CurrentValueType valueType)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry.SetProperty(IPropertyBase propertyBase, Object value, Boolean isMaterialization, Boolean setModified, Boolean isCascadeDelete)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry.set_Item(IPropertyBase propertyBase, Object value)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.NavigationFixer.ConditionallyNullForeignKeyProperties(InternalEntityEntry dependentEntry, InternalEntityEntry principalEntry, IForeignKey foreignKey)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.NavigationFixer.NavigationCollectionChanged(InternalEntityEntry entry, INavigationBase navigationBase, IEnumerable`1 added, IEnumerable`1 removed)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntryNotifier.NavigationCollectionChanged(InternalEntityEntry entry, INavigationBase navigationBase, IEnumerable`1 added, IEnumerable`1 removed)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.ChangeDetector.DetectNavigationChange(InternalEntityEntry entry, INavigationBase navigationBase)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.ChangeDetector.LocalDetectChanges(InternalEntityEntry entry)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.ChangeDetector.DetectChanges(IStateManager stateManager)
at Microsoft.EntityFrameworkCore.ChangeTracking.ChangeTracker.DetectChanges()
at Microsoft.EntityFrameworkCore.DbContext.TryDetectChanges()
at Microsoft.EntityFrameworkCore.DbContext.SaveChangesAsync(Boolean acceptAllChangesOnSuccess, CancellationToken cancellationToken)
at error_repro.ReproTest.Test() in C:\Users\richard.dungal\Documents\Dev\richard1927\ef-child-to-parent-error\error-repro\ReproTest.cs:line 43
--- End of stack trace from previous location ---
[xUnit.net 00:00:16.53] Finished: error-repro
[xUnit.net 00:00:16.53] Finished: error-repro
Test Run Failed.
Total tests: 1
Failed: 1
Total time: 17.2405 Seconds
error-repro test failed with 1 error(s) (17.9s)
C:\Users\richard.dungal\Documents\Dev\richard1927\ef-child-to-parent-error\error-repro\ReproTest.cs(43): error TESTERROR:
error_repro.ReproTest.Test (2s 851ms): Error Message: System.InvalidOperationException : The association between e
ntity types 'Parent' and 'Child' has been severed, but the relationship is either marked as required or is implici
tly required because the foreign key is not nullable. If the dependent/child entity should be deleted when a requi
red relationship is severed, configure the relationship to use cascade deletes. Consider using 'DbContextOptionsBu
ilder.EnableSensitiveDataLogging' to see the key values.
Stack Trace:
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry.HandleConceptualNulls(Boolean sens
itiveLoggingEnabled, Boolean force, Boolean isCascadeDelete)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry.HandleNullForeignKey(IProperty pro
perty, Boolean setModified, Boolean isCascadeDelete)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry.SetProperty(IPropertyBase property
Base, Object value, Boolean isMaterialization, Boolean setModified, Boolean isCascadeDelete, CurrentValueType valu
eType)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry.SetProperty(IPropertyBase property
Base, Object value, Boolean isMaterialization, Boolean setModified, Boolean isCascadeDelete)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry.set_Item(IPropertyBase propertyBas
e, Object value)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.NavigationFixer.ConditionallyNullForeignKeyProperties(
InternalEntityEntry dependentEntry, InternalEntityEntry principalEntry, IForeignKey foreignKey)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.NavigationFixer.NavigationCollectionChanged(InternalEn
tityEntry entry, INavigationBase navigationBase, IEnumerable`1 added, IEnumerable`1 removed)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntryNotifier.NavigationCollectionChange
d(InternalEntityEntry entry, INavigationBase navigationBase, IEnumerable`1 added, IEnumerable`1 removed)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.ChangeDetector.DetectNavigationChange(InternalEntityEn
try entry, INavigationBase navigationBase)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.ChangeDetector.LocalDetectChanges(InternalEntityEntry
entry)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.ChangeDetector.DetectChanges(IStateManager stateManage
r)
at Microsoft.EntityFrameworkCore.ChangeTracking.ChangeTracker.DetectChanges()
at Microsoft.EntityFrameworkCore.DbContext.TryDetectChanges()
at Microsoft.EntityFrameworkCore.DbContext.SaveChangesAsync(Boolean acceptAllChangesOnSuccess, CancellationToke
n cancellationToken)
at error_repro.ReproTest.Test() in C:\Users\richard.dungal\Documents\Dev\richard1927\ef-child-to-parent-error\e
rror-repro\ReproTest.cs:line 43
--- End of stack trace from previous location ---
Test summary: total: 1, failed: 1, succeeded: 0, skipped: 0, duration: 17.8s
Build failed with 1 error(s) and 1 warning(s) in 22.6s
EF Core version
9.0.4
Database provider
Microsoft.EntityFrameworkCore.SqlServer
Target framework
.NET 9.0
Operating system
Windows 11
IDE
JetBrains Rider 2024.3.6