From 3952bcd381f64cd0d6cea35105e0967a8c525e8a Mon Sep 17 00:00:00 2001 From: Andriy Svyryd Date: Mon, 3 Nov 2025 13:43:11 -0800 Subject: [PATCH] Fix parameter type for ComplexCollection and ComplexProperty entry methods Fixes #37064 --- src/EFCore/ChangeTracking/ComplexElementEntry`.cs | 2 +- src/EFCore/ChangeTracking/ComplexPropertyEntry`.cs | 2 +- .../ChangeTracking/Internal/InternalComplexEntryTest.cs | 9 ++++++++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/EFCore/ChangeTracking/ComplexElementEntry`.cs b/src/EFCore/ChangeTracking/ComplexElementEntry`.cs index 01b51169e63..fc78ac03500 100644 --- a/src/EFCore/ChangeTracking/ComplexElementEntry`.cs +++ b/src/EFCore/ChangeTracking/ComplexElementEntry`.cs @@ -124,7 +124,7 @@ public virtual ComplexPropertyEntry ComplexProp /// /// An object that exposes change tracking information and operations for the given property. public virtual ComplexCollectionEntry ComplexCollection( - Expression?>> propertyExpression) + Expression?>> propertyExpression) where TElement : notnull { Check.NotNull(propertyExpression, nameof(propertyExpression)); diff --git a/src/EFCore/ChangeTracking/ComplexPropertyEntry`.cs b/src/EFCore/ChangeTracking/ComplexPropertyEntry`.cs index 0045f0a4c02..8b459f02ce6 100644 --- a/src/EFCore/ChangeTracking/ComplexPropertyEntry`.cs +++ b/src/EFCore/ChangeTracking/ComplexPropertyEntry`.cs @@ -117,7 +117,7 @@ public virtual ComplexPropertyEntry ComplexProp /// /// An object that exposes change tracking information and operations for the given property. public virtual ComplexCollectionEntry ComplexCollection( - Expression?>> propertyExpression) + Expression?>> propertyExpression) where TElement : notnull { Check.NotNull(propertyExpression, nameof(propertyExpression)); diff --git a/test/EFCore.Tests/ChangeTracking/Internal/InternalComplexEntryTest.cs b/test/EFCore.Tests/ChangeTracking/Internal/InternalComplexEntryTest.cs index ef361b1a753..3f500ae99d6 100644 --- a/test/EFCore.Tests/ChangeTracking/Internal/InternalComplexEntryTest.cs +++ b/test/EFCore.Tests/ChangeTracking/Internal/InternalComplexEntryTest.cs @@ -707,7 +707,7 @@ public void DetectChanges_detects_changes_in_nested_complex_collections() { Items = [ - new NestedItem { Name = "bar" }, + new NestedItem { Name = "bar1" }, new NestedItem { Name = "baz" }, new NestedItem { Name = "new-bar" } ] @@ -717,6 +717,13 @@ public void DetectChanges_detects_changes_in_nested_complex_collections() changeDetector.DetectChanges(stateManager); Assert.Equal(EntityState.Modified, entityEntry.EntityState); + + var nestedJson = new EntityEntry(entityEntry).ComplexProperty(b => b.NestedJson); + var items = nestedJson.ComplexCollection(j => j.Items); + Assert.Equal(3, items.CurrentValue!.Count); + Assert.Equal(EntityState.Modified, items[0].State); + Assert.Equal(EntityState.Unchanged, items[1].State); + Assert.Equal(EntityState.Added, items[2].State); } private static IModel CreateModel()