diff --git a/src/EFCore/Metadata/Conventions/BackingFieldConvention.cs b/src/EFCore/Metadata/Conventions/BackingFieldConvention.cs index e68c47f3bb6..3042da396a8 100644 --- a/src/EFCore/Metadata/Conventions/BackingFieldConvention.cs +++ b/src/EFCore/Metadata/Conventions/BackingFieldConvention.cs @@ -82,7 +82,7 @@ public virtual void ProcessModelFinalizing( throw new InvalidOperationException((string?)ambiguousField.Value); } - property.RemoveAnnotation(CoreAnnotationNames.AmbiguousField); + property.Builder.HasNoAnnotation(CoreAnnotationNames.AmbiguousField); } } } diff --git a/test/EFCore.Specification.Tests/ApiConsistencyTestBase.cs b/test/EFCore.Specification.Tests/ApiConsistencyTestBase.cs index 0cdd96c7052..0eaa66b1722 100644 --- a/test/EFCore.Specification.Tests/ApiConsistencyTestBase.cs +++ b/test/EFCore.Specification.Tests/ApiConsistencyTestBase.cs @@ -216,25 +216,25 @@ public void Metadata_types_have_expected_structure() private string ValidateMetadata(KeyValuePair types) { - var readonlyType = types.Key; + var readOnlyType = types.Key; var (mutableType, conventionType, conventionBuilderType, runtimeType) = types.Value; - if (!readonlyType.IsAssignableFrom(mutableType)) + if (!readOnlyType.IsAssignableFrom(mutableType)) { - return $"{mutableType.Name} should derive from {readonlyType.Name}"; + return $"{mutableType.Name} should derive from {readOnlyType.Name}"; } - if (!readonlyType.IsAssignableFrom(conventionType)) + if (!readOnlyType.IsAssignableFrom(conventionType)) { - return $"{mutableType.Name} should derive from {readonlyType.Name}"; + return $"{mutableType.Name} should derive from {readOnlyType.Name}"; } - if (typeof(IAnnotation) != readonlyType - && typeof(IReadOnlyAnnotatable) != readonlyType) + if (readOnlyType != typeof(IAnnotation) + && readOnlyType != typeof(IReadOnlyAnnotatable)) { - if (!typeof(IReadOnlyAnnotatable).IsAssignableFrom(readonlyType)) + if (!typeof(IReadOnlyAnnotatable).IsAssignableFrom(readOnlyType)) { - return $"{readonlyType.Name} should derive from IAnnotatable"; + return $"{readOnlyType.Name} should derive from IReadOnlyAnnotatable"; } if (!typeof(IMutableAnnotatable).IsAssignableFrom(mutableType)) @@ -246,6 +246,11 @@ private string ValidateMetadata(KeyValuePair typ { return $"{conventionType.Name} should derive from IConventionAnnotatable"; } + + if (!typeof(IAnnotatable).IsAssignableFrom(runtimeType)) + { + return $"{runtimeType.Name} should derive from IAnnotatable"; + } if (conventionBuilderType != null && !typeof(IConventionAnnotatableBuilder).IsAssignableFrom(conventionBuilderType)) @@ -253,9 +258,9 @@ private string ValidateMetadata(KeyValuePair typ return $"{conventionBuilderType.Name} should derive from IConventionAnnotatableBuilder"; } - if (readonlyType.Namespace != MetadataNamespace) + if (readOnlyType.Namespace != MetadataNamespace) { - return $"{readonlyType.Name} is expected to be in the {MetadataNamespace} namespace"; + return $"{readOnlyType.Name} is expected to be in the {MetadataNamespace} namespace"; } if (mutableType.Namespace != MetadataNamespace) @@ -268,6 +273,11 @@ private string ValidateMetadata(KeyValuePair typ return $"{conventionType.Name} is expected to be in the {MetadataNamespace} namespace"; } + if (runtimeType.Namespace != MetadataNamespace) + { + return $"{runtimeType.Name} is expected to be in the {MetadataNamespace} namespace"; + } + if (conventionBuilderType != null && conventionBuilderType.Namespace != MetadataBuilderNamespace) { diff --git a/test/EFCore.Tests/ModelBuilding/ManyToManyTestBase.cs b/test/EFCore.Tests/ModelBuilding/ManyToManyTestBase.cs index bb419c1e078..258546f93c3 100644 --- a/test/EFCore.Tests/ModelBuilding/ManyToManyTestBase.cs +++ b/test/EFCore.Tests/ModelBuilding/ManyToManyTestBase.cs @@ -710,6 +710,8 @@ public virtual void Overrides_ForeignKeyAttribute() var joinEntityType = categoryFk.DeclaringEntityType; Assert.Equal(2, joinEntityType.GetForeignKeys().Count()); + Assert.Equal(new[] {"CategoryWithAttributeId", "ProductWithAttributeId"}, + joinEntityType.FindPrimaryKey()!.Properties.Select(p => p.Name)); } protected class ProductWithAttribute