diff --git a/src/EFCore/Metadata/IReadOnlyComplexProperty.cs b/src/EFCore/Metadata/IReadOnlyComplexProperty.cs index 235453e26bb..ef056484ca3 100644 --- a/src/EFCore/Metadata/IReadOnlyComplexProperty.cs +++ b/src/EFCore/Metadata/IReadOnlyComplexProperty.cs @@ -91,7 +91,7 @@ string ToDebugString(MetadataDebugStringOptions options = MetadataDebugStringOpt } if ((options & MetadataDebugStringOptions.IncludePropertyIndexes) != 0 - && ((AnnotatableBase)this).IsReadOnly) + && (this is RuntimeAnnotatableBase || this is AnnotatableBase { IsReadOnly: true })) { var indexes = ((IProperty)this).GetPropertyIndexes(); builder.Append(' ').Append(indexes.Index); diff --git a/src/EFCore/Metadata/IReadOnlyNavigation.cs b/src/EFCore/Metadata/IReadOnlyNavigation.cs index 5dd9bc89ae2..eca258ab435 100644 --- a/src/EFCore/Metadata/IReadOnlyNavigation.cs +++ b/src/EFCore/Metadata/IReadOnlyNavigation.cs @@ -165,7 +165,7 @@ string ToDebugString(MetadataDebugStringOptions options = MetadataDebugStringOpt } if ((options & MetadataDebugStringOptions.IncludePropertyIndexes) != 0 - && ((AnnotatableBase)this).IsReadOnly) + && (this is RuntimeAnnotatableBase || this is AnnotatableBase { IsReadOnly: true })) { var indexes = ((INavigation)this).GetPropertyIndexes(); builder.Append(' ').Append(indexes.Index); diff --git a/src/EFCore/Metadata/IReadOnlyProperty.cs b/src/EFCore/Metadata/IReadOnlyProperty.cs index f8a80655c9f..be9a4c06802 100644 --- a/src/EFCore/Metadata/IReadOnlyProperty.cs +++ b/src/EFCore/Metadata/IReadOnlyProperty.cs @@ -433,7 +433,7 @@ string ToDebugString(MetadataDebugStringOptions options = MetadataDebugStringOpt } if ((options & MetadataDebugStringOptions.IncludePropertyIndexes) != 0 - && ((AnnotatableBase)this).IsReadOnly) + && (this is RuntimeAnnotatableBase || this is AnnotatableBase { IsReadOnly: true })) { var indexes = ((IProperty)this).GetPropertyIndexes(); builder.Append(' ').Append(indexes.Index); diff --git a/src/EFCore/Metadata/IReadOnlySkipNavigation.cs b/src/EFCore/Metadata/IReadOnlySkipNavigation.cs index d7017c74085..ffe835e8041 100644 --- a/src/EFCore/Metadata/IReadOnlySkipNavigation.cs +++ b/src/EFCore/Metadata/IReadOnlySkipNavigation.cs @@ -99,7 +99,7 @@ string ToDebugString(MetadataDebugStringOptions options = MetadataDebugStringOpt } if ((options & MetadataDebugStringOptions.IncludePropertyIndexes) != 0 - && ((AnnotatableBase)this).IsReadOnly) + && (this is RuntimeAnnotatableBase || this is AnnotatableBase { IsReadOnly: true })) { var indexes = ((ISkipNavigation)this).GetPropertyIndexes(); builder.Append(' ').Append(indexes.Index);