From 3e46934bc99fc2e4fe519f6fca747df9e6abb45a Mon Sep 17 00:00:00 2001 From: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com> Date: Sun, 15 Nov 2026 02:54:11 +0000 Subject: [PATCH 1/5] Initial plan From ec14e577672f6eac02eccc220d45055f2ab36a27 Mon Sep 17 00:00:00 2001 From: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com> Date: Sun, 15 Nov 2026 03:00:22 +0000 Subject: [PATCH 2/5] Add regression test for shared TPH complex property updates Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> --- .../Update/NonSharedModelUpdatesTestBase.cs | 107 ++++++++++++++++++ 1 file changed, 107 insertions(+) diff --git a/test/EFCore.Relational.Specification.Tests/Update/NonSharedModelUpdatesTestBase.cs b/test/EFCore.Relational.Specification.Tests/Update/NonSharedModelUpdatesTestBase.cs index 66cc126de82..3b9d5b6f7ff 100644 --- a/test/EFCore.Relational.Specification.Tests/Update/NonSharedModelUpdatesTestBase.cs +++ b/test/EFCore.Relational.Specification.Tests/Update/NonSharedModelUpdatesTestBase.cs @@ -11,6 +11,113 @@ public abstract class NonSharedModelUpdatesTestBase(NonSharedFixture fixture) protected override string NonSharedStoreName => "NonSharedModelUpdatesTestBase"; + [Theory, MemberData(nameof(IsAsyncData))] // Issue #39596 + public virtual async Task Optional_complex_properties_on_sibling_types_sharing_columns_can_be_set_to_null(bool async) + { + var contextFactory = await InitializeNonSharedTest( + onModelCreating: mb => + { + mb.Entity().HasDiscriminator("Discriminator") + .HasValue(0) + .HasValue(1); + mb.Entity().ComplexProperty(e => e.Value, ConfigureValue); + mb.Entity().ComplexProperty(e => e.Value, ConfigureValue); + mb.Entity().HasDiscriminator("Discriminator").HasValue(0); + mb.Entity().ComplexProperty(e => e.Value, ConfigureValue); + mb.Entity().ComplexProperty(e => e.Value, ConfigureValue); + }); + + await ExecuteWithStrategyInTransactionAsync( + contextFactory, + async context => + { + context.AddRange( + new SharedComplexA { Id = 1, Value = new ComplexValue(1, 2, 3) }, + new SharedComplexB { Id = 2, Value = new ComplexValue(4, 5, 6) }, + new SharedComplexB { Id = 3, Value = new ComplexValue(7, 8, 9) }, + new SingleComplex { Id = 4, Value = new ComplexValue(1, 2, 3) }, + new PlainComplex { Id = 5, Value = new ComplexValue(1, 2, 3) }); + await context.SaveChangesAsync(); + }, + async context => + { + (await context.Set().SingleAsync()).Value = null; + (await context.Set().SingleAsync(e => e.Id == 2)).Value = null; + (await context.Set().SingleAsync()).Value = null; + (await context.Set().SingleAsync()).Value = null; + + if (async) + { + await context.SaveChangesAsync(); + } + else + { + context.SaveChanges(); + } + }, + async context => + { + var a = await context.Set().SingleAsync(); + Assert.Null(a.Value); + Assert.Null((await context.Set().SingleAsync(e => e.Id == 2)).Value); + Assert.Equal(new ComplexValue(7, 8, 9), (await context.Set().SingleAsync(e => e.Id == 3)).Value); + Assert.Null((await context.Set().SingleAsync()).Value); + Assert.Null((await context.Set().SingleAsync()).Value); + + a.Value = new ComplexValue(10, 11, 12); + if (async) + { + await context.SaveChangesAsync(); + } + else + { + context.SaveChanges(); + } + }, + async context => + Assert.Equal(new ComplexValue(10, 11, 12), (await context.Set().SingleAsync()).Value)); + + static void ConfigureValue(ComplexPropertyBuilder builder) + { + builder.Property(e => e.Amount).HasColumnName("Amount"); + builder.Property(e => e.Error).HasColumnName("Error"); + builder.Property(e => e.Precision).HasColumnName("Precision"); + } + } + + private abstract class SharedComplexBase + { + public int Id { get; set; } + } + + private sealed class SharedComplexA : SharedComplexBase + { + public ComplexValue? Value { get; set; } + } + + private sealed class SharedComplexB : SharedComplexBase + { + public ComplexValue? Value { get; set; } + } + + private abstract class SingleComplexBase + { + public int Id { get; set; } + } + + private sealed class SingleComplex : SingleComplexBase + { + public ComplexValue? Value { get; set; } + } + + private sealed class PlainComplex + { + public int Id { get; set; } + public ComplexValue? Value { get; set; } + } + + private sealed record ComplexValue(decimal Amount, decimal Error, short Precision); + [Theory, MemberData(nameof(IsAsyncData))] // Issue #29356 public virtual async Task Principal_and_dependent_roundtrips_with_cycle_breaking(bool async) { From 6a1352d71eda902c9ffbc6da506e27c986f1f85d Mon Sep 17 00:00:00 2001 From: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com> Date: Sun, 15 Nov 2026 03:02:41 +0000 Subject: [PATCH 3/5] Preserve writes for null shared complex properties Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> --- .agents/skills/update-pipeline/SKILL.md | 2 ++ src/EFCore.Relational/Update/ModificationCommand.cs | 10 +++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/.agents/skills/update-pipeline/SKILL.md b/.agents/skills/update-pipeline/SKILL.md index 400f9a95aea..fe8a2ed2681 100644 --- a/.agents/skills/update-pipeline/SKILL.md +++ b/.agents/skills/update-pipeline/SKILL.md @@ -21,6 +21,8 @@ Converts tracked entity changes into database INSERT/UPDATE/DELETE commands duri → `BatchExecutor` executes all batches in a transaction → `StateManager.AcceptAllChanges()` +For shared columns, `ColumnValuePropagator.TryPropagate` returns `false` for the writing entry; a null complex property must not suppress that write. Only skip propagation into a null complex property after identifying the writer. + ## Concurrency Concurrency tokens → WHERE conditions on UPDATE/DELETE. `AffectedCountModificationCommandBatch` checks affected rows. Throws `DbUpdateConcurrencyException` on mismatch. diff --git a/src/EFCore.Relational/Update/ModificationCommand.cs b/src/EFCore.Relational/Update/ModificationCommand.cs index c73bacac841..068116476fb 100644 --- a/src/EFCore.Relational/Update/ModificationCommand.cs +++ b/src/EFCore.Relational/Update/ModificationCommand.cs @@ -1290,9 +1290,7 @@ public void RecordValue(IColumnMapping mapping, IUpdateEntry entry) public bool TryPropagate(IColumnMappingBase mapping, IUpdateEntry entry) { var property = mapping.Property; - if (!_write - || (property.DeclaringType is IComplexType complexType - && entry.GetCurrentValue(complexType.ComplexProperty) == null)) + if (!_write) { return true; } @@ -1310,6 +1308,12 @@ public bool TryPropagate(IColumnMappingBase mapping, IUpdateEntry entry) return false; } + if (property.DeclaringType is IComplexType complexType + && entry.GetCurrentValue(complexType.ComplexProperty) == null) + { + return true; + } + if ((property.GetAfterSaveBehavior() == PropertySaveBehavior.Save || entry.EntityState == EntityState.Added) && property.ValueGenerated != ValueGenerated.Never) From e27c0353307ddb81b3dff82984db5846090e55b3 Mon Sep 17 00:00:00 2001 From: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com> Date: Sun, 15 Nov 2026 05:56:11 +0000 Subject: [PATCH 4/5] Revert update pipeline skill changes Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> --- .agents/skills/update-pipeline/SKILL.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/.agents/skills/update-pipeline/SKILL.md b/.agents/skills/update-pipeline/SKILL.md index fe8a2ed2681..400f9a95aea 100644 --- a/.agents/skills/update-pipeline/SKILL.md +++ b/.agents/skills/update-pipeline/SKILL.md @@ -21,8 +21,6 @@ Converts tracked entity changes into database INSERT/UPDATE/DELETE commands duri → `BatchExecutor` executes all batches in a transaction → `StateManager.AcceptAllChanges()` -For shared columns, `ColumnValuePropagator.TryPropagate` returns `false` for the writing entry; a null complex property must not suppress that write. Only skip propagation into a null complex property after identifying the writer. - ## Concurrency Concurrency tokens → WHERE conditions on UPDATE/DELETE. `AffectedCountModificationCommandBatch` checks affected rows. Throws `DbUpdateConcurrencyException` on mismatch. From e246b736367641cceb998e5daf486fcc2b404325 Mon Sep 17 00:00:00 2001 From: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com> Date: Mon, 16 Nov 2026 17:43:01 +0000 Subject: [PATCH 5/5] Fix SQL Server decimal warning in regression test Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> --- .../Update/NonSharedModelUpdatesTestBase.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/test/EFCore.Relational.Specification.Tests/Update/NonSharedModelUpdatesTestBase.cs b/test/EFCore.Relational.Specification.Tests/Update/NonSharedModelUpdatesTestBase.cs index 3b9d5b6f7ff..04ad4fd00a2 100644 --- a/test/EFCore.Relational.Specification.Tests/Update/NonSharedModelUpdatesTestBase.cs +++ b/test/EFCore.Relational.Specification.Tests/Update/NonSharedModelUpdatesTestBase.cs @@ -20,10 +20,13 @@ public virtual async Task Optional_complex_properties_on_sibling_types_sharing_c mb.Entity().HasDiscriminator("Discriminator") .HasValue(0) .HasValue(1); + mb.Entity().Property(e => e.Id).ValueGeneratedNever(); mb.Entity().ComplexProperty(e => e.Value, ConfigureValue); mb.Entity().ComplexProperty(e => e.Value, ConfigureValue); mb.Entity().HasDiscriminator("Discriminator").HasValue(0); + mb.Entity().Property(e => e.Id).ValueGeneratedNever(); mb.Entity().ComplexProperty(e => e.Value, ConfigureValue); + mb.Entity().Property(e => e.Id).ValueGeneratedNever(); mb.Entity().ComplexProperty(e => e.Value, ConfigureValue); }); @@ -79,8 +82,8 @@ await ExecuteWithStrategyInTransactionAsync( static void ConfigureValue(ComplexPropertyBuilder builder) { - builder.Property(e => e.Amount).HasColumnName("Amount"); - builder.Property(e => e.Error).HasColumnName("Error"); + builder.Property(e => e.Amount).HasColumnName("Amount").HasPrecision(18, 2); + builder.Property(e => e.Error).HasColumnName("Error").HasPrecision(18, 2); builder.Property(e => e.Precision).HasColumnName("Precision"); } }