Repository: dotnet/efcore
File: src/EFCore.Design/Migrations/Internal/SnapshotModelProcessor.cs (C#)

Code before:

    private void ProcessComplexProperties(IReadOnlyTypeBase typeBase, string version)
    {
        foreach (var complexProperty in typeBase.GetComplexProperties())
        {
            ProcessElement(complexProperty, version);
            
            if (complexProperty is IMutableComplexProperty mutableComplexProperty)
            {
                UpdateComplexPropertyNullability(mutableComplexProperty, version);
            }

            ProcessComplexProperties(complexProperty.ComplexType, version);
        }
    }

    private static void UpdateComplexPropertyNullability(IMutableComplexProperty complexProperty, string version)
    {
        if (!IsPreEFCore10Version(version)
            || complexProperty is not ComplexProperty mutableComplexPropertyInternal)
        {
            return;
        }

        if (mutableComplexPropertyInternal.GetIsNullableConfigurationSource() == null
            && !complexProperty.ClrType.IsNullableType())
        {
            mutableComplexPropertyInternal.SetIsNullable(false, ConfigurationSource.Explicit);
        }
    }

    private static bool IsPreEFCore10Version(string version)
        => version.StartsWith("1.", StringComparison.Ordinal)
            || version.StartsWith("2.", StringComparison.Ordinal)
            || version.StartsWith("3.", StringComparison.Ordinal)
            || version.StartsWith("5.", StringComparison.Ordinal)
            || version.StartsWith("6.", StringComparison.Ordinal)
            || version.StartsWith("7.", StringComparison.Ordinal)
            || version.StartsWith("8.", StringComparison.Ordinal)
            || version.StartsWith("9.", StringComparison.Ordinal);

    private void ProcessElement(IReadOnlyAnnotatable? metadata, string version)
    {
        if (version.StartsWith("1.", StringComparison.Ordinal)
            && metadata is IMutableAnnotatable mutableMetadata)
        {
            foreach (var annotation in mutableMetadata.GetAnnotations().ToList())
            {
                var colon = annotation.Name.IndexOf(':');
                if (colon > 0)
                {

Review comment (suggestion):
@copilot Don't perform this check or cast to `ComplexProperty`, just use `complexProperty`

Code after:

    private void ProcessComplexProperties(IReadOnlyTypeBase typeBase, string version)
    {
        foreach (var complexProperty in typeBase.GetComplexProperties())
        {
            ProcessElement(complexProperty, version);
            
            if (complexProperty is IMutableComplexProperty mutableComplexProperty)
            {
                UpdateComplexPropertyNullability(mutableComplexProperty, version);
            }

            ProcessComplexProperties(complexProperty.ComplexType, version);
        }
    }

    private static void UpdateComplexPropertyNullability(IMutableComplexProperty complexProperty, string version)
    {
        if ((version.StartsWith("8.", StringComparison.Ordinal)
                || version.StartsWith("9.", StringComparison.Ordinal))
            && !complexProperty.ClrType.IsNullableType())
        {
            complexProperty.IsNullable = false;
        }
    }

    private void ProcessElement(IReadOnlyAnnotatable? metadata, string version)
    {
        if (version.StartsWith("1.", StringComparison.Ordinal)
            && metadata is IMutableAnnotatable mutableMetadata)
        {
            foreach (var annotation in mutableMetadata.GetAnnotations().ToList())
            {
                var colon = annotation.Name.IndexOf(':');
                if (colon > 0)
                {
                    var stripped = annotation.Name[colon..];
                    if (_relationalNames.Contains(stripped))
                    {
                        mutableMetadata.RemoveAnnotation(annotation.Name);
                        var relationalName = "Relational" + stripped;
                        var duplicate = mutableMetadata.FindAnnotation(relationalName);

                        if (duplicate == null)
                        {
                            mutableMetadata[relationalName] = annotation.Value;
                        }
                        else if (!Equals(duplicate.Value, annotation.Value))
                        {
                            _operationReporter.WriteWarning(
                                DesignStrings.MultipleAnnotationConflict(stripped[1..]));