Repository: dotnet/efcore
File: src/EFCore/ChangeTracking/PropertyValues.cs (C#)

Code before:
        AppContext.TryGetSwitch("Microsoft.EntityFrameworkCore.Issue37516", out var enabled37516) && enabled37516;

    private readonly IReadOnlyList<IComplexProperty> _complexCollectionProperties;
    private readonly IReadOnlyList<IComplexProperty>? _nullableComplexProperties;

    /// <summary>
    ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to
    ///     the same compatibility standards as public APIs. It may be changed or removed without notice in
    ///     any release. You should only use it directly in your code with extreme caution and knowing that
    ///     doing so can result in application failures when updating to a new Entity Framework Core release.
    /// </summary>
    [EntityFrameworkInternal]
    protected PropertyValues(InternalEntryBase internalEntry)
    {
        InternalEntry = internalEntry;

        var complexCollectionProperties = new List<IComplexProperty>();
        var nullableComplexProperties = UseOldBehavior37249 || UseOldBehavior37516 ? null : new List<IComplexProperty>();

        foreach (var complexProperty in internalEntry.StructuralType.GetFlattenedComplexProperties())
        {
            if (complexProperty.IsCollection)
            {
                complexCollectionProperties.Add(complexProperty);
            }
            else if (!UseOldBehavior37249 && !UseOldBehavior37516 && complexProperty.IsNullable && !complexProperty.IsShadowProperty())
            {
                nullableComplexProperties!.Add(complexProperty);
            }
        }

        _complexCollectionProperties = complexCollectionProperties;
        Check.DebugAssert(
            _complexCollectionProperties.Select((p, i) => p.GetIndex() == i).All(e => e),
            "Complex collection properties indices are not sequential.");
        _nullableComplexProperties = nullableComplexProperties?.Count > 0 ? nullableComplexProperties : null;
    }

    /// <summary>
    ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to
    ///     the same compatibility standards as public APIs. It may be changed or removed without notice in
    ///     any release. You should only use it directly in your code with extreme caution and knowing that
    ///     doing so can result in application failures when updating to a new Entity Framework Core release.
    /// </summary>
    [EntityFrameworkInternal]
    protected virtual InternalEntryBase InternalEntry { [DebuggerStepThrough] get; }

    /// <summary>
    ///     Creates an instance of the entity type and sets all its properties using the
    ///     values from this object.
    /// </summary>

Review comment (suggestion):
@copilot The `UseOldBehavior37516` switch shouldn't be checked here, but in EntryPropertyValues and ArrayPropertyValues where the new fix is being added

Code after:
    private readonly IReadOnlyList<IComplexProperty>? _nullableComplexProperties;

    /// <summary>
    ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to
    ///     the same compatibility standards as public APIs. It may be changed or removed without notice in
    ///     any release. You should only use it directly in your code with extreme caution and knowing that
    ///     doing so can result in application failures when updating to a new Entity Framework Core release.
    /// </summary>
    [EntityFrameworkInternal]
    protected PropertyValues(InternalEntryBase internalEntry)
    {
        InternalEntry = internalEntry;

        var complexCollectionProperties = new List<IComplexProperty>();
        var nullableComplexProperties = UseOldBehavior37249 ? null : new List<IComplexProperty>();

        foreach (var complexProperty in internalEntry.StructuralType.GetFlattenedComplexProperties())
        {
            if (complexProperty.IsCollection)
            {
                complexCollectionProperties.Add(complexProperty);
            }
            else if (!UseOldBehavior37249 && complexProperty.IsNullable && !complexProperty.IsShadowProperty())
            {
                nullableComplexProperties!.Add(complexProperty);
            }
        }

        _complexCollectionProperties = complexCollectionProperties;
        Check.DebugAssert(
            _complexCollectionProperties.Select((p, i) => p.GetIndex() == i).All(e => e),
            "Complex collection properties indices are not sequential.");
        _nullableComplexProperties = nullableComplexProperties?.Count > 0 ? nullableComplexProperties : null;
    }

    /// <summary>
    ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to
    ///     the same compatibility standards as public APIs. It may be changed or removed without notice in
    ///     any release. You should only use it directly in your code with extreme caution and knowing that
    ///     doing so can result in application failures when updating to a new Entity Framework Core release.
    /// </summary>
    [EntityFrameworkInternal]
    protected virtual InternalEntryBase InternalEntry { [DebuggerStepThrough] get; }

    /// <summary>
    ///     Creates an instance of the entity type and sets all its properties using the
    ///     values from this object.
    /// </summary>
    /// <remarks>
    ///     See <see href="https://aka.ms/efcore-docs-entity-entries">Accessing tracked entities in EF Core</see> for more information and
    ///     examples.