From 9ad2086e0ecf08e18c997b68202bec4bf75caecd Mon Sep 17 00:00:00 2001 From: Shay Rojansky Date: Tue, 2 Jul 2019 00:03:49 +0200 Subject: [PATCH] Added conventions to ModelFinalizedConventions --- .../Infrastructure/ProviderConventionSetBuilder.cs | 5 ++++- src/EFCore/Metadata/Conventions/NonNullableConventionBase.cs | 3 +-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/EFCore/Metadata/Conventions/Infrastructure/ProviderConventionSetBuilder.cs b/src/EFCore/Metadata/Conventions/Infrastructure/ProviderConventionSetBuilder.cs index 5faed428dab..b6c4dfb4cf0 100644 --- a/src/EFCore/Metadata/Conventions/Infrastructure/ProviderConventionSetBuilder.cs +++ b/src/EFCore/Metadata/Conventions/Infrastructure/ProviderConventionSetBuilder.cs @@ -104,6 +104,7 @@ public virtual ConventionSet CreateConventionSet() var databaseGeneratedAttributeConvention = new DatabaseGeneratedAttributeConvention(Dependencies); var requiredPropertyAttributeConvention = new RequiredPropertyAttributeConvention(Dependencies); var nonNullableReferencePropertyConvention = new NonNullableReferencePropertyConvention(Dependencies); + var nonNullableNavigationConvention = new NonNullableNavigationConvention(Dependencies); var maxLengthAttributeConvention = new MaxLengthAttributeConvention(Dependencies); var stringLengthAttributeConvention = new StringLengthAttributeConvention(Dependencies); var timestampAttributeConvention = new TimestampAttributeConvention(Dependencies); @@ -172,10 +173,12 @@ public virtual ConventionSet CreateConventionSet() conventionSet.ModelFinalizedConventions.Add(foreignKeyPropertyDiscoveryConvention); conventionSet.ModelFinalizedConventions.Add(servicePropertyDiscoveryConvention); conventionSet.ModelFinalizedConventions.Add(new ValidatingConvention(Dependencies)); + conventionSet.ModelFinalizedConventions.Add(nonNullableReferencePropertyConvention); + conventionSet.ModelFinalizedConventions.Add(nonNullableNavigationConvention); conventionSet.NavigationAddedConventions.Add(backingFieldConvention); conventionSet.NavigationAddedConventions.Add(new RequiredNavigationAttributeConvention(Dependencies)); - conventionSet.NavigationAddedConventions.Add(new NonNullableNavigationConvention(Dependencies)); + conventionSet.NavigationAddedConventions.Add(nonNullableNavigationConvention); conventionSet.NavigationAddedConventions.Add(inversePropertyAttributeConvention); conventionSet.NavigationAddedConventions.Add(foreignKeyPropertyDiscoveryConvention); conventionSet.NavigationAddedConventions.Add(relationshipDiscoveryConvention); diff --git a/src/EFCore/Metadata/Conventions/NonNullableConventionBase.cs b/src/EFCore/Metadata/Conventions/NonNullableConventionBase.cs index ade27a0084f..5d921ed151c 100644 --- a/src/EFCore/Metadata/Conventions/NonNullableConventionBase.cs +++ b/src/EFCore/Metadata/Conventions/NonNullableConventionBase.cs @@ -20,6 +20,7 @@ public abstract class NonNullableConventionBase : IModelFinalizedConvention // For the interpretation of nullability metadata, see // https://github.com/dotnet/roslyn/blob/master/docs/features/nullable-metadata.md + private const string StateAnnotationName = "NonNullableConventionState"; private const string NullableAttributeFullName = "System.Runtime.CompilerServices.NullableAttribute"; private const string NullableContextAttributeFullName = "System.Runtime.CompilerServices.NullableContextAttribute"; @@ -141,8 +142,6 @@ NonNullabilityConventionState GetOrInitializeState(IConventionModelBuilder model modelBuilder.Metadata.AddAnnotation(StateAnnotationName, new NonNullabilityConventionState()) ).Value; - private const string StateAnnotationName = "NonNullableConventionState"; - private class NonNullabilityConventionState { public Type NullableAttrType;