Repository: dotnet/efcore
File: test/EFCore.Specification.Tests/ComplexTypesTrackingTestBase.cs (C#)

Code before:
        await ExecuteWithStrategyInTransactionAsync(
            async context =>
            {
                var pub = createPub(context);
                context.Add(pub);
                _ = async ? await context.SaveChangesAsync() : context.SaveChanges();
            },
            async context =>
            {
                var pub = async
                    ? await context.Set<TEntity>().Where(e => EF.Property<string>(e, "Name") == "The FBI").FirstAsync()
                    : context.Set<TEntity>().Where(e => EF.Property<string>(e, "Name") == "The FBI").First();
                var entry = context.Entry(pub);

                // Set to Deleted state (soft delete pattern)
                entry.State = EntityState.Deleted;
                Assert.Equal(EntityState.Deleted, entry.State);

                // Change to target state - this should not throw an exception
                entry.State = newState;
                Assert.Equal(newState, entry.State);

                // Verify the complex collection is still accessible
                var activitiesEntry = entry.ComplexCollection("Activities");
                Assert.NotNull(activitiesEntry);
                var activitiesValue = entry.Property("Activities").CurrentValue;
                Assert.Equal(2, ((System.Collections.IList)activitiesValue!).Count);
            });
    }

    [ConditionalTheory(Skip = "Issue #31411"), InlineData(EntityState.Added, false), InlineData(EntityState.Added, true),
     InlineData(EntityState.Unchanged, false), InlineData(EntityState.Unchanged, true), InlineData(EntityState.Modified, false),
     InlineData(EntityState.Modified, true), InlineData(EntityState.Deleted, false), InlineData(EntityState.Deleted, true)]
    public virtual Task Can_track_entity_with_complex_struct_collections(EntityState state, bool async)
        => TrackAndSaveTest(state, async, CreatePubWithStructCollections);

    [ConditionalTheory(Skip = "Issue #31411"), InlineData(false), InlineData(true)]
    public virtual void Can_mark_complex_struct_collection_properties_modified(bool trackFromQuery)
        => MarkModifiedTest(trackFromQuery, CreatePubWithStructCollections);

    [ConditionalTheory(Skip = "Issue #31411"), InlineData(false), InlineData(true)]
    public virtual void Can_read_original_values_for_properties_of_complex_struct_collections(bool trackFromQuery)
        => ReadOriginalValuesTest(trackFromQuery, CreatePubWithStructCollections);

    [ConditionalTheory(Skip = "Issue #31411"), InlineData(false), InlineData(true)]
    public virtual void Can_write_original_values_for_properties_of_complex_struct_collections(bool trackFromQuery)
        => WriteOriginalValuesTest(trackFromQuery, CreatePubWithStructCollections);

    [ConditionalTheory(Skip = "Issue #31621"), InlineData(EntityState.Added, false), InlineData(EntityState.Added, true),
     InlineData(EntityState.Unchanged, false), InlineData(EntityState.Unchanged, true), InlineData(EntityState.Modified, false),
     InlineData(EntityState.Modified, true), InlineData(EntityState.Deleted, false), InlineData(EntityState.Deleted, true)]

Review comment (suggestion):
@copilot 

```suggestion
                var activitiesValue = activitiesEntry.CurrentValue;
```

Code after:
    {
        await ExecuteWithStrategyInTransactionAsync(
            async context =>
            {
                var pub = createPub(context);
                context.Add(pub);
                _ = async ? await context.SaveChangesAsync() : context.SaveChanges();
            },
            async context =>
            {
                var pub = async
                    ? await context.Set<TEntity>().Where(e => EF.Property<string>(e, "Name") == "The FBI").FirstAsync()
                    : context.Set<TEntity>().Where(e => EF.Property<string>(e, "Name") == "The FBI").First();
                var entry = context.Entry(pub);

                entry.State = EntityState.Deleted;

                // Change to target state - this should not throw an exception
                entry.State = newState;
                Assert.Equal(newState, entry.State);

                // Verify the complex collection is still accessible
                var activitiesEntry = entry.ComplexCollection("Activities");
                Assert.NotNull(activitiesEntry);
                var activitiesValue = activitiesEntry.CurrentValue;
                Assert.Equal(2, ((System.Collections.IList)activitiesValue!).Count);
            });
    }

    [ConditionalTheory(Skip = "Issue #31411"), InlineData(EntityState.Added, false), InlineData(EntityState.Added, true),
     InlineData(EntityState.Unchanged, false), InlineData(EntityState.Unchanged, true), InlineData(EntityState.Modified, false),
     InlineData(EntityState.Modified, true), InlineData(EntityState.Deleted, false), InlineData(EntityState.Deleted, true)]
    public virtual Task Can_track_entity_with_complex_struct_collections(EntityState state, bool async)
        => TrackAndSaveTest(state, async, CreatePubWithStructCollections);

    [ConditionalTheory(Skip = "Issue #31411"), InlineData(false), InlineData(true)]
    public virtual void Can_mark_complex_struct_collection_properties_modified(bool trackFromQuery)
        => MarkModifiedTest(trackFromQuery, CreatePubWithStructCollections);

    [ConditionalTheory(Skip = "Issue #31411"), InlineData(false), InlineData(true)]
    public virtual void Can_read_original_values_for_properties_of_complex_struct_collections(bool trackFromQuery)
        => ReadOriginalValuesTest(trackFromQuery, CreatePubWithStructCollections);

    [ConditionalTheory(Skip = "Issue #31411"), InlineData(false), InlineData(true)]
    public virtual void Can_write_original_values_for_properties_of_complex_struct_collections(bool trackFromQuery)
        => WriteOriginalValuesTest(trackFromQuery, CreatePubWithStructCollections);

    [ConditionalTheory(Skip = "Issue #31621"), InlineData(EntityState.Added, false), InlineData(EntityState.Added, true),
     InlineData(EntityState.Unchanged, false), InlineData(EntityState.Unchanged, true), InlineData(EntityState.Modified, false),
     InlineData(EntityState.Modified, true), InlineData(EntityState.Deleted, false), InlineData(EntityState.Deleted, true)]
    public virtual Task Can_track_entity_with_complex_readonly_struct_collections(EntityState state, bool async)