From 5b64e1ac2d1d2e57d3ef8f2daa2fe6a7c7682a3a Mon Sep 17 00:00:00 2001 From: Shay Rojansky Date: Fri, 15 Jan 2021 16:04:51 +0100 Subject: [PATCH 1/8] Annotate the remainder of metadata for nullability Part of #19007 --- All.sln.DotSettings | 1 + .../AbstractionsStrings.Designer.cs | 2 +- .../CosmosEntityTypeBuilderExtensions.cs | 32 +- .../Extensions/CosmosEntityTypeExtensions.cs | 36 +- .../CosmosModelBuilderExtensions.cs | 10 +- .../Extensions/CosmosModelExtensions.cs | 12 +- .../CosmosPropertyBuilderExtensions.cs | 8 +- .../Extensions/CosmosPropertyExtensions.cs | 10 +- .../Conventions/ContextContainerConvention.cs | 2 + .../CosmosDiscriminatorConvention.cs | 13 +- .../CosmosKeyDiscoveryConvention.cs | 6 +- .../Conventions/ETagPropertyConvention.cs | 2 + .../Internal/CosmosConventionSetBuilder.cs | 4 +- .../Conventions/StoreKeyConvention.cs | 30 +- .../Storage/Internal/CosmosTypeMapping.cs | 8 +- .../InMemoryEntityTypeBuilderExtensions.cs | 8 +- .../InMemoryEntityTypeExtensions.cs | 14 +- .../DefiningQueryRewritingConvention.cs | 2 + .../InMemoryConventionSetBuilder.cs | 6 +- .../Query/Internal/InMemoryQueryExpression.cs | 8 +- .../Storage/Internal/InMemoryTypeMapping.cs | 8 +- .../RelationalEntityTypeBuilderExtensions.cs | 173 +++-- .../RelationalEntityTypeExtensions.cs | 112 +-- .../RelationalForeignKeyBuilderExtensions.cs | 20 +- .../RelationalForeignKeyExtensions.cs | 32 +- .../RelationalIndexBuilderExtensions.cs | 32 +- .../Extensions/RelationalIndexExtensions.cs | 49 +- .../RelationalKeyBuilderExtensions.cs | 12 +- .../Extensions/RelationalKeyExtensions.cs | 48 +- .../RelationalModelBuilderExtensions.cs | 38 +- .../Extensions/RelationalModelExtensions.cs | 12 +- ...ationalOwnedNavigationBuilderExtensions.cs | 6 +- .../RelationalPropertyBuilderExtensions.cs | 86 ++- .../RelationalPropertyExtensions.cs | 184 ++--- .../Metadata/Builders/DbFunctionBuilder.cs | 6 +- .../Builders/DbFunctionBuilderBase.cs | 8 +- .../Builders/DbFunctionParameterBuilder.cs | 10 +- .../Builders/IConventionDbFunctionBuilder.cs | 28 +- .../IConventionDbFunctionParameterBuilder.cs | 16 +- .../Builders/IConventionSequenceBuilder.cs | 16 +- .../Metadata/Builders/SequenceBuilder.cs | 6 +- .../Metadata/Builders/TableBuilder.cs | 8 +- .../Metadata/Builders/TableBuilder`.cs | 4 +- .../Builders/TableValuedFunctionBuilder.cs | 4 +- .../DbFunctionTypeMappingConvention.cs | 4 +- .../EntityTypeHierarchyMappingConvention.cs | 4 +- .../RelationalConventionSetBuilder.cs | 2 + ...ationalConventionSetBuilderDependencies.cs | 2 + .../RelationalColumnAttributeConvention.cs | 2 + ...ationalColumnCommentAttributeConvention.cs | 2 + ...RelationalDbFunctionAttributeConvention.cs | 2 + ...RelationalMaxIdentifierLengthConvention.cs | 2 + .../Conventions/RelationalModelConvention.cs | 2 + ...elationalQueryFilterRewritingConvention.cs | 4 +- .../RelationalTableAttributeConvention.cs | 2 + ...lationalTableCommentAttributeConvention.cs | 2 + .../RelationalValueGenerationConvention.cs | 24 +- .../SequenceUniquificationConvention.cs | 4 +- .../Conventions/SharedTableConvention.cs | 37 +- .../Conventions/StoreGenerationConvention.cs | 6 +- .../TableNameFromDbSetConvention.cs | 8 +- .../TableSharingConcurrencyTokenConvention.cs | 20 +- .../TableValuedDbFunctionConvention.cs | 6 +- .../Metadata/IConventionDbFunction.cs | 8 +- .../Metadata/IConventionSequence.cs | 8 +- .../Metadata/Internal/DbFunction.cs | 36 +- .../Metadata/Internal/DbFunctionParameter.cs | 2 +- .../Internal/InternalDbFunctionBuilder.cs | 20 +- .../InternalDbFunctionParameterBuilder.cs | 8 +- .../Internal/InternalSequenceBuilder.cs | 4 +- .../Metadata/Internal/RelationalModel.cs | 22 +- .../Metadata/Internal/Sequence.cs | 35 +- .../Metadata/Internal/View.cs | 2 +- .../Internal/FromSqlQueryingEnumerable.cs | 2 +- .../RelationalCollectionShaperExpression.cs | 2 +- .../Query/SqlExpressions/SelectExpression.cs | 22 +- .../SqlExpressions/SqlFunctionExpression.cs | 12 +- .../Storage/RelationalTypeMapping.cs | 4 +- .../SqlServerEntityTypeBuilderExtensions.cs | 4 +- .../SqlServerEntityTypeExtensions.cs | 2 + .../SqlServerIndexBuilderExtensions.cs | 21 +- .../Extensions/SqlServerIndexExtensions.cs | 10 +- .../SqlServerKeyBuilderExtensions.cs | 4 +- .../Extensions/SqlServerKeyExtensions.cs | 2 + .../SqlServerModelBuilderExtensions.cs | 40 +- .../Extensions/SqlServerModelExtensions.cs | 50 +- .../SqlServerPropertyBuilderExtensions.cs | 26 +- .../Extensions/SqlServerPropertyExtensions.cs | 30 +- .../SqlServerConventionSetBuilder.cs | 6 +- .../SqlServerDbFunctionConvention.cs | 2 + .../Conventions/SqlServerIndexConvention.cs | 18 +- ...qlServerMemoryOptimizedTablesConvention.cs | 6 +- .../SqlServerOnDeleteConvention.cs | 13 +- .../SqlServerSharedTableConvention.cs | 2 + .../SqlServerStoreGenerationConvention.cs | 6 +- .../SqlServerValueGenerationConvention.cs | 6 +- ...ServerValueGenerationStrategyConvention.cs | 2 + .../Internal/SqlServerAnnotationProvider.cs | 7 +- .../Internal/SqlServerIndexExtensions.cs | 11 +- .../SqlitePropertyBuilderExtensions.cs | 4 +- .../Extensions/SqlitePropertyExtensions.cs | 2 + .../Conventions/SqliteConventionSetBuilder.cs | 6 +- .../ConventionAnnotatableExtensions.cs | 6 +- .../ConventionForeignKeyExtensions.cs | 4 +- .../Extensions/ConventionKeyExtensions.cs | 2 + .../Extensions/ConventionModelExtensions.cs | 22 +- .../ConventionPropertyExtensions.cs | 2 +- .../Extensions/Internal/TypeExtensions.cs | 2 +- .../Extensions/MutablePropertyExtensions.cs | 2 +- .../Extensions/PropertyBaseExtensions.cs | 10 +- .../Infrastructure/AnnotatableBuilder.cs | 30 +- .../Infrastructure/ConventionAnnotatable.cs | 4 + .../Infrastructure/ExpressionExtensions.cs | 9 +- src/EFCore/Infrastructure/IInfrastructure.cs | 2 + .../Builders/CollectionCollectionBuilder.cs | 32 +- .../Builders/CollectionCollectionBuilder`.cs | 14 +- .../Builders/CollectionNavigationBuilder.cs | 57 +- .../Builders/CollectionNavigationBuilder`.cs | 14 +- src/EFCore/Metadata/Builders/DataBuilder.cs | 6 +- src/EFCore/Metadata/Builders/DataBuilder`.cs | 2 + .../Metadata/Builders/DiscriminatorBuilder.cs | 38 +- .../Builders/DiscriminatorBuilder`.cs | 12 +- .../Metadata/Builders/EntityTypeBuilder.cs | 78 +- .../Metadata/Builders/EntityTypeBuilder`.cs | 62 +- .../Builders/IConventionAnnotatableBuilder.cs | 18 +- .../IConventionDiscriminatorBuilder.cs | 14 +- .../Builders/IConventionEntityTypeBuilder.cs | 120 +-- .../Builders/IConventionForeignKeyBuilder.cs | 72 +- .../Builders/IConventionIndexBuilder.cs | 4 +- .../Builders/IConventionKeyBuilder.cs | 2 + .../Builders/IConventionModelBuilder.cs | 24 +- .../Builders/IConventionNavigationBuilder.cs | 12 +- .../IConventionOwnedEntityTypeBuilder.cs | 2 + .../IConventionPropertyBaseBuilder.cs | 12 +- .../Builders/IConventionPropertyBuilder.cs | 56 +- .../IConventionServicePropertyBuilder.cs | 14 +- .../IConventionSkipNavigationBuilder.cs | 18 +- src/EFCore/Metadata/Builders/IndexBuilder.cs | 6 +- src/EFCore/Metadata/Builders/IndexBuilder`.cs | 2 + .../InvertibleRelationshipBuilderBase.cs | 76 +- src/EFCore/Metadata/Builders/KeyBuilder.cs | 6 +- src/EFCore/Metadata/Builders/KeyBuilder`.cs | 2 + .../Metadata/Builders/NavigationBuilder.cs | 28 +- .../Metadata/Builders/NavigationBuilder`.cs | 8 +- .../Builders/OwnedEntityTypeBuilder.cs | 6 +- .../Builders/OwnedEntityTypeBuilder`.cs | 2 + .../Builders/OwnedNavigationBuilder.cs | 56 +- .../Builders/OwnedNavigationBuilder`.cs | 36 +- .../Metadata/Builders/OwnershipBuilder.cs | 8 +- .../Metadata/Builders/OwnershipBuilder`.cs | 12 +- .../Metadata/Builders/PropertyBuilder.cs | 18 +- .../Metadata/Builders/PropertyBuilder`.cs | 30 +- .../Builders/ReferenceCollectionBuilder.cs | 19 +- .../Builders/ReferenceCollectionBuilder`.cs | 8 +- .../Builders/ReferenceNavigationBuilder.cs | 52 +- .../Builders/ReferenceNavigationBuilder`.cs | 14 +- .../Builders/ReferenceReferenceBuilder.cs | 40 +- .../Builders/ReferenceReferenceBuilder`.cs | 22 +- .../Builders/RelationshipBuilderBase.cs | 67 +- .../BackingFieldAttributeConvention.cs | 2 + .../Conventions/BackingFieldConvention.cs | 18 +- .../BaseTypeDiscoveryConvention.cs | 15 +- .../Conventions/CascadeDeleteConvention.cs | 2 + .../ChangeTrackingStrategyConvention.cs | 2 + .../ConcurrencyCheckAttributeConvention.cs | 2 + .../ConstructorBindingConvention.cs | 4 +- .../Metadata/Conventions/ConventionSet.cs | 2 + .../DatabaseGeneratedAttributeConvention.cs | 2 + .../Conventions/DbSetFindingConvention.cs | 2 + .../DerivedTypeDiscoveryConvention.cs | 2 + .../Conventions/DiscriminatorConvention.cs | 14 +- .../EntityTypeAttributeConventionBase.cs | 2 + .../ForeignKeyAttributeConvention.cs | 73 +- .../Conventions/ForeignKeyIndexConvention.cs | 16 +- .../ForeignKeyPropertyDiscoveryConvention.cs | 83 +- .../Metadata/Conventions/IConvention.cs | 2 + .../Metadata/Conventions/IConventionBatch.cs | 5 +- .../Conventions/IConventionContext.cs | 2 + .../Conventions/IConventionContext`.cs | 11 +- .../Conventions/IEntityTypeAddedConvention.cs | 2 + .../IEntityTypeAnnotationChangedConvention.cs | 6 +- .../IEntityTypeBaseTypeChangedConvention.cs | 6 +- .../IEntityTypeIgnoredConvention.cs | 4 +- .../IEntityTypeMemberIgnoredConvention.cs | 2 + .../IEntityTypePrimaryKeyChangedConvention.cs | 6 +- .../IEntityTypeRemovedConvention.cs | 2 + .../Conventions/IForeignKeyAddedConvention.cs | 2 + .../IForeignKeyAnnotationChangedConvention.cs | 6 +- ...yDependentRequirednessChangedConvention.cs | 2 + .../IForeignKeyOwnershipChangedConvention.cs | 2 + ...ForeignKeyPrincipalEndChangedConvention.cs | 2 + .../IForeignKeyPropertiesChangedConvention.cs | 2 + .../IForeignKeyRemovedConvention.cs | 2 + ...ForeignKeyRequirednessChangedConvention.cs | 2 + .../IForeignKeyUniquenessChangedConvention.cs | 2 + .../Conventions/IIndexAddedConvention.cs | 2 + .../IIndexAnnotationChangedConvention.cs | 6 +- .../Conventions/IIndexRemovedConvention.cs | 2 + .../IIndexUniquenessChangedConvention.cs | 2 + .../Conventions/IKeyAddedConvention.cs | 2 + .../IKeyAnnotationChangedConvention.cs | 6 +- .../Conventions/IKeyRemovedConvention.cs | 2 + .../IModelAnnotationChangedConvention.cs | 6 +- .../Conventions/IModelFinalizedConvention.cs | 2 + .../Conventions/IModelFinalizingConvention.cs | 2 + .../IModelInitializedConvention.cs | 2 + .../Conventions/INavigationAddedConvention.cs | 2 + .../INavigationAnnotationChangedConvention.cs | 6 +- .../INavigationRemovedConvention.cs | 4 +- .../Conventions/IPropertyAddedConvention.cs | 2 + .../IPropertyAnnotationChangedConvention.cs | 6 +- .../IPropertyFieldChangedConvention.cs | 6 +- .../IPropertyNullabilityChangedConvention.cs | 2 + .../Conventions/IPropertyRemovedConvention.cs | 2 + .../ISkipNavigationAddedConvention.cs | 2 + ...ipNavigationAnnotationChangedConvention.cs | 6 +- ...ipNavigationForeignKeyChangedConvention.cs | 6 +- ...ISkipNavigationInverseChangedConvention.cs | 6 +- .../ISkipNavigationRemovedConvention.cs | 2 + .../Conventions/IndexAttributeConvention.cs | 8 +- .../Infrastructure/IConventionSetBuilder.cs | 2 + .../Infrastructure/IConventionSetPlugin.cs | 2 + .../IProviderConventionSetBuilder.cs | 2 + .../ProviderConventionSetBuilder.cs | 2 + ...roviderConventionSetBuilderDependencies.cs | 2 + .../InheritanceDiscoveryConventionBase.cs | 6 +- .../Internal/ConventionBatchExtensions.cs | 6 +- .../Conventions/Internal/ConventionContext.cs | 14 +- .../ConventionDispatcher.ConventionNode.cs | 2 + .../ConventionDispatcher.ConventionScope.cs | 122 +-- ...entionDispatcher.DelayedConventionScope.cs | 189 ++--- ...tionDispatcher.ImmediateConventionScope.cs | 252 +++--- .../Internal/ConventionDispatcher.cs | 137 ++-- .../Internal/IReadableConventionContext.cs | 2 + .../Conventions/Internal/MetadataTracker.cs | 6 +- .../Internal/RuntimeConventionSetBuilder.cs | 2 + .../InversePropertyAttributeConvention.cs | 59 +- .../Conventions/KeyAttributeConvention.cs | 2 + .../Conventions/KeyDiscoveryConvention.cs | 18 +- .../KeylessEntityTypeAttributeConvention.cs | 2 + .../ManyToManyJoinEntityTypeConvention.cs | 24 +- .../MaxLengthAttributeConvention.cs | 2 + .../Conventions/ModelCleanupConvention.cs | 6 +- .../NavigationAttributeConventionBase.cs | 24 +- ...vigationBackingFieldAttributeConvention.cs | 2 + .../NavigationEagerLoadingConvention.cs | 2 + .../Conventions/NonNullableConventionBase.cs | 10 +- .../NonNullableNavigationConvention.cs | 2 + .../NonNullableReferencePropertyConvention.cs | 6 +- .../NotMappedEntityTypeAttributeConvention.cs | 2 + .../NotMappedMemberAttributeConvention.cs | 6 +- .../OwnedEntityTypeAttributeConvention.cs | 2 + .../Conventions/OwnedTypesConvention.cs | 2 + .../PropertyAttributeConventionBase.cs | 6 +- .../PropertyDiscoveryConvention.cs | 8 +- .../QueryFilterRewritingConvention.cs | 12 +- .../RelationshipDiscoveryConvention.cs | 92 ++- .../RequiredNavigationAttributeConvention.cs | 10 +- .../RequiredPropertyAttributeConvention.cs | 2 + .../ServicePropertyDiscoveryConvention.cs | 16 +- .../StringLengthAttributeConvention.cs | 2 + .../TimestampAttributeConvention.cs | 2 + .../Conventions/TypeMappingConvention.cs | 2 + .../Conventions/UnicodeAttributeConvention.cs | 2 + .../Conventions/ValidatingConvention.cs | 2 + .../Conventions/ValueGenerationConvention.cs | 36 +- src/EFCore/Metadata/IClrPropertyGetter.cs | 2 +- .../Metadata/IConstructorBindingFactory.cs | 9 +- src/EFCore/Metadata/IConventionAnnotatable.cs | 9 +- src/EFCore/Metadata/IConventionEntityType.cs | 7 +- src/EFCore/Metadata/IConventionForeignKey.cs | 3 +- src/EFCore/Metadata/IConventionIndex.cs | 4 +- src/EFCore/Metadata/IConventionKey.cs | 4 +- src/EFCore/Metadata/IConventionNavigation.cs | 4 +- src/EFCore/Metadata/IConventionProperty.cs | 4 +- .../Metadata/IConventionServiceProperty.cs | 4 +- .../Metadata/IConventionSkipNavigation.cs | 5 +- src/EFCore/Metadata/IConventionTypeBase.cs | 2 +- src/EFCore/Metadata/IMutableProperty.cs | 2 + src/EFCore/Metadata/IMutableTypeBase.cs | 2 +- .../Metadata/IParameterBindingFactories.cs | 4 +- .../IPropertyParameterBindingFactory.cs | 2 +- .../Metadata/Internal/ClrAccessorFactory.cs | 12 +- .../Internal/ClrCollectionAccessor.cs | 22 +- .../Internal/ClrCollectionAccessorFactory.cs | 38 +- .../Metadata/Internal/ClrPropertyGetter.cs | 4 +- .../Internal/ClrPropertyGetterFactory.cs | 6 +- ...ClrPropertyMaterializationSetterFactory.cs | 2 + .../Metadata/Internal/ClrPropertySetter.cs | 6 +- .../Internal/ClrPropertySetterFactory.cs | 6 +- .../Internal/CollectionTypeFactory.cs | 4 +- .../Internal/ConstructorBindingFactory.cs | 21 +- .../ContextParameterBindingFactory.cs | 2 + src/EFCore/Metadata/Internal/EntityType.cs | 92 ++- .../EntityTypeParameterBindingFactory.cs | 2 + src/EFCore/Metadata/Internal/ForeignKey.cs | 55 +- .../Metadata/Internal/IMemberClassifier.cs | 4 +- .../Metadata/Internal/IReferenceRoot.cs | 2 + src/EFCore/Metadata/Internal/Index.cs | 40 +- .../Internal/InternalEntityTypeBuilder.cs | 720 +++++++++--------- .../Internal/InternalForeignKeyBuilder.cs | 505 ++++++------ .../Metadata/Internal/InternalIndexBuilder.cs | 8 +- .../Metadata/Internal/InternalKeyBuilder.cs | 4 +- .../Metadata/Internal/InternalModelBuilder.cs | 79 +- .../Internal/InternalNavigationBuilder.cs | 50 +- .../InternalOwnedEntityTypeBuilder.cs | 2 + .../Internal/InternalPropertyBaseBuilder`.cs | 16 +- .../Internal/InternalPropertyBuilder.cs | 143 ++-- .../InternalServicePropertyBuilder.cs | 48 +- .../Internal/InternalSkipNavigationBuilder.cs | 100 +-- src/EFCore/Metadata/Internal/Key.cs | 39 +- .../Metadata/Internal/MemberClassifier.cs | 4 +- .../Metadata/Internal/MetadataExtensions.cs | 3 + src/EFCore/Metadata/Internal/Model.cs | 43 +- src/EFCore/Metadata/Internal/Navigation.cs | 33 +- .../Internal/NullableEnumClrPropertySetter.cs | 6 +- .../Internal/ParameterBindingFactories.cs | 6 +- .../Metadata/Internal/PropertiesSnapshot.cs | 18 +- src/EFCore/Metadata/Internal/Property.cs | 33 +- .../Metadata/Internal/PropertyAccessors.cs | 10 +- .../Internal/PropertyAccessorsFactory.cs | 7 +- src/EFCore/Metadata/Internal/PropertyBase.cs | 4 +- .../Internal/PropertyBaseExtensions.cs | 12 +- .../Metadata/Internal/PropertyCounts.cs | 2 + .../Metadata/Internal/PropertyIndexes.cs | 2 + .../PropertyParameterBindingFactory.cs | 4 +- .../Metadata/Internal/RelationshipSnapshot.cs | 16 +- .../Metadata/Internal/ServiceProperty.cs | 32 +- .../Metadata/Internal/SkipNavigation.cs | 49 +- src/EFCore/Metadata/Internal/TypeBase.cs | 10 +- .../Metadata/Internal/TypeBaseExtensions.cs | 15 +- src/EFCore/Metadata/Internal/TypeIdentity.cs | 6 +- src/EFCore/Properties/CoreStrings.Designer.cs | 6 + src/EFCore/Properties/CoreStrings.resx | 3 + src/EFCore/Storage/CoreTypeMapping.cs | 2 +- src/Shared/Check.cs | 8 +- .../RelationalMetadataExtensionsTest.cs | 8 +- .../Conventions/ConventionDispatcherTest.cs | 14 +- .../Metadata/Internal/EntityTypeTest.cs | 24 +- .../InternalSkipNavigationBuilderTest.cs | 2 +- .../Metadata/Internal/ModelTest.cs | 12 +- 341 files changed, 3934 insertions(+), 3105 deletions(-) diff --git a/All.sln.DotSettings b/All.sln.DotSettings index 237a053d2fc..057325cb8fc 100644 --- a/All.sln.DotSettings +++ b/All.sln.DotSettings @@ -230,4 +230,5 @@ Licensed under the Apache License, Version 2.0. See License.txt in the project r True True True + True True \ No newline at end of file diff --git a/src/EFCore.Abstractions/Properties/AbstractionsStrings.Designer.cs b/src/EFCore.Abstractions/Properties/AbstractionsStrings.Designer.cs index fd0fdab4432..7aa43dede24 100644 --- a/src/EFCore.Abstractions/Properties/AbstractionsStrings.Designer.cs +++ b/src/EFCore.Abstractions/Properties/AbstractionsStrings.Designer.cs @@ -34,7 +34,7 @@ public static string ArgumentIsEmpty([CanBeNull] object? argumentName) /// /// The number argument '{argumentName}' cannot be negative number. /// - public static string ArgumentIsNegativeNumber([CanBeNull] object argumentName) + public static string ArgumentIsNegativeNumber([CanBeNull] object? argumentName) => string.Format( GetString("ArgumentIsNegativeNumber", nameof(argumentName)), argumentName); diff --git a/src/EFCore.Cosmos/Extensions/CosmosEntityTypeBuilderExtensions.cs b/src/EFCore.Cosmos/Extensions/CosmosEntityTypeBuilderExtensions.cs index 9f3c918835f..3608f20fac5 100644 --- a/src/EFCore.Cosmos/Extensions/CosmosEntityTypeBuilderExtensions.cs +++ b/src/EFCore.Cosmos/Extensions/CosmosEntityTypeBuilderExtensions.cs @@ -10,6 +10,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + // ReSharper disable once CheckNamespace namespace Microsoft.EntityFrameworkCore { @@ -26,7 +28,7 @@ public static class CosmosEntityTypeBuilderExtensions /// The same builder instance so that multiple calls can be chained. public static EntityTypeBuilder ToContainer( [NotNull] this EntityTypeBuilder entityTypeBuilder, - [CanBeNull] string name) + [CanBeNull] string? name) { Check.NotNull(entityTypeBuilder, nameof(entityTypeBuilder)); Check.NullButNotEmpty(name, nameof(name)); @@ -45,7 +47,7 @@ public static EntityTypeBuilder ToContainer( /// The same builder instance so that multiple calls can be chained. public static EntityTypeBuilder ToContainer( [NotNull] this EntityTypeBuilder entityTypeBuilder, - [CanBeNull] string name) + [CanBeNull] string? name) where TEntity : class => (EntityTypeBuilder)ToContainer((EntityTypeBuilder)entityTypeBuilder, name); @@ -59,9 +61,9 @@ public static EntityTypeBuilder ToContainer( /// The same builder instance if the configuration was applied, /// otherwise. /// - public static IConventionEntityTypeBuilder ToContainer( + public static IConventionEntityTypeBuilder? ToContainer( [NotNull] this IConventionEntityTypeBuilder entityTypeBuilder, - [CanBeNull] string name, + [CanBeNull] string? name, bool fromDataAnnotation = false) { if (!entityTypeBuilder.CanSetContainer(name, fromDataAnnotation)) @@ -84,7 +86,7 @@ public static IConventionEntityTypeBuilder ToContainer( /// if the configuration can be applied. public static bool CanSetContainer( [NotNull] this IConventionEntityTypeBuilder entityTypeBuilder, - [CanBeNull] string name, + [CanBeNull] string? name, bool fromDataAnnotation = false) { Check.NotNull(entityTypeBuilder, nameof(entityTypeBuilder)); @@ -101,7 +103,7 @@ public static bool CanSetContainer( /// The same builder instance so that multiple calls can be chained. public static OwnedNavigationBuilder ToJsonProperty( [NotNull] this OwnedNavigationBuilder entityTypeBuilder, - [CanBeNull] string name) + [CanBeNull] string? name) { entityTypeBuilder.OwnedEntityType.SetContainingPropertyName(name); @@ -116,7 +118,7 @@ public static OwnedNavigationBuilder ToJsonProperty( /// The same builder instance so that multiple calls can be chained. public static OwnedNavigationBuilder ToJsonProperty( [NotNull] this OwnedNavigationBuilder entityTypeBuilder, - [CanBeNull] string name) + [CanBeNull] string? name) where TEntity : class where TDependentEntity : class { @@ -135,9 +137,9 @@ public static OwnedNavigationBuilder ToJsonProperty otherwise. /// - public static IConventionEntityTypeBuilder ToJsonProperty( + public static IConventionEntityTypeBuilder? ToJsonProperty( [NotNull] this IConventionEntityTypeBuilder entityTypeBuilder, - [CanBeNull] string name, + [CanBeNull] string? name, bool fromDataAnnotation = false) { if (!entityTypeBuilder.CanSetJsonProperty(name, fromDataAnnotation)) @@ -160,7 +162,7 @@ public static IConventionEntityTypeBuilder ToJsonProperty( /// if the configuration can be applied. public static bool CanSetJsonProperty( [NotNull] this IConventionEntityTypeBuilder entityTypeBuilder, - [CanBeNull] string name, + [CanBeNull] string? name, bool fromDataAnnotation = false) { Check.NotNull(entityTypeBuilder, nameof(entityTypeBuilder)); @@ -177,7 +179,7 @@ public static bool CanSetJsonProperty( /// The same builder instance so that multiple calls can be chained. public static EntityTypeBuilder HasPartitionKey( [NotNull] this EntityTypeBuilder entityTypeBuilder, - [CanBeNull] string name) + [CanBeNull] string? name) { entityTypeBuilder.Metadata.SetPartitionKeyPropertyName(name); @@ -192,7 +194,7 @@ public static EntityTypeBuilder HasPartitionKey( /// The same builder instance so that multiple calls can be chained. public static EntityTypeBuilder HasPartitionKey( [NotNull] this EntityTypeBuilder entityTypeBuilder, - [CanBeNull] string name) + [CanBeNull] string? name) where TEntity : class { entityTypeBuilder.Metadata.SetPartitionKeyPropertyName(name); @@ -228,9 +230,9 @@ public static EntityTypeBuilder HasPartitionKey( /// The same builder instance if the configuration was applied, /// otherwise. /// - public static IConventionEntityTypeBuilder HasPartitionKey( + public static IConventionEntityTypeBuilder? HasPartitionKey( [NotNull] this IConventionEntityTypeBuilder entityTypeBuilder, - [CanBeNull] string name, + [CanBeNull] string? name, bool fromDataAnnotation = false) { if (!entityTypeBuilder.CanSetPartitionKey(name, fromDataAnnotation)) @@ -253,7 +255,7 @@ public static IConventionEntityTypeBuilder HasPartitionKey( /// if the configuration can be applied. public static bool CanSetPartitionKey( [NotNull] this IConventionEntityTypeBuilder entityTypeBuilder, - [CanBeNull] string name, + [CanBeNull] string? name, bool fromDataAnnotation = false) { Check.NotNull(entityTypeBuilder, nameof(entityTypeBuilder)); diff --git a/src/EFCore.Cosmos/Extensions/CosmosEntityTypeExtensions.cs b/src/EFCore.Cosmos/Extensions/CosmosEntityTypeExtensions.cs index 06df02876a3..45df40bf3e2 100644 --- a/src/EFCore.Cosmos/Extensions/CosmosEntityTypeExtensions.cs +++ b/src/EFCore.Cosmos/Extensions/CosmosEntityTypeExtensions.cs @@ -6,6 +6,8 @@ using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + // ReSharper disable once CheckNamespace namespace Microsoft.EntityFrameworkCore { @@ -19,13 +21,13 @@ public static class CosmosEntityTypeExtensions /// /// The entity type to get the container name for. /// The name of the container to which the entity type is mapped. - public static string GetContainer([NotNull] this IEntityType entityType) + public static string? GetContainer([NotNull] this IEntityType entityType) => entityType.BaseType != null ? entityType.GetRootType().GetContainer() - : (string)entityType[CosmosAnnotationNames.ContainerName] + : (string?)entityType[CosmosAnnotationNames.ContainerName] ?? GetDefaultContainer(entityType); - private static string GetDefaultContainer(IEntityType entityType) + private static string? GetDefaultContainer(IEntityType entityType) => entityType.IsOwned() ? null : entityType.Model.GetDefaultContainer() @@ -36,7 +38,7 @@ private static string GetDefaultContainer(IEntityType entityType) /// /// The entity type to set the container name for. /// The name to set. - public static void SetContainer([NotNull] this IMutableEntityType entityType, [CanBeNull] string name) + public static void SetContainer([NotNull] this IMutableEntityType entityType, [CanBeNull] string? name) => entityType.SetOrRemoveAnnotation( CosmosAnnotationNames.ContainerName, Check.NullButNotEmpty(name, nameof(name))); @@ -49,7 +51,7 @@ public static void SetContainer([NotNull] this IMutableEntityType entityType, [C /// Indicates whether the configuration was specified using a data annotation. public static void SetContainer( [NotNull] this IConventionEntityType entityType, - [CanBeNull] string name, + [CanBeNull] string? name, bool fromDataAnnotation = false) => entityType.SetOrRemoveAnnotation( CosmosAnnotationNames.ContainerName, @@ -70,19 +72,19 @@ public static void SetContainer( /// /// The entity type to get the containing property name for. /// The name of the parent property to which the entity type is mapped. - public static string GetContainingPropertyName([NotNull] this IEntityType entityType) + public static string? GetContainingPropertyName([NotNull] this IEntityType entityType) => entityType[CosmosAnnotationNames.PropertyName] as string ?? GetDefaultContainingPropertyName(entityType); - private static string GetDefaultContainingPropertyName(IEntityType entityType) - => entityType.FindOwnership()?.PrincipalToDependent.Name; + private static string? GetDefaultContainingPropertyName(IEntityType entityType) + => entityType.FindOwnership()?.PrincipalToDependent!.Name; /// /// Sets the name of the parent property to which the entity type is mapped. /// /// The entity type to set the containing property name for. /// The name to set. - public static void SetContainingPropertyName([NotNull] this IMutableEntityType entityType, [CanBeNull] string name) + public static void SetContainingPropertyName([NotNull] this IMutableEntityType entityType, [CanBeNull] string? name) => entityType.SetOrRemoveAnnotation( CosmosAnnotationNames.PropertyName, Check.NullButNotEmpty(name, nameof(name))); @@ -95,7 +97,7 @@ public static void SetContainingPropertyName([NotNull] this IMutableEntityType e /// Indicates whether the configuration was specified using a data annotation. public static void SetContainingPropertyName( [NotNull] this IConventionEntityType entityType, - [CanBeNull] string name, + [CanBeNull] string? name, bool fromDataAnnotation = false) => entityType.SetOrRemoveAnnotation( CosmosAnnotationNames.PropertyName, @@ -116,7 +118,7 @@ public static void SetContainingPropertyName( /// /// The entity type to get the partition key property name for. /// The name of the partition key property. - public static string GetPartitionKeyPropertyName([NotNull] this IEntityType entityType) + public static string? GetPartitionKeyPropertyName([NotNull] this IEntityType entityType) => entityType[CosmosAnnotationNames.PartitionKeyName] as string; /// @@ -124,7 +126,7 @@ public static string GetPartitionKeyPropertyName([NotNull] this IEntityType enti /// /// The entity type to set the partition key property name for. /// The name to set. - public static void SetPartitionKeyPropertyName([NotNull] this IMutableEntityType entityType, [CanBeNull] string name) + public static void SetPartitionKeyPropertyName([NotNull] this IMutableEntityType entityType, [CanBeNull] string? name) => entityType.SetOrRemoveAnnotation( CosmosAnnotationNames.PartitionKeyName, Check.NullButNotEmpty(name, nameof(name))); @@ -137,7 +139,7 @@ public static void SetPartitionKeyPropertyName([NotNull] this IMutableEntityType /// Indicates whether the configuration was specified using a data annotation. public static void SetPartitionKeyPropertyName( [NotNull] this IConventionEntityType entityType, - [CanBeNull] string name, + [CanBeNull] string? name, bool fromDataAnnotation = false) => entityType.SetOrRemoveAnnotation( CosmosAnnotationNames.PartitionKeyName, @@ -158,7 +160,7 @@ public static void SetPartitionKeyPropertyName( /// /// The entity type to get the etag property name for. /// The name of the etag property. - public static string GetETagPropertyName([NotNull] this IEntityType entityType) + public static string? GetETagPropertyName([NotNull] this IEntityType entityType) => entityType[CosmosAnnotationNames.ETagName] as string; /// @@ -166,7 +168,7 @@ public static string GetETagPropertyName([NotNull] this IEntityType entityType) /// /// The entity type to set the etag property name for. /// The name to set. - public static void SetETagPropertyName([NotNull] this IMutableEntityType entityType, [CanBeNull] string name) + public static void SetETagPropertyName([NotNull] this IMutableEntityType entityType, [CanBeNull] string? name) => entityType.SetOrRemoveAnnotation( CosmosAnnotationNames.ETagName, Check.NullButNotEmpty(name, nameof(name))); @@ -179,7 +181,7 @@ public static void SetETagPropertyName([NotNull] this IMutableEntityType entityT /// Indicates whether the configuration was specified using a data annotation. public static void SetETagPropertyName( [NotNull] this IConventionEntityType entityType, - [CanBeNull] string name, + [CanBeNull] string? name, bool fromDataAnnotation = false) => entityType.SetOrRemoveAnnotation( CosmosAnnotationNames.ETagName, @@ -200,7 +202,7 @@ public static void SetETagPropertyName( /// /// The entity type to get the etag property for. /// The mapped to etag, or null if no property is mapped to etag. - public static IProperty GetETagProperty([NotNull] this IEntityType entityType) + public static IProperty? GetETagProperty([NotNull] this IEntityType entityType) { Check.NotNull(entityType, nameof(entityType)); var etagPropertyName = entityType.GetETagPropertyName(); diff --git a/src/EFCore.Cosmos/Extensions/CosmosModelBuilderExtensions.cs b/src/EFCore.Cosmos/Extensions/CosmosModelBuilderExtensions.cs index 7accac5d79b..595de88ab78 100644 --- a/src/EFCore.Cosmos/Extensions/CosmosModelBuilderExtensions.cs +++ b/src/EFCore.Cosmos/Extensions/CosmosModelBuilderExtensions.cs @@ -6,6 +6,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + // ReSharper disable once CheckNamespace namespace Microsoft.EntityFrameworkCore { @@ -23,7 +25,7 @@ public static class CosmosModelBuilderExtensions /// The same builder instance so that multiple calls can be chained. public static ModelBuilder HasDefaultContainer( [NotNull] this ModelBuilder modelBuilder, - [CanBeNull] string name) + [CanBeNull] string? name) { Check.NotNull(modelBuilder, nameof(modelBuilder)); Check.NullButNotEmpty(name, nameof(name)); @@ -44,9 +46,9 @@ public static ModelBuilder HasDefaultContainer( /// The same builder instance if the configuration was applied, /// otherwise. /// - public static IConventionModelBuilder HasDefaultContainer( + public static IConventionModelBuilder? HasDefaultContainer( [NotNull] this IConventionModelBuilder modelBuilder, - [CanBeNull] string name, + [CanBeNull] string? name, bool fromDataAnnotation = false) { if (!modelBuilder.CanSetDefaultContainer(name, fromDataAnnotation)) @@ -68,7 +70,7 @@ public static IConventionModelBuilder HasDefaultContainer( /// if the given container name can be set as default. public static bool CanSetDefaultContainer( [NotNull] this IConventionModelBuilder modelBuilder, - [CanBeNull] string name, + [CanBeNull] string? name, bool fromDataAnnotation = false) { Check.NotNull(modelBuilder, nameof(modelBuilder)); diff --git a/src/EFCore.Cosmos/Extensions/CosmosModelExtensions.cs b/src/EFCore.Cosmos/Extensions/CosmosModelExtensions.cs index c88a8e7ab89..80b4de7d1a2 100644 --- a/src/EFCore.Cosmos/Extensions/CosmosModelExtensions.cs +++ b/src/EFCore.Cosmos/Extensions/CosmosModelExtensions.cs @@ -6,6 +6,8 @@ using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + // ReSharper disable once CheckNamespace namespace Microsoft.EntityFrameworkCore { @@ -19,15 +21,15 @@ public static class CosmosModelExtensions /// /// The model. /// The default container name. - public static string GetDefaultContainer([NotNull] this IModel model) - => (string)model[CosmosAnnotationNames.ContainerName]; + public static string? GetDefaultContainer([NotNull] this IModel model) + => (string?)model[CosmosAnnotationNames.ContainerName]; /// /// Sets the default container name. /// /// The model. /// The name to set. - public static void SetDefaultContainer([NotNull] this IMutableModel model, [CanBeNull] string name) + public static void SetDefaultContainer([NotNull] this IMutableModel model, [CanBeNull] string? name) => model.SetOrRemoveAnnotation( CosmosAnnotationNames.ContainerName, Check.NullButNotEmpty(name, nameof(name))); @@ -39,9 +41,9 @@ public static void SetDefaultContainer([NotNull] this IMutableModel model, [CanB /// The name to set. /// Indicates whether the configuration was specified using a data annotation. /// The configured value. - public static string SetDefaultContainer( + public static string? SetDefaultContainer( [NotNull] this IConventionModel model, - [CanBeNull] string name, + [CanBeNull] string? name, bool fromDataAnnotation = false) { model.SetOrRemoveAnnotation( diff --git a/src/EFCore.Cosmos/Extensions/CosmosPropertyBuilderExtensions.cs b/src/EFCore.Cosmos/Extensions/CosmosPropertyBuilderExtensions.cs index d1b56328812..bf67189b9f3 100644 --- a/src/EFCore.Cosmos/Extensions/CosmosPropertyBuilderExtensions.cs +++ b/src/EFCore.Cosmos/Extensions/CosmosPropertyBuilderExtensions.cs @@ -6,6 +6,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + // ReSharper disable once CheckNamespace namespace Microsoft.EntityFrameworkCore { @@ -60,9 +62,9 @@ public static PropertyBuilder ToJsonProperty( /// The same builder instance if the configuration was applied, /// otherwise. /// - public static IConventionPropertyBuilder ToJsonProperty( + public static IConventionPropertyBuilder? ToJsonProperty( [NotNull] this IConventionPropertyBuilder propertyBuilder, - [CanBeNull] string name, + [CanBeNull] string? name, bool fromDataAnnotation = false) { if (!propertyBuilder.CanSetJsonProperty(name, fromDataAnnotation)) @@ -84,7 +86,7 @@ public static IConventionPropertyBuilder ToJsonProperty( /// if the property name can be set. public static bool CanSetJsonProperty( [NotNull] this IConventionPropertyBuilder propertyBuilder, - [CanBeNull] string name, + [CanBeNull] string? name, bool fromDataAnnotation = false) => propertyBuilder.CanSetAnnotation(CosmosAnnotationNames.PropertyName, name, fromDataAnnotation); diff --git a/src/EFCore.Cosmos/Extensions/CosmosPropertyExtensions.cs b/src/EFCore.Cosmos/Extensions/CosmosPropertyExtensions.cs index 8db108e8e7b..4fb7a1a0f88 100644 --- a/src/EFCore.Cosmos/Extensions/CosmosPropertyExtensions.cs +++ b/src/EFCore.Cosmos/Extensions/CosmosPropertyExtensions.cs @@ -6,6 +6,8 @@ using Microsoft.EntityFrameworkCore.Cosmos.Metadata.Internal; using Microsoft.EntityFrameworkCore.Metadata; +#nullable enable + // ReSharper disable once CheckNamespace namespace Microsoft.EntityFrameworkCore { @@ -20,7 +22,7 @@ public static class CosmosPropertyExtensions /// The property. /// Returns the property name that the property is mapped to when targeting Cosmos. public static string GetJsonPropertyName([NotNull] this IProperty property) - => (string)property[CosmosAnnotationNames.PropertyName] + => (string?)property[CosmosAnnotationNames.PropertyName] ?? GetDefaultJsonPropertyName(property); private static string GetDefaultJsonPropertyName(IProperty property) @@ -49,7 +51,7 @@ private static string GetDefaultJsonPropertyName(IProperty property) /// /// The property. /// The name to set. - public static void SetJsonPropertyName([NotNull] this IMutableProperty property, [CanBeNull] string name) + public static void SetJsonPropertyName([NotNull] this IMutableProperty property, [CanBeNull] string? name) => property.SetOrRemoveAnnotation( CosmosAnnotationNames.PropertyName, name); @@ -61,9 +63,9 @@ public static void SetJsonPropertyName([NotNull] this IMutableProperty property, /// The name to set. /// Indicates whether the configuration was specified using a data annotation. /// The configured value. - public static string SetJsonPropertyName( + public static string? SetJsonPropertyName( [NotNull] this IConventionProperty property, - [CanBeNull] string name, + [CanBeNull] string? name, bool fromDataAnnotation = false) { property.SetOrRemoveAnnotation( diff --git a/src/EFCore.Cosmos/Metadata/Conventions/ContextContainerConvention.cs b/src/EFCore.Cosmos/Metadata/Conventions/ContextContainerConvention.cs index 5b60b827613..3eb63c1b40f 100644 --- a/src/EFCore.Cosmos/Metadata/Conventions/ContextContainerConvention.cs +++ b/src/EFCore.Cosmos/Metadata/Conventions/ContextContainerConvention.cs @@ -6,6 +6,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// diff --git a/src/EFCore.Cosmos/Metadata/Conventions/CosmosDiscriminatorConvention.cs b/src/EFCore.Cosmos/Metadata/Conventions/CosmosDiscriminatorConvention.cs index 378a2029759..a1278f188b1 100644 --- a/src/EFCore.Cosmos/Metadata/Conventions/CosmosDiscriminatorConvention.cs +++ b/src/EFCore.Cosmos/Metadata/Conventions/CosmosDiscriminatorConvention.cs @@ -8,6 +8,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// @@ -101,8 +103,8 @@ public virtual void ProcessForeignKeyRemoved( /// Additional information associated with convention execution. public override void ProcessEntityTypeBaseTypeChanged( IConventionEntityTypeBuilder entityTypeBuilder, - IConventionEntityType newBaseType, - IConventionEntityType oldBaseType, + IConventionEntityType? newBaseType, + IConventionEntityType? oldBaseType, IConventionContext context) { if (entityTypeBuilder.Metadata.BaseType != newBaseType) @@ -110,7 +112,7 @@ public override void ProcessEntityTypeBaseTypeChanged( return; } - IConventionDiscriminatorBuilder discriminator = null; + IConventionDiscriminatorBuilder? discriminator = null; var entityType = entityTypeBuilder.Metadata; if (newBaseType == null) { @@ -121,7 +123,10 @@ public override void ProcessEntityTypeBaseTypeChanged( } else { - discriminator = newBaseType.GetRootType().Builder?.HasDiscriminator(typeof(string)); + var rootType = newBaseType.GetRootType(); + discriminator = rootType.IsInModel + ? rootType.Builder.HasDiscriminator(typeof(string)) + : null; if (newBaseType.BaseType == null) { diff --git a/src/EFCore.Cosmos/Metadata/Conventions/CosmosKeyDiscoveryConvention.cs b/src/EFCore.Cosmos/Metadata/Conventions/CosmosKeyDiscoveryConvention.cs index 1adb526121e..cb40a0d7dbb 100644 --- a/src/EFCore.Cosmos/Metadata/Conventions/CosmosKeyDiscoveryConvention.cs +++ b/src/EFCore.Cosmos/Metadata/Conventions/CosmosKeyDiscoveryConvention.cs @@ -8,6 +8,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// @@ -38,8 +40,8 @@ public CosmosKeyDiscoveryConvention([NotNull] ProviderConventionSetBuilderDepend public virtual void ProcessEntityTypeAnnotationChanged( IConventionEntityTypeBuilder entityTypeBuilder, string name, - IConventionAnnotation annotation, - IConventionAnnotation oldAnnotation, + IConventionAnnotation? annotation, + IConventionAnnotation? oldAnnotation, IConventionContext context) { Check.NotNull(entityTypeBuilder, nameof(entityTypeBuilder)); diff --git a/src/EFCore.Cosmos/Metadata/Conventions/ETagPropertyConvention.cs b/src/EFCore.Cosmos/Metadata/Conventions/ETagPropertyConvention.cs index eda65264cea..0e8fa5e9f87 100644 --- a/src/EFCore.Cosmos/Metadata/Conventions/ETagPropertyConvention.cs +++ b/src/EFCore.Cosmos/Metadata/Conventions/ETagPropertyConvention.cs @@ -4,6 +4,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Metadata.Conventions; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Cosmos.Metadata.Conventions { /// diff --git a/src/EFCore.Cosmos/Metadata/Conventions/Internal/CosmosConventionSetBuilder.cs b/src/EFCore.Cosmos/Metadata/Conventions/Internal/CosmosConventionSetBuilder.cs index c22c2a314c5..75c961ca288 100644 --- a/src/EFCore.Cosmos/Metadata/Conventions/Internal/CosmosConventionSetBuilder.cs +++ b/src/EFCore.Cosmos/Metadata/Conventions/Internal/CosmosConventionSetBuilder.cs @@ -7,6 +7,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure; using Microsoft.Extensions.DependencyInjection; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Cosmos.Metadata.Conventions.Internal { /// @@ -100,7 +102,7 @@ public override ConventionSet CreateConventionSet() public static ModelBuilder CreateModelBuilder() { using var serviceScope = CreateServiceScope(); - using var context = serviceScope.ServiceProvider.GetService(); + using var context = serviceScope.ServiceProvider.GetRequiredService(); return new ModelBuilder(ConventionSet.CreateConventionSet(context), context.GetService()); } diff --git a/src/EFCore.Cosmos/Metadata/Conventions/StoreKeyConvention.cs b/src/EFCore.Cosmos/Metadata/Conventions/StoreKeyConvention.cs index 7cd6dbcedbd..2741e6294b4 100644 --- a/src/EFCore.Cosmos/Metadata/Conventions/StoreKeyConvention.cs +++ b/src/EFCore.Cosmos/Metadata/Conventions/StoreKeyConvention.cs @@ -11,6 +11,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure; using Newtonsoft.Json.Linq; +#nullable enable + // ReSharper disable once CheckNamespace namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { @@ -76,8 +78,8 @@ public StoreKeyConvention([NotNull] ProviderConventionSetBuilderDependencies dep private static void ProcessIdProperty(IConventionEntityTypeBuilder entityTypeBuilder) { - IConventionKey newKey = null; - IConventionProperty idProperty = null; + IConventionKey? newKey = null; + IConventionProperty? idProperty; var entityType = entityTypeBuilder.Metadata; if (entityType.BaseType == null && entityType.IsDocumentRoot() @@ -94,11 +96,11 @@ private static void ProcessIdProperty(IConventionEntityTypeBuilder entityTypeBui { if (idProperty.IsPrimaryKey()) { - idProperty.Builder.HasValueGenerator((Type)null); + idProperty.Builder.HasValueGenerator((Type?)null); } else { - idProperty.Builder.HasValueGenerator((_, __) => new IdValueGenerator()); + idProperty.Builder.HasValueGenerator((_, _) => new IdValueGenerator()); } } @@ -222,8 +224,8 @@ public virtual void ProcessKeyRemoved( /// public virtual void ProcessEntityTypePrimaryKeyChanged( IConventionEntityTypeBuilder entityTypeBuilder, - IConventionKey newPrimaryKey, - IConventionKey previousPrimaryKey, + IConventionKey? newPrimaryKey, + IConventionKey? previousPrimaryKey, IConventionContext context) { if ((newPrimaryKey != null && newPrimaryKey.Properties.Any(p => p.GetJsonPropertyName() == IdPropertyJsonName)) @@ -236,8 +238,8 @@ public virtual void ProcessEntityTypePrimaryKeyChanged( /// public virtual void ProcessEntityTypeBaseTypeChanged( IConventionEntityTypeBuilder entityTypeBuilder, - IConventionEntityType newBaseType, - IConventionEntityType oldBaseType, + IConventionEntityType? newBaseType, + IConventionEntityType? oldBaseType, IConventionContext context) { if (entityTypeBuilder.Metadata.BaseType == newBaseType) @@ -251,8 +253,8 @@ public virtual void ProcessEntityTypeBaseTypeChanged( public virtual void ProcessEntityTypeAnnotationChanged( IConventionEntityTypeBuilder entityTypeBuilder, string name, - IConventionAnnotation annotation, - IConventionAnnotation oldAnnotation, + IConventionAnnotation? annotation, + IConventionAnnotation? oldAnnotation, IConventionContext context) { if (name == CosmosAnnotationNames.ContainerName @@ -263,7 +265,7 @@ public virtual void ProcessEntityTypeAnnotationChanged( } else if (name == CosmosAnnotationNames.PartitionKeyName) { - var oldName = (string)oldAnnotation?.Value; + var oldName = (string?)oldAnnotation?.Value; if (oldName != null) { var oldPartitionKeyProperty = entityTypeBuilder.Metadata.FindProperty(oldName); @@ -284,12 +286,12 @@ public virtual void ProcessEntityTypeAnnotationChanged( public virtual void ProcessPropertyAnnotationChanged( IConventionPropertyBuilder propertyBuilder, string name, - IConventionAnnotation annotation, - IConventionAnnotation oldAnnotation, + IConventionAnnotation? annotation, + IConventionAnnotation? oldAnnotation, IConventionContext context) { if (name == CosmosAnnotationNames.PropertyName - && (string)annotation?.Value == IdPropertyJsonName + && (string?)annotation?.Value == IdPropertyJsonName && propertyBuilder.Metadata.Name != DefaultIdPropertyName) { var entityType = propertyBuilder.Metadata.DeclaringEntityType; diff --git a/src/EFCore.Cosmos/Storage/Internal/CosmosTypeMapping.cs b/src/EFCore.Cosmos/Storage/Internal/CosmosTypeMapping.cs index 299607ca4f8..162caa39dd9 100644 --- a/src/EFCore.Cosmos/Storage/Internal/CosmosTypeMapping.cs +++ b/src/EFCore.Cosmos/Storage/Internal/CosmosTypeMapping.cs @@ -7,6 +7,8 @@ using Microsoft.EntityFrameworkCore.Storage; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Cosmos.Storage.Internal { /// @@ -25,8 +27,8 @@ public class CosmosTypeMapping : CoreTypeMapping /// public CosmosTypeMapping( [NotNull] Type clrType, - [CanBeNull] ValueComparer comparer = null, - [CanBeNull] ValueComparer keyComparer = null) + [CanBeNull] ValueComparer? comparer = null, + [CanBeNull] ValueComparer? keyComparer = null) : base( new CoreTypeMappingParameters( clrType, @@ -53,7 +55,7 @@ protected CosmosTypeMapping(CoreTypeMappingParameters parameters) /// 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. /// - public override CoreTypeMapping Clone(ValueConverter converter) + public override CoreTypeMapping Clone(ValueConverter? converter) => new CosmosTypeMapping(Parameters.WithComposedConverter(converter)); } } diff --git a/src/EFCore.InMemory/Extensions/InMemoryEntityTypeBuilderExtensions.cs b/src/EFCore.InMemory/Extensions/InMemoryEntityTypeBuilderExtensions.cs index b0769362ca2..3235499d4db 100644 --- a/src/EFCore.InMemory/Extensions/InMemoryEntityTypeBuilderExtensions.cs +++ b/src/EFCore.InMemory/Extensions/InMemoryEntityTypeBuilderExtensions.cs @@ -9,6 +9,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Internal; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + // ReSharper disable once CheckNamespace namespace Microsoft.EntityFrameworkCore { @@ -44,9 +46,9 @@ public static EntityTypeBuilder ToInMemoryQuery( /// /// The same builder instance if the query was set, otherwise. /// - public static IConventionEntityTypeBuilder ToInMemoryQuery( + public static IConventionEntityTypeBuilder? ToInMemoryQuery( [NotNull] this IConventionEntityTypeBuilder entityTypeBuilder, - [CanBeNull] LambdaExpression query, + [CanBeNull] LambdaExpression? query, bool fromDataAnnotation = false) { if (CanSetInMemoryQuery(entityTypeBuilder, query, fromDataAnnotation)) @@ -68,7 +70,7 @@ public static IConventionEntityTypeBuilder ToInMemoryQuery( /// if the given in-memory query can be set. public static bool CanSetInMemoryQuery( [NotNull] this IConventionEntityTypeBuilder entityTypeBuilder, - [CanBeNull] LambdaExpression query, + [CanBeNull] LambdaExpression? query, bool fromDataAnnotation = false) #pragma warning disable EF1001 // Internal EF Core API usage. #pragma warning disable CS0612 // Type or member is obsolete diff --git a/src/EFCore.InMemory/Extensions/InMemoryEntityTypeExtensions.cs b/src/EFCore.InMemory/Extensions/InMemoryEntityTypeExtensions.cs index 9b6692bc19a..123181eabfc 100644 --- a/src/EFCore.InMemory/Extensions/InMemoryEntityTypeExtensions.cs +++ b/src/EFCore.InMemory/Extensions/InMemoryEntityTypeExtensions.cs @@ -7,6 +7,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Internal; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + // ReSharper disable once CheckNamespace namespace Microsoft.EntityFrameworkCore { @@ -20,10 +22,10 @@ public static class InMemoryEntityTypeExtensions /// /// The entity type to get the in-memory query for. /// The LINQ query used as the default source. - public static LambdaExpression GetInMemoryQuery([NotNull] this IEntityType entityType) + public static LambdaExpression? GetInMemoryQuery([NotNull] this IEntityType entityType) #pragma warning disable EF1001 // Internal EF Core API usage. #pragma warning disable CS0612 // Type or member is obsolete - => (LambdaExpression)Check.NotNull(entityType, nameof(entityType))[CoreAnnotationNames.DefiningQuery]; + => (LambdaExpression?)Check.NotNull(entityType, nameof(entityType))[CoreAnnotationNames.DefiningQuery]; #pragma warning restore CS0612 // Type or member is obsolete #pragma warning restore EF1001 // Internal EF Core API usage. @@ -34,7 +36,7 @@ public static LambdaExpression GetInMemoryQuery([NotNull] this IEntityType entit /// The LINQ query used as the default source. public static void SetInMemoryQuery( [NotNull] this IMutableEntityType entityType, - [CanBeNull] LambdaExpression inMemoryQuery) + [CanBeNull] LambdaExpression? inMemoryQuery) => Check.NotNull(entityType, nameof(entityType)) #pragma warning disable EF1001 // Internal EF Core API usage. #pragma warning disable CS0612 // Type or member is obsolete @@ -49,11 +51,11 @@ public static void SetInMemoryQuery( /// The LINQ query used as the default source. /// Indicates whether the configuration was specified using a data annotation. /// The configured entity type. - public static LambdaExpression SetInMemoryQuery( + public static LambdaExpression? SetInMemoryQuery( [NotNull] this IConventionEntityType entityType, - [CanBeNull] LambdaExpression inMemoryQuery, + [CanBeNull] LambdaExpression? inMemoryQuery, bool fromDataAnnotation = false) - => (LambdaExpression)Check.NotNull(entityType, nameof(entityType)) + => (LambdaExpression?)Check.NotNull(entityType, nameof(entityType)) #pragma warning disable EF1001 // Internal EF Core API usage. #pragma warning disable CS0612 // Type or member is obsolete .SetOrRemoveAnnotation(CoreAnnotationNames.DefiningQuery, inMemoryQuery, fromDataAnnotation) diff --git a/src/EFCore.InMemory/Metadata/Conventions/DefiningQueryRewritingConvention.cs b/src/EFCore.InMemory/Metadata/Conventions/DefiningQueryRewritingConvention.cs index 9b8593008c8..33f4699b7a9 100644 --- a/src/EFCore.InMemory/Metadata/Conventions/DefiningQueryRewritingConvention.cs +++ b/src/EFCore.InMemory/Metadata/Conventions/DefiningQueryRewritingConvention.cs @@ -7,6 +7,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure; using Microsoft.EntityFrameworkCore.Query; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// diff --git a/src/EFCore.InMemory/Metadata/Conventions/InMemoryConventionSetBuilder.cs b/src/EFCore.InMemory/Metadata/Conventions/InMemoryConventionSetBuilder.cs index 0b32bf4c8b6..bb6f50c9b29 100644 --- a/src/EFCore.InMemory/Metadata/Conventions/InMemoryConventionSetBuilder.cs +++ b/src/EFCore.InMemory/Metadata/Conventions/InMemoryConventionSetBuilder.cs @@ -8,6 +8,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure; using Microsoft.Extensions.DependencyInjection; +#nullable enable + namespace Microsoft.EntityFrameworkCore.InMemory.Metadata.Conventions { /// @@ -58,7 +60,7 @@ public override ConventionSet CreateConventionSet() public static ConventionSet Build() { using var serviceScope = CreateServiceScope(); - using var context = serviceScope.ServiceProvider.GetService(); + using var context = serviceScope.ServiceProvider.GetRequiredService(); return ConventionSet.CreateConventionSet(context); } @@ -75,7 +77,7 @@ public static ConventionSet Build() public static ModelBuilder CreateModelBuilder() { using var serviceScope = CreateServiceScope(); - using var context = serviceScope.ServiceProvider.GetService(); + using var context = serviceScope.ServiceProvider.GetRequiredService(); return new ModelBuilder(ConventionSet.CreateConventionSet(context), context.GetService()); } diff --git a/src/EFCore.InMemory/Query/Internal/InMemoryQueryExpression.cs b/src/EFCore.InMemory/Query/Internal/InMemoryQueryExpression.cs index 0ba21736128..926f0b4a498 100644 --- a/src/EFCore.InMemory/Query/Internal/InMemoryQueryExpression.cs +++ b/src/EFCore.InMemory/Query/Internal/InMemoryQueryExpression.cs @@ -237,7 +237,7 @@ public virtual int AddToProjection([NotNull] Expression expression) /// public virtual int AddSubqueryProjection( [NotNull] ShapedQueryExpression shapedQueryExpression, - [CanBeNull] out Expression innerShaper) + [NotNull] out Expression innerShaper) { var subquery = (InMemoryQueryExpression)shapedQueryExpression.QueryExpression; subquery.ApplyProjection(); @@ -698,7 +698,7 @@ public virtual void AddInnerJoin( [NotNull] InMemoryQueryExpression innerQueryExpression, [NotNull] LambdaExpression outerKeySelector, [NotNull] LambdaExpression innerKeySelector, - [CanBeNull] Type transparentIdentifierType) + [CanBeNull] Type? transparentIdentifierType) { var outerParameter = Parameter(typeof(ValueBuffer), "outer"); var innerParameter = Parameter(typeof(ValueBuffer), "inner"); @@ -790,7 +790,7 @@ public virtual void AddLeftJoin( [NotNull] InMemoryQueryExpression innerQueryExpression, [NotNull] LambdaExpression outerKeySelector, [NotNull] LambdaExpression innerKeySelector, - [CanBeNull] Type transparentIdentifierType) + [CanBeNull] Type? transparentIdentifierType) { // GroupJoin phase var groupTransparentIdentifierType = TransparentIdentifierFactory.Create( @@ -938,7 +938,7 @@ EntityProjectionExpression CopyEntityProjectionToOuter(EntityProjectionExpressio /// public virtual void AddSelectMany( [NotNull] InMemoryQueryExpression innerQueryExpression, - [CanBeNull] Type transparentIdentifierType, + [CanBeNull] Type? transparentIdentifierType, bool innerNullable) { var outerParameter = Parameter(typeof(ValueBuffer), "outer"); diff --git a/src/EFCore.InMemory/Storage/Internal/InMemoryTypeMapping.cs b/src/EFCore.InMemory/Storage/Internal/InMemoryTypeMapping.cs index 8aaf0412724..f2f284f2e24 100644 --- a/src/EFCore.InMemory/Storage/Internal/InMemoryTypeMapping.cs +++ b/src/EFCore.InMemory/Storage/Internal/InMemoryTypeMapping.cs @@ -7,6 +7,8 @@ using Microsoft.EntityFrameworkCore.Storage; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +#nullable enable + namespace Microsoft.EntityFrameworkCore.InMemory.Storage.Internal { /// @@ -25,8 +27,8 @@ public class InMemoryTypeMapping : CoreTypeMapping /// public InMemoryTypeMapping( [NotNull] Type clrType, - [CanBeNull] ValueComparer comparer = null, - [CanBeNull] ValueComparer keyComparer = null) + [CanBeNull] ValueComparer? comparer = null, + [CanBeNull] ValueComparer? keyComparer = null) : base( new CoreTypeMappingParameters( clrType, @@ -47,7 +49,7 @@ private InMemoryTypeMapping(CoreTypeMappingParameters parameters) /// 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. /// - public override CoreTypeMapping Clone(ValueConverter converter) + public override CoreTypeMapping Clone(ValueConverter? converter) => new InMemoryTypeMapping(Parameters.WithComposedConverter(converter)); } } diff --git a/src/EFCore.Relational/Extensions/RelationalEntityTypeBuilderExtensions.cs b/src/EFCore.Relational/Extensions/RelationalEntityTypeBuilderExtensions.cs index 2a0b7530109..0e62c2a773e 100644 --- a/src/EFCore.Relational/Extensions/RelationalEntityTypeBuilderExtensions.cs +++ b/src/EFCore.Relational/Extensions/RelationalEntityTypeBuilderExtensions.cs @@ -9,6 +9,9 @@ using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Metadata.Internal; using Microsoft.EntityFrameworkCore.Utilities; +using CA = System.Diagnostics.CodeAnalysis; + +#nullable enable // ReSharper disable once CheckNamespace namespace Microsoft.EntityFrameworkCore @@ -26,8 +29,8 @@ public static class RelationalEntityTypeBuilderExtensions /// The same builder instance so that multiple calls can be chained. public static EntityTypeBuilder ToTable( [NotNull] this EntityTypeBuilder entityTypeBuilder, - [CanBeNull] string name) - => entityTypeBuilder.ToTable(name, (string)null); + [CanBeNull] string? name) + => entityTypeBuilder.ToTable(name, (string?)null); /// /// Configures the table that the entity type maps to when targeting a relational database. @@ -38,7 +41,7 @@ public static EntityTypeBuilder ToTable( /// The same builder instance so that multiple calls can be chained. public static EntityTypeBuilder ToTable( [NotNull] this EntityTypeBuilder entityTypeBuilder, - [CanBeNull] string name, + [CanBeNull] string? name, [NotNull] Action buildAction) => entityTypeBuilder.ToTable(name, null, buildAction); @@ -51,9 +54,9 @@ public static EntityTypeBuilder ToTable( /// The same builder instance so that multiple calls can be chained. public static EntityTypeBuilder ToTable( [NotNull] this EntityTypeBuilder entityTypeBuilder, - [CanBeNull] string name) + [CanBeNull] string? name) where TEntity : class - => entityTypeBuilder.ToTable(name, (string)null); + => entityTypeBuilder.ToTable(name, (string?)null); /// /// Configures the table that the entity type maps to when targeting a relational database. @@ -65,7 +68,7 @@ public static EntityTypeBuilder ToTable( /// The same builder instance so that multiple calls can be chained. public static EntityTypeBuilder ToTable( [NotNull] this EntityTypeBuilder entityTypeBuilder, - [CanBeNull] string name, + [CanBeNull] string? name, [NotNull] Action buildAction) where TEntity : class => entityTypeBuilder.ToTable(name, null, buildAction); @@ -80,7 +83,7 @@ public static EntityTypeBuilder ToTable( /// The same builder instance so that multiple calls can be chained. public static EntityTypeBuilder ToTable( [NotNull] this EntityTypeBuilder entityTypeBuilder, - [CanBeNull] string name, + [CanBeNull] string? name, [NotNull] Action> buildAction) where TEntity : class => entityTypeBuilder.ToTable(name, null, buildAction); @@ -94,8 +97,8 @@ public static EntityTypeBuilder ToTable( /// The same builder instance so that multiple calls can be chained. public static EntityTypeBuilder ToTable( [NotNull] this EntityTypeBuilder entityTypeBuilder, - [CanBeNull] string name, - [CanBeNull] string schema) + [CanBeNull] string? name, + [CanBeNull] string? schema) { entityTypeBuilder.Metadata.SetTableName(name); entityTypeBuilder.Metadata.SetSchema(schema); @@ -112,8 +115,8 @@ public static EntityTypeBuilder ToTable( /// The same builder instance so that multiple calls can be chained. public static EntityTypeBuilder ToTable( [NotNull] this EntityTypeBuilder entityTypeBuilder, - [NotNull] string name, - [CanBeNull] string schema, + [CanBeNull] string? name, // TODO-NULLABLE: Note nullability change (called with null by other overloads) + [CanBeNull] string? schema, [NotNull] Action buildAction) { Check.NotNull(name, nameof(name)); @@ -137,8 +140,8 @@ public static EntityTypeBuilder ToTable( /// The same builder instance so that multiple calls can be chained. public static EntityTypeBuilder ToTable( [NotNull] this EntityTypeBuilder entityTypeBuilder, - [NotNull] string name, - [CanBeNull] string schema, + [CanBeNull] string? name, + [CanBeNull] string? schema, [NotNull] Action buildAction) where TEntity : class => (EntityTypeBuilder)((EntityTypeBuilder)entityTypeBuilder).ToTable(name, schema, buildAction); @@ -153,8 +156,8 @@ public static EntityTypeBuilder ToTable( /// The same builder instance so that multiple calls can be chained. public static EntityTypeBuilder ToTable( [NotNull] this EntityTypeBuilder entityTypeBuilder, - [CanBeNull] string name, - [CanBeNull] string schema) + [CanBeNull] string? name, + [CanBeNull] string? schema) where TEntity : class { entityTypeBuilder.Metadata.SetTableName(name); @@ -173,8 +176,8 @@ public static EntityTypeBuilder ToTable( /// The same builder instance so that multiple calls can be chained. public static EntityTypeBuilder ToTable( [NotNull] this EntityTypeBuilder entityTypeBuilder, - [CanBeNull] string name, - [CanBeNull] string schema, + [CanBeNull] string? name, + [CanBeNull] string? schema, [NotNull] Action> buildAction) where TEntity : class { @@ -196,7 +199,7 @@ public static EntityTypeBuilder ToTable( /// The same builder instance so that multiple calls can be chained. public static OwnedNavigationBuilder ToTable( [NotNull] this OwnedNavigationBuilder referenceOwnershipBuilder, - [CanBeNull] string name) + [CanBeNull] string? name) => ToTable(referenceOwnershipBuilder, name, schema: null, excludedFromMigrations: null); /// @@ -208,7 +211,7 @@ public static OwnedNavigationBuilder ToTable( /// The same builder instance so that multiple calls can be chained. public static OwnedNavigationBuilder ToTable( [NotNull] this OwnedNavigationBuilder referenceOwnershipBuilder, - [CanBeNull] string name, + [CanBeNull] string? name, bool excludedFromMigrations) => referenceOwnershipBuilder.ToTable(name, null, excludedFromMigrations); @@ -222,7 +225,7 @@ public static OwnedNavigationBuilder ToTable( /// The same builder instance so that multiple calls can be chained. public static OwnedNavigationBuilder ToTable( [NotNull] this OwnedNavigationBuilder referenceOwnershipBuilder, - [CanBeNull] string name) + [CanBeNull] string? name) where TEntity : class where TRelatedEntity : class => (OwnedNavigationBuilder)ToTable( @@ -239,7 +242,7 @@ public static OwnedNavigationBuilder ToTable The same builder instance so that multiple calls can be chained. public static OwnedNavigationBuilder ToTable( [NotNull] this OwnedNavigationBuilder referenceOwnershipBuilder, - [CanBeNull] string name, + [CanBeNull] string? name, bool excludedFromMigrations) where TEntity : class where TRelatedEntity : class @@ -255,8 +258,8 @@ public static OwnedNavigationBuilder ToTable The same builder instance so that multiple calls can be chained. public static OwnedNavigationBuilder ToTable( [NotNull] this OwnedNavigationBuilder referenceOwnershipBuilder, - [CanBeNull] string name, - [CanBeNull] string schema) + [CanBeNull] string? name, + [CanBeNull] string? schema) => ToTable(referenceOwnershipBuilder, name, schema, excludedFromMigrations: null); /// @@ -269,8 +272,8 @@ public static OwnedNavigationBuilder ToTable( /// The same builder instance so that multiple calls can be chained. public static OwnedNavigationBuilder ToTable( [NotNull] this OwnedNavigationBuilder referenceOwnershipBuilder, - [CanBeNull] string name, - [CanBeNull] string schema, + [CanBeNull] string? name, + [CanBeNull] string? schema, bool excludedFromMigrations) { Check.NotNull(referenceOwnershipBuilder, nameof(referenceOwnershipBuilder)); @@ -282,8 +285,8 @@ public static OwnedNavigationBuilder ToTable( private static OwnedNavigationBuilder ToTable( OwnedNavigationBuilder referenceOwnershipBuilder, - string name, - string schema, + string? name, + string? schema, bool? excludedFromMigrations) { referenceOwnershipBuilder.OwnedEntityType.SetTableName(name); @@ -308,8 +311,8 @@ private static OwnedNavigationBuilder ToTable( /// The same builder instance so that multiple calls can be chained. public static OwnedNavigationBuilder ToTable( [NotNull] this OwnedNavigationBuilder referenceOwnershipBuilder, - [CanBeNull] string name, - [CanBeNull] string schema) + [CanBeNull] string? name, + [CanBeNull] string? schema) where TEntity : class where TRelatedEntity : class => (OwnedNavigationBuilder)ToTable( @@ -327,8 +330,8 @@ public static OwnedNavigationBuilder ToTable The same builder instance so that multiple calls can be chained. public static OwnedNavigationBuilder ToTable( [NotNull] this OwnedNavigationBuilder referenceOwnershipBuilder, - [CanBeNull] string name, - [CanBeNull] string schema, + [CanBeNull] string? name, + [CanBeNull] string? schema, bool excludedFromMigrations) where TEntity : class where TRelatedEntity : class @@ -344,9 +347,9 @@ public static OwnedNavigationBuilder ToTable /// The same builder instance if the configuration was applied, otherwise. /// - public static IConventionEntityTypeBuilder ToTable( + public static IConventionEntityTypeBuilder? ToTable( [NotNull] this IConventionEntityTypeBuilder entityTypeBuilder, - [CanBeNull] string name, + [CanBeNull] string? name, bool fromDataAnnotation = false) { if (!entityTypeBuilder.CanSetTable(name, fromDataAnnotation)) @@ -368,10 +371,10 @@ public static IConventionEntityTypeBuilder ToTable( /// /// The same builder instance if the configuration was applied, otherwise. /// - public static IConventionEntityTypeBuilder ToTable( + public static IConventionEntityTypeBuilder? ToTable( [NotNull] this IConventionEntityTypeBuilder entityTypeBuilder, - [CanBeNull] string name, - [CanBeNull] string schema, + [CanBeNull] string? name, + [CanBeNull] string? schema, bool fromDataAnnotation = false) { if (!entityTypeBuilder.CanSetTable(name, fromDataAnnotation) @@ -395,7 +398,7 @@ public static IConventionEntityTypeBuilder ToTable( /// if the configuration can be applied. public static bool CanSetTable( [NotNull] this IConventionEntityTypeBuilder entityTypeBuilder, - [CanBeNull] string name, + [CanBeNull] string? name, bool fromDataAnnotation = false) { Check.NullButNotEmpty(name, nameof(name)); @@ -412,9 +415,9 @@ public static bool CanSetTable( /// /// The same builder instance if the configuration was applied, otherwise. /// - public static IConventionEntityTypeBuilder ToSchema( + public static IConventionEntityTypeBuilder? ToSchema( [NotNull] this IConventionEntityTypeBuilder entityTypeBuilder, - [CanBeNull] string schema, + [CanBeNull] string? schema, bool fromDataAnnotation = false) { if (!entityTypeBuilder.CanSetSchema(schema, fromDataAnnotation)) @@ -436,7 +439,7 @@ public static IConventionEntityTypeBuilder ToSchema( /// if the configuration can be applied. public static bool CanSetSchema( [NotNull] this IConventionEntityTypeBuilder entityTypeBuilder, - [CanBeNull] string schema, + [CanBeNull] string? schema, bool fromDataAnnotation = false) { Check.NullButNotEmpty(schema, nameof(schema)); @@ -454,7 +457,7 @@ public static bool CanSetSchema( /// The same builder instance if the configuration was applied, /// otherwise. /// - public static IConventionEntityTypeBuilder ExcludeTableFromMigrations( + public static IConventionEntityTypeBuilder? ExcludeTableFromMigrations( [NotNull] this IConventionEntityTypeBuilder entityTypeBuilder, bool? excludedFromMigrations, bool fromDataAnnotation = false) @@ -491,7 +494,7 @@ public static bool CanExcludeTableFromMigrations( /// The same builder instance so that multiple calls can be chained. public static EntityTypeBuilder ToView( [NotNull] this EntityTypeBuilder entityTypeBuilder, - [CanBeNull] string name) + [CanBeNull] string? name) => entityTypeBuilder.ToView(name, null); /// @@ -503,7 +506,7 @@ public static EntityTypeBuilder ToView( /// The same builder instance so that multiple calls can be chained. public static EntityTypeBuilder ToView( [NotNull] this EntityTypeBuilder entityTypeBuilder, - [CanBeNull] string name) + [CanBeNull] string? name) where TEntity : class => (EntityTypeBuilder)ToView((EntityTypeBuilder)entityTypeBuilder, name); @@ -516,8 +519,8 @@ public static EntityTypeBuilder ToView( /// The same builder instance so that multiple calls can be chained. public static EntityTypeBuilder ToView( [NotNull] this EntityTypeBuilder entityTypeBuilder, - [CanBeNull] string name, - [CanBeNull] string schema) + [CanBeNull] string? name, + [CanBeNull] string? schema) { Check.NotNull(entityTypeBuilder, nameof(entityTypeBuilder)); Check.NullButNotEmpty(name, nameof(name)); @@ -540,8 +543,8 @@ public static EntityTypeBuilder ToView( /// The same builder instance so that multiple calls can be chained. public static EntityTypeBuilder ToView( [NotNull] this EntityTypeBuilder entityTypeBuilder, - [CanBeNull] string name, - [CanBeNull] string schema) + [CanBeNull] string? name, + [CanBeNull] string? schema) where TEntity : class => (EntityTypeBuilder)ToView((EntityTypeBuilder)entityTypeBuilder, name, schema); @@ -554,9 +557,9 @@ public static EntityTypeBuilder ToView( /// /// The same builder instance if the configuration was applied, otherwise. /// - public static IConventionEntityTypeBuilder ToView( + public static IConventionEntityTypeBuilder? ToView( [NotNull] this IConventionEntityTypeBuilder entityTypeBuilder, - [CanBeNull] string name, + [CanBeNull] string? name, bool fromDataAnnotation = false) { if (!entityTypeBuilder.CanSetView(name, fromDataAnnotation)) @@ -578,10 +581,10 @@ public static IConventionEntityTypeBuilder ToView( /// /// The same builder instance if the configuration was applied, otherwise. /// - public static IConventionEntityTypeBuilder ToView( + public static IConventionEntityTypeBuilder? ToView( [NotNull] this IConventionEntityTypeBuilder entityTypeBuilder, - [CanBeNull] string name, - [CanBeNull] string schema, + [CanBeNull] string? name, + [CanBeNull] string? schema, bool fromDataAnnotation = false) { if (!entityTypeBuilder.CanSetView(name, fromDataAnnotation) @@ -605,7 +608,7 @@ public static IConventionEntityTypeBuilder ToView( /// if the configuration can be applied. public static bool CanSetView( [NotNull] this IConventionEntityTypeBuilder entityTypeBuilder, - [CanBeNull] string name, + [CanBeNull] string? name, bool fromDataAnnotation = false) { Check.NullButNotEmpty(name, nameof(name)); @@ -622,9 +625,9 @@ public static bool CanSetView( /// /// The same builder instance if the configuration was applied, otherwise. /// - public static IConventionEntityTypeBuilder ToViewSchema( + public static IConventionEntityTypeBuilder? ToViewSchema( [NotNull] this IConventionEntityTypeBuilder entityTypeBuilder, - [CanBeNull] string schema, + [CanBeNull] string? schema, bool fromDataAnnotation = false) { if (!entityTypeBuilder.CanSetSchema(schema, fromDataAnnotation)) @@ -646,7 +649,7 @@ public static IConventionEntityTypeBuilder ToViewSchema( /// if the configuration can be applied. public static bool CanSetViewSchema( [NotNull] this IConventionEntityTypeBuilder entityTypeBuilder, - [CanBeNull] string schema, + [CanBeNull] string? schema, bool fromDataAnnotation = false) { Check.NullButNotEmpty(schema, nameof(schema)); @@ -681,9 +684,9 @@ public static EntityTypeBuilder ToSqlQuery( /// /// The same builder instance if the configuration was applied, otherwise. /// - public static IConventionEntityTypeBuilder ToSqlQuery( + public static IConventionEntityTypeBuilder? ToSqlQuery( [NotNull] this IConventionEntityTypeBuilder entityTypeBuilder, - [CanBeNull] string name, + [CanBeNull] string? name, bool fromDataAnnotation = false) { if (!entityTypeBuilder.CanSetSqlQuery(name, fromDataAnnotation)) @@ -707,7 +710,7 @@ public static IConventionEntityTypeBuilder ToSqlQuery( /// if the configuration can be applied. public static bool CanSetSqlQuery( [NotNull] this IConventionEntityTypeBuilder entityTypeBuilder, - [CanBeNull] string name, + [CanBeNull] string? name, bool fromDataAnnotation = false) { Check.NullButNotEmpty(name, nameof(name)); @@ -723,7 +726,7 @@ public static bool CanSetSqlQuery( /// The function configuration builder. public static EntityTypeBuilder ToFunction( [NotNull] this EntityTypeBuilder entityTypeBuilder, - [CanBeNull] string name) + [CanBeNull] string? name) { Check.NotNull(entityTypeBuilder, nameof(entityTypeBuilder)); Check.NullButNotEmpty(name, nameof(name)); @@ -742,7 +745,7 @@ public static EntityTypeBuilder ToFunction( /// The same builder instance so that multiple calls can be chained. public static EntityTypeBuilder ToFunction( [NotNull] this EntityTypeBuilder entityTypeBuilder, - [CanBeNull] string name, + [NotNull] string name, [NotNull] Action configureFunction) { Check.NotNull(entityTypeBuilder, nameof(entityTypeBuilder)); @@ -763,7 +766,7 @@ public static EntityTypeBuilder ToFunction( /// The function configuration builder. public static EntityTypeBuilder ToFunction( [NotNull] this EntityTypeBuilder entityTypeBuilder, - [CanBeNull] string name) + [CanBeNull] string? name) where TEntity : class => (EntityTypeBuilder)ToFunction((EntityTypeBuilder)entityTypeBuilder, name); @@ -777,7 +780,7 @@ public static EntityTypeBuilder ToFunction( /// The same builder instance so that multiple calls can be chained. public static EntityTypeBuilder ToFunction( [NotNull] this EntityTypeBuilder entityTypeBuilder, - [CanBeNull] string name, + [NotNull] string name, [NotNull] Action configureFunction) where TEntity : class => (EntityTypeBuilder)ToFunction((EntityTypeBuilder)entityTypeBuilder, name, configureFunction); @@ -790,7 +793,7 @@ public static EntityTypeBuilder ToFunction( /// The function configuration builder. public static OwnedNavigationBuilder ToFunction( [NotNull] this OwnedNavigationBuilder ownedNavigationBuilder, - [CanBeNull] string name) + [CanBeNull] string? name) { Check.NotNull(ownedNavigationBuilder, nameof(ownedNavigationBuilder)); Check.NullButNotEmpty(name, nameof(name)); @@ -809,7 +812,7 @@ public static OwnedNavigationBuilder ToFunction( /// The same builder instance so that multiple calls can be chained. public static OwnedNavigationBuilder ToFunction( [NotNull] this OwnedNavigationBuilder ownedNavigationBuilder, - [CanBeNull] string name, + [NotNull] string name, [NotNull] Action configureFunction) { Check.NotNull(ownedNavigationBuilder, nameof(ownedNavigationBuilder)); @@ -831,7 +834,7 @@ public static OwnedNavigationBuilder ToFunction( /// The function configuration builder. public static OwnedNavigationBuilder ToFunction( [NotNull] this OwnedNavigationBuilder referenceOwnershipBuilder, - [CanBeNull] string name) + [CanBeNull] string? name) where TEntity : class where TRelatedEntity : class => (OwnedNavigationBuilder)ToFunction((OwnedNavigationBuilder)referenceOwnershipBuilder, name); @@ -847,21 +850,23 @@ public static OwnedNavigationBuilder ToFunction The same builder instance so that multiple calls can be chained. public static OwnedNavigationBuilder ToFunction( [NotNull] this OwnedNavigationBuilder referenceOwnershipBuilder, - [CanBeNull] string name, + [NotNull] string name, [NotNull] Action configureFunction) where TEntity : class where TRelatedEntity : class => (OwnedNavigationBuilder)ToFunction( (OwnedNavigationBuilder)referenceOwnershipBuilder, name, configureFunction); - private static IMutableDbFunction CreateFunction(string name, IMutableEntityType entityType) + [return: CA.NotNullIfNotNull("name")] + private static IMutableDbFunction? CreateFunction(string? name, IMutableEntityType entityType) { entityType.SetFunctionName(name); var model = entityType.Model; - var function = model.FindDbFunction(name) - ?? model.AddDbFunction( - name, typeof(IQueryable<>).MakeGenericType(entityType.ClrType ?? typeof(Dictionary))); + var function = name is not null + ? model.FindDbFunction(name) ?? model.AddDbFunction( + name, typeof(IQueryable<>).MakeGenericType(entityType.ClrType ?? typeof(Dictionary))) + : null; return function; } @@ -876,9 +881,9 @@ private static IMutableDbFunction CreateFunction(string name, IMutableEntityType /// The same builder instance if the configuration was applied, /// otherwise. /// - public static IConventionEntityTypeBuilder ToFunction( + public static IConventionEntityTypeBuilder? ToFunction( [NotNull] this IConventionEntityTypeBuilder entityTypeBuilder, - [CanBeNull] string name, + [CanBeNull] string? name, bool fromDataAnnotation = false) { if (!entityTypeBuilder.CanSetFunction(name, fromDataAnnotation)) @@ -904,7 +909,7 @@ public static IConventionEntityTypeBuilder ToFunction( /// if the configuration can be applied. public static bool CanSetFunction( [NotNull] this IConventionEntityTypeBuilder entityTypeBuilder, - [CanBeNull] string name, + [CanBeNull] string? name, bool fromDataAnnotation = false) { Check.NullButNotEmpty(name, nameof(name)); @@ -922,7 +927,7 @@ public static bool CanSetFunction( public static EntityTypeBuilder HasCheckConstraint( [NotNull] this EntityTypeBuilder entityTypeBuilder, [NotNull] string name, - [CanBeNull] string sql) + [CanBeNull] string? sql) { Check.NotNull(entityTypeBuilder, nameof(entityTypeBuilder)); Check.NotEmpty(name, nameof(name)); @@ -961,7 +966,7 @@ public static EntityTypeBuilder HasCheckConstraint( public static EntityTypeBuilder HasCheckConstraint( [NotNull] this EntityTypeBuilder entityTypeBuilder, [NotNull] string name, - [CanBeNull] string sql) + [CanBeNull] string? sql) where TEntity : class => (EntityTypeBuilder)HasCheckConstraint((EntityTypeBuilder)entityTypeBuilder, name, sql); @@ -976,10 +981,10 @@ public static EntityTypeBuilder HasCheckConstraint( /// The same builder instance if the check constraint was configured, /// otherwise. /// - public static IConventionEntityTypeBuilder HasCheckConstraint( + public static IConventionEntityTypeBuilder? HasCheckConstraint( [NotNull] this IConventionEntityTypeBuilder entityTypeBuilder, [NotNull] string name, - [CanBeNull] string sql, + [CanBeNull] string? sql, bool fromDataAnnotation = false) { Check.NotNull(entityTypeBuilder, nameof(entityTypeBuilder)); @@ -1026,7 +1031,7 @@ public static IConventionEntityTypeBuilder HasCheckConstraint( public static bool CanSetCheckConstraint( [NotNull] this IConventionEntityTypeBuilder entityTypeBuilder, [NotNull] string name, - [CanBeNull] string sql, + [CanBeNull] string? sql, bool fromDataAnnotation = false) { Check.NotNull(entityTypeBuilder, nameof(entityTypeBuilder)); @@ -1049,7 +1054,7 @@ public static bool CanSetCheckConstraint( /// A builder to further configure the entity type. public static EntityTypeBuilder HasComment( [NotNull] this EntityTypeBuilder entityTypeBuilder, - [CanBeNull] string comment) + [CanBeNull] string? comment) { Check.NotNull(entityTypeBuilder, nameof(entityTypeBuilder)); @@ -1066,7 +1071,7 @@ public static EntityTypeBuilder HasComment( /// A builder to further configure the entity type. public static EntityTypeBuilder HasComment( [NotNull] this EntityTypeBuilder entityTypeBuilder, - [CanBeNull] string comment) + [CanBeNull] string? comment) where TEntity : class => (EntityTypeBuilder)HasComment((EntityTypeBuilder)entityTypeBuilder, comment); @@ -1080,9 +1085,9 @@ public static EntityTypeBuilder HasComment( /// The same builder instance if the configuration was applied, /// otherwise. /// - public static IConventionEntityTypeBuilder HasComment( + public static IConventionEntityTypeBuilder? HasComment( [NotNull] this IConventionEntityTypeBuilder entityTypeBuilder, - [CanBeNull] string comment, + [CanBeNull] string? comment, bool fromDataAnnotation = false) { Check.NotNull(entityTypeBuilder, nameof(entityTypeBuilder)); @@ -1106,7 +1111,7 @@ public static IConventionEntityTypeBuilder HasComment( /// if the configuration can be applied. public static bool CanSetComment( [NotNull] this IConventionEntityTypeBuilder entityTypeBuilder, - [CanBeNull] string comment, + [CanBeNull] string? comment, bool fromDataAnnotation = false) => entityTypeBuilder.CanSetAnnotation( RelationalAnnotationNames.Comment, diff --git a/src/EFCore.Relational/Extensions/RelationalEntityTypeExtensions.cs b/src/EFCore.Relational/Extensions/RelationalEntityTypeExtensions.cs index 167f5cf906a..5fc70755186 100644 --- a/src/EFCore.Relational/Extensions/RelationalEntityTypeExtensions.cs +++ b/src/EFCore.Relational/Extensions/RelationalEntityTypeExtensions.cs @@ -10,6 +10,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Internal; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + // ReSharper disable once CheckNamespace namespace Microsoft.EntityFrameworkCore { @@ -24,7 +26,7 @@ public static class RelationalEntityTypeExtensions /// /// The entity type to get the table name for. /// The name of the table to which the entity type is mapped. - public static string GetTableName([NotNull] this IEntityType entityType) + public static string? GetTableName([NotNull] this IEntityType entityType) { var nameAnnotation = entityType.FindAnnotation(RelationalAnnotationNames.TableName); if (nameAnnotation != null) @@ -53,7 +55,7 @@ public static string GetTableName([NotNull] this IEntityType entityType) /// The entity type to get the table name for. /// A value indicating whether the name should be truncated to the max identifier length. /// The default name of the table to which the entity type would be mapped. - public static string GetDefaultTableName([NotNull] this IEntityType entityType, bool truncate = true) + public static string? GetDefaultTableName([NotNull] this IEntityType entityType, bool truncate = true) { var ownership = entityType.FindOwnership(); if (ownership != null @@ -66,7 +68,7 @@ public static string GetDefaultTableName([NotNull] this IEntityType entityType, if (entityType.HasSharedClrType && ownership != null #pragma warning disable EF1001 // Internal EF Core API usage. - && entityType.Name == ownership.PrincipalEntityType.GetOwnedName(name, ownership.PrincipalToDependent.Name)) + && entityType.Name == ownership.PrincipalEntityType.GetOwnedName(name, ownership.PrincipalToDependent!.Name)) #pragma warning restore EF1001 // Internal EF Core API usage. { var ownerTypeTable = ownership.PrincipalEntityType.GetTableName(); @@ -85,7 +87,7 @@ public static string GetDefaultTableName([NotNull] this IEntityType entityType, /// /// The entity type to set the table name for. /// The name to set. - public static void SetTableName([NotNull] this IMutableEntityType entityType, [CanBeNull] string name) + public static void SetTableName([NotNull] this IMutableEntityType entityType, [CanBeNull] string? name) => entityType.SetAnnotation( RelationalAnnotationNames.TableName, Check.NullButNotEmpty(name, nameof(name))); @@ -97,9 +99,9 @@ public static void SetTableName([NotNull] this IMutableEntityType entityType, [C /// The name to set. /// Indicates whether the configuration was specified using a data annotation. /// The configured table name. - public static string SetTableName( + public static string? SetTableName( [NotNull] this IConventionEntityType entityType, - [CanBeNull] string name, + [CanBeNull] string? name, bool fromDataAnnotation = false) { entityType.SetAnnotation( @@ -124,12 +126,12 @@ public static string SetTableName( /// /// The entity type to get the schema for. /// The database schema that contains the mapped table. - public static string GetSchema([NotNull] this IEntityType entityType) + public static string? GetSchema([NotNull] this IEntityType entityType) { var schemaAnnotation = entityType.FindAnnotation(RelationalAnnotationNames.Schema); if (schemaAnnotation != null) { - return (string)schemaAnnotation.Value ?? GetDefaultSchema(entityType); + return (string?)schemaAnnotation.Value ?? GetDefaultSchema(entityType); } return entityType.BaseType != null @@ -142,7 +144,7 @@ public static string GetSchema([NotNull] this IEntityType entityType) /// /// The entity type to get the schema for. /// The default database schema to which the entity type would be mapped. - public static string GetDefaultSchema([NotNull] this IEntityType entityType) + public static string? GetDefaultSchema([NotNull] this IEntityType entityType) { var ownership = entityType.FindOwnership(); if (ownership != null) @@ -169,7 +171,7 @@ public static string GetDefaultSchema([NotNull] this IEntityType entityType) /// /// The entity type to set the schema for. /// The value to set. - public static void SetSchema([NotNull] this IMutableEntityType entityType, [CanBeNull] string value) + public static void SetSchema([NotNull] this IMutableEntityType entityType, [CanBeNull] string? value) => entityType.SetAnnotation( RelationalAnnotationNames.Schema, Check.NullButNotEmpty(value, nameof(value))); @@ -181,9 +183,9 @@ public static void SetSchema([NotNull] this IMutableEntityType entityType, [CanB /// The value to set. /// Indicates whether the configuration was specified using a data annotation. /// The configured value. - public static string SetSchema( + public static string? SetSchema( [NotNull] this IConventionEntityType entityType, - [CanBeNull] string value, + [CanBeNull] string? value, bool fromDataAnnotation = false) { entityType.SetAnnotation( @@ -209,7 +211,7 @@ public static string SetSchema( /// /// The entity type to get the table name for. /// The name of the table to which the entity type is mapped prepended by the schema. - public static string GetSchemaQualifiedTableName([NotNull] this IEntityType entityType) + public static string? GetSchemaQualifiedTableName([NotNull] this IEntityType entityType) { var tableName = entityType.GetTableName(); if (tableName == null) @@ -227,7 +229,7 @@ public static string GetSchemaQualifiedTableName([NotNull] this IEntityType enti /// /// The entity type to get the table name for. /// The name of the table to which the entity type is mapped prepended by the schema. - public static string GetSchemaQualifiedViewName([NotNull] this IEntityType entityType) + public static string? GetSchemaQualifiedViewName([NotNull] this IEntityType entityType) { var viewName = entityType.GetViewName(); if (viewName == null) @@ -245,7 +247,7 @@ public static string GetSchemaQualifiedViewName([NotNull] this IEntityType entit /// The entity type to get the table mappings for. /// The tables to which the entity type is mapped. public static IEnumerable GetDefaultMappings([NotNull] this IEntityType entityType) - => (IEnumerable)entityType[RelationalAnnotationNames.DefaultMappings] + => (IEnumerable?)entityType[RelationalAnnotationNames.DefaultMappings] ?? Array.Empty(); /// @@ -254,7 +256,7 @@ public static IEnumerable GetDefaultMappings([NotNull] this I /// The entity type to get the table mappings for. /// The tables to which the entity type is mapped. public static IEnumerable GetTableMappings([NotNull] this IEntityType entityType) - => (IEnumerable)entityType[RelationalAnnotationNames.TableMappings] + => (IEnumerable?)entityType[RelationalAnnotationNames.TableMappings] ?? Array.Empty(); /// @@ -262,9 +264,9 @@ public static IEnumerable GetTableMappings([NotNull] this IEntity /// /// The entity type to get the view name for. /// The name of the view to which the entity type is mapped. - public static string GetViewName([NotNull] this IEntityType entityType) + public static string? GetViewName([NotNull] this IEntityType entityType) { - var nameAnnotation = (string)entityType[RelationalAnnotationNames.ViewName]; + var nameAnnotation = (string?)entityType[RelationalAnnotationNames.ViewName]; if (nameAnnotation != null) { return nameAnnotation; @@ -289,7 +291,7 @@ public static string GetViewName([NotNull] this IEntityType entityType) /// /// The entity type to get the table name for. /// The default name of the table to which the entity type would be mapped. - public static string GetDefaultViewName([NotNull] this IEntityType entityType) + public static string? GetDefaultViewName([NotNull] this IEntityType entityType) { var ownership = entityType.FindOwnership(); return ownership != null @@ -303,7 +305,7 @@ public static string GetDefaultViewName([NotNull] this IEntityType entityType) /// /// The entity type to set the view name for. /// The name to set. - public static void SetViewName([NotNull] this IMutableEntityType entityType, [CanBeNull] string name) + public static void SetViewName([NotNull] this IMutableEntityType entityType, [CanBeNull] string? name) => entityType.SetAnnotation( RelationalAnnotationNames.ViewName, Check.NullButNotEmpty(name, nameof(name))); @@ -315,9 +317,9 @@ public static void SetViewName([NotNull] this IMutableEntityType entityType, [Ca /// The name to set. /// Indicates whether the configuration was specified using a data annotation. /// The configured value. - public static string SetViewName( + public static string? SetViewName( [NotNull] this IConventionEntityType entityType, - [CanBeNull] string name, + [CanBeNull] string? name, bool fromDataAnnotation = false) { entityType.SetAnnotation( @@ -342,12 +344,12 @@ public static string SetViewName( /// /// The entity type to get the view schema for. /// The database schema that contains the mapped view. - public static string GetViewSchema([NotNull] this IEntityType entityType) + public static string? GetViewSchema([NotNull] this IEntityType entityType) { var schemaAnnotation = entityType.FindAnnotation(RelationalAnnotationNames.ViewSchema); if (schemaAnnotation != null) { - return (string)schemaAnnotation.Value ?? GetDefaultViewSchema(entityType); + return (string?)schemaAnnotation.Value ?? GetDefaultViewSchema(entityType); } return entityType.BaseType != null @@ -360,7 +362,7 @@ public static string GetViewSchema([NotNull] this IEntityType entityType) /// /// The entity type to get the view schema for. /// The default database schema to which the entity type would be mapped. - public static string GetDefaultViewSchema([NotNull] this IEntityType entityType) + public static string? GetDefaultViewSchema([NotNull] this IEntityType entityType) { var ownership = entityType.FindOwnership(); if (ownership != null @@ -377,7 +379,7 @@ public static string GetDefaultViewSchema([NotNull] this IEntityType entityType) /// /// The entity type to set the view schema for. /// The value to set. - public static void SetViewSchema([NotNull] this IMutableEntityType entityType, [CanBeNull] string value) + public static void SetViewSchema([NotNull] this IMutableEntityType entityType, [CanBeNull] string? value) => entityType.SetAnnotation( RelationalAnnotationNames.ViewSchema, Check.NullButNotEmpty(value, nameof(value))); @@ -389,9 +391,9 @@ public static void SetViewSchema([NotNull] this IMutableEntityType entityType, [ /// The value to set. /// Indicates whether the configuration was specified using a data annotation. /// The configured schema. - public static string SetViewSchema( + public static string? SetViewSchema( [NotNull] this IConventionEntityType entityType, - [CanBeNull] string value, + [CanBeNull] string? value, bool fromDataAnnotation = false) { entityType.SetAnnotation( @@ -417,7 +419,7 @@ public static string SetViewSchema( /// The entity type to get the view mappings for. /// The views to which the entity type is mapped. public static IEnumerable GetViewMappings([NotNull] this IEntityType entityType) - => (IEnumerable)entityType[RelationalAnnotationNames.ViewMappings] + => (IEnumerable?)entityType[RelationalAnnotationNames.ViewMappings] ?? Array.Empty(); /// @@ -434,9 +436,9 @@ public static string GetDefaultSqlQueryName([NotNull] this IEntityType entityTyp /// /// The entity type. /// The SQL string used to provide data for the entity type. - public static string GetSqlQuery([NotNull] this IEntityType entityType) + public static string? GetSqlQuery([NotNull] this IEntityType entityType) { - var nameAnnotation = (string)entityType[RelationalAnnotationNames.SqlQuery]; + var nameAnnotation = (string?)entityType[RelationalAnnotationNames.SqlQuery]; if (nameAnnotation != null) { return nameAnnotation; @@ -455,7 +457,7 @@ public static string GetSqlQuery([NotNull] this IEntityType entityType) /// /// The entity type. /// The SQL string to set. - public static void SetSqlQuery([NotNull] this IMutableEntityType entityType, [CanBeNull] string name) + public static void SetSqlQuery([NotNull] this IMutableEntityType entityType, [CanBeNull] string? name) => entityType.SetAnnotation( RelationalAnnotationNames.SqlQuery, Check.NullButNotEmpty(name, nameof(name))); @@ -467,11 +469,11 @@ public static void SetSqlQuery([NotNull] this IMutableEntityType entityType, [Ca /// The SQL string to set. /// Indicates whether the configuration was specified using a data annotation. /// The configured value. - public static string SetSqlQuery( + public static string? SetSqlQuery( [NotNull] this IConventionEntityType entityType, - [CanBeNull] string name, + [CanBeNull] string? name, bool fromDataAnnotation = false) - => (string)entityType.SetAnnotation( + => (string?)entityType.SetAnnotation( RelationalAnnotationNames.SqlQuery, Check.NullButNotEmpty(name, nameof(name)), fromDataAnnotation)?.Value; @@ -491,7 +493,7 @@ public static string SetSqlQuery( /// The entity type to get the function mappings for. /// The functions to which the entity type is mapped. public static IEnumerable GetSqlQueryMappings([NotNull] this IEntityType entityType) - => (IEnumerable)entityType[RelationalAnnotationNames.SqlQueryMappings] + => (IEnumerable?)entityType[RelationalAnnotationNames.SqlQueryMappings] ?? Array.Empty(); /// @@ -499,9 +501,9 @@ public static IEnumerable GetSqlQueryMappings([NotNull] this I /// /// The entity type to get the function name for. /// The name of the function to which the entity type is mapped. - public static string GetFunctionName([NotNull] this IEntityType entityType) + public static string? GetFunctionName([NotNull] this IEntityType entityType) { - var nameAnnotation = (string)entityType[RelationalAnnotationNames.FunctionName]; + var nameAnnotation = (string?)entityType[RelationalAnnotationNames.FunctionName]; if (nameAnnotation != null) { return nameAnnotation; @@ -520,7 +522,7 @@ public static string GetFunctionName([NotNull] this IEntityType entityType) /// /// The entity type to set the function name for. /// The name to set. - public static void SetFunctionName([NotNull] this IMutableEntityType entityType, [CanBeNull] string name) + public static void SetFunctionName([NotNull] this IMutableEntityType entityType, [CanBeNull] string? name) => entityType.SetAnnotation( RelationalAnnotationNames.FunctionName, Check.NullButNotEmpty(name, nameof(name))); @@ -532,11 +534,11 @@ public static void SetFunctionName([NotNull] this IMutableEntityType entityType, /// The name to set. /// Indicates whether the configuration was specified using a data annotation. /// The configured value. - public static string SetFunctionName( + public static string? SetFunctionName( [NotNull] this IConventionEntityType entityType, - [CanBeNull] string name, + [CanBeNull] string? name, bool fromDataAnnotation = false) - => (string)entityType.SetAnnotation( + => (string?)entityType.SetAnnotation( RelationalAnnotationNames.ViewName, Check.NullButNotEmpty(name, nameof(name)), fromDataAnnotation)?.Value; @@ -556,7 +558,7 @@ public static string SetFunctionName( /// The entity type to get the function mappings for. /// The functions to which the entity type is mapped. public static IEnumerable GetFunctionMappings([NotNull] this IEntityType entityType) - => (IEnumerable)entityType[RelationalAnnotationNames.FunctionMappings] + => (IEnumerable?)entityType[RelationalAnnotationNames.FunctionMappings] ?? Array.Empty(); /// @@ -568,7 +570,7 @@ public static IEnumerable GetFunctionMappings([NotNull] this I /// The or if no check constraint with the /// given name in the given entity type was found. /// - public static ICheckConstraint FindCheckConstraint( + public static ICheckConstraint? FindCheckConstraint( [NotNull] this IEntityType entityType, [NotNull] string name) { @@ -586,10 +588,10 @@ public static ICheckConstraint FindCheckConstraint( /// The or if no check constraint with the /// given name in the given entity type was found. /// - public static IMutableCheckConstraint FindCheckConstraint( + public static IMutableCheckConstraint? FindCheckConstraint( [NotNull] this IMutableEntityType entityType, [NotNull] string name) - => (IMutableCheckConstraint)((IEntityType)entityType).FindCheckConstraint(name); + => (IMutableCheckConstraint?)((IEntityType)entityType).FindCheckConstraint(name); /// /// Finds an with the given name. @@ -600,10 +602,10 @@ public static IMutableCheckConstraint FindCheckConstraint( /// The or if no check constraint with the /// given name in the given entity type was found. /// - public static IConventionCheckConstraint FindCheckConstraint( + public static IConventionCheckConstraint? FindCheckConstraint( [NotNull] this IConventionEntityType entityType, [NotNull] string name) - => (IConventionCheckConstraint)((IEntityType)entityType).FindCheckConstraint(name); + => (IConventionCheckConstraint?)((IEntityType)entityType).FindCheckConstraint(name); /// /// Creates a new check constraint with the given name on entity type. Throws an exception @@ -653,7 +655,7 @@ public static IConventionCheckConstraint AddCheckConstraint( /// The entity type to remove the check constraint from. /// The check constraint name to be removed. /// The removed . - public static IMutableCheckConstraint RemoveCheckConstraint( + public static IMutableCheckConstraint? RemoveCheckConstraint( [NotNull] this IMutableEntityType entityType, [NotNull] string name) => CheckConstraint.RemoveCheckConstraint(entityType, Check.NotEmpty(name, nameof(name))); @@ -664,7 +666,7 @@ public static IMutableCheckConstraint RemoveCheckConstraint( /// The entity type to remove the check constraint from. /// The check constraint name. /// The removed . - public static IConventionCheckConstraint RemoveCheckConstraint( + public static IConventionCheckConstraint? RemoveCheckConstraint( [NotNull] this IConventionEntityType entityType, [NotNull] string name) => CheckConstraint.RemoveCheckConstraint((IMutableEntityType)entityType, Check.NotEmpty(name, nameof(name))); @@ -695,15 +697,15 @@ public static IEnumerable GetCheckConstraints([NotNu /// /// The entity type. /// The comment for the table this entity is mapped to. - public static string GetComment([NotNull] this IEntityType entityType) - => (string)entityType[RelationalAnnotationNames.Comment]; + public static string? GetComment([NotNull] this IEntityType entityType) + => (string?)entityType[RelationalAnnotationNames.Comment]; /// /// Configures a comment to be applied to the table this entity is mapped to. /// /// The entity type. /// The comment for the table this entity is mapped to. - public static void SetComment([NotNull] this IMutableEntityType entityType, [CanBeNull] string comment) + public static void SetComment([NotNull] this IMutableEntityType entityType, [CanBeNull] string? comment) => entityType.SetOrRemoveAnnotation(RelationalAnnotationNames.Comment, comment); /// @@ -713,9 +715,9 @@ public static void SetComment([NotNull] this IMutableEntityType entityType, [Can /// The comment for the table. /// Indicates whether the configuration was specified using a data annotation. /// The configured comment. - public static string SetComment( + public static string? SetComment( [NotNull] this IConventionEntityType entityType, - [CanBeNull] string comment, + [CanBeNull] string? comment, bool fromDataAnnotation = false) { entityType.SetOrRemoveAnnotation(RelationalAnnotationNames.Comment, comment, fromDataAnnotation); diff --git a/src/EFCore.Relational/Extensions/RelationalForeignKeyBuilderExtensions.cs b/src/EFCore.Relational/Extensions/RelationalForeignKeyBuilderExtensions.cs index e625097acf9..ab2bed2c9ed 100644 --- a/src/EFCore.Relational/Extensions/RelationalForeignKeyBuilderExtensions.cs +++ b/src/EFCore.Relational/Extensions/RelationalForeignKeyBuilderExtensions.cs @@ -6,6 +6,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + // ReSharper disable once CheckNamespace namespace Microsoft.EntityFrameworkCore { @@ -22,7 +24,7 @@ public static class RelationalForeignKeyBuilderExtensions /// The same builder instance so that multiple calls can be chained. public static ReferenceCollectionBuilder HasConstraintName( [NotNull] this ReferenceCollectionBuilder referenceCollectionBuilder, - [CanBeNull] string name) + [CanBeNull] string? name) { Check.NotNull(referenceCollectionBuilder, nameof(referenceCollectionBuilder)); Check.NullButNotEmpty(name, nameof(name)); @@ -42,7 +44,7 @@ public static ReferenceCollectionBuilder HasConstraintName( /// The dependent entity type in this relationship. public static ReferenceCollectionBuilder HasConstraintName( [NotNull] this ReferenceCollectionBuilder referenceCollectionBuilder, - [CanBeNull] string name) + [CanBeNull] string? name) where TEntity : class where TRelatedEntity : class => (ReferenceCollectionBuilder)HasConstraintName( @@ -56,7 +58,7 @@ public static ReferenceCollectionBuilder HasConstraintN /// The same builder instance so that multiple calls can be chained. public static ReferenceReferenceBuilder HasConstraintName( [NotNull] this ReferenceReferenceBuilder referenceReferenceBuilder, - [CanBeNull] string name) + [CanBeNull] string? name) { Check.NotNull(referenceReferenceBuilder, nameof(referenceReferenceBuilder)); Check.NullButNotEmpty(name, nameof(name)); @@ -76,7 +78,7 @@ public static ReferenceReferenceBuilder HasConstraintName( /// The entity type on the other end of the relationship. public static ReferenceReferenceBuilder HasConstraintName( [NotNull] this ReferenceReferenceBuilder referenceReferenceBuilder, - [CanBeNull] string name) + [CanBeNull] string? name) where TEntity : class where TRelatedEntity : class => (ReferenceReferenceBuilder)HasConstraintName( @@ -90,7 +92,7 @@ public static ReferenceReferenceBuilder HasConstraintNa /// The same builder instance so that multiple calls can be chained. public static OwnershipBuilder HasConstraintName( [NotNull] this OwnershipBuilder ownershipBuilder, - [CanBeNull] string name) + [CanBeNull] string? name) { Check.NullButNotEmpty(name, nameof(name)); @@ -109,7 +111,7 @@ public static OwnershipBuilder HasConstraintName( /// The entity type on the other end of the relationship. public static OwnershipBuilder HasConstraintName( [NotNull] this OwnershipBuilder ownershipBuilder, - [CanBeNull] string name) + [CanBeNull] string? name) where TEntity : class where TDependentEntity : class => (OwnershipBuilder)HasConstraintName( @@ -125,9 +127,9 @@ public static OwnershipBuilder HasConstraintName otherwise. /// - public static IConventionForeignKeyBuilder HasConstraintName( + public static IConventionForeignKeyBuilder? HasConstraintName( [NotNull] this IConventionForeignKeyBuilder relationship, - [CanBeNull] string name, + [CanBeNull] string? name, bool fromDataAnnotation = false) { if (!relationship.CanSetConstraintName(name, fromDataAnnotation)) @@ -149,7 +151,7 @@ public static IConventionForeignKeyBuilder HasConstraintName( /// if the configuration can be applied. public static bool CanSetConstraintName( [NotNull] this IConventionForeignKeyBuilder relationship, - [CanBeNull] string name, + [CanBeNull] string? name, bool fromDataAnnotation = false) => Check.NotNull(relationship, nameof(relationship)) .CanSetAnnotation(RelationalAnnotationNames.Name, name, fromDataAnnotation); diff --git a/src/EFCore.Relational/Extensions/RelationalForeignKeyExtensions.cs b/src/EFCore.Relational/Extensions/RelationalForeignKeyExtensions.cs index 726191d1889..c7d1d611c38 100644 --- a/src/EFCore.Relational/Extensions/RelationalForeignKeyExtensions.cs +++ b/src/EFCore.Relational/Extensions/RelationalForeignKeyExtensions.cs @@ -9,6 +9,8 @@ using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + // ReSharper disable once CheckNamespace namespace Microsoft.EntityFrameworkCore { @@ -37,7 +39,7 @@ public static string GetConstraintName([NotNull] this IForeignKey foreignKey) /// The identifier of the containing store object. /// The identifier of the principal store object. /// The foreign key constraint name. - public static string GetConstraintName( + public static string? GetConstraintName( [NotNull] this IForeignKey foreignKey, in StoreObjectIdentifier storeObject, in StoreObjectIdentifier principalStoreObject) @@ -78,7 +80,7 @@ public static string GetDefaultName([NotNull] this IForeignKey foreignKey) /// The identifier of the containing store object. /// The identifier of the principal store object. /// The default constraint name that would be used for this foreign key. - public static string GetDefaultName( + public static string? GetDefaultName( [NotNull] this IForeignKey foreignKey, in StoreObjectIdentifier storeObject, in StoreObjectIdentifier principalStoreObject) @@ -97,7 +99,7 @@ public static string GetDefaultName( // Using a hashset is detrimental to the perf when there are no cycles for (var i = 0; i < Metadata.Internal.RelationalEntityTypeExtensions.MaxEntityTypesSharingTable; i++) { - IForeignKey linkedForeignKey = null; + IForeignKey? linkedForeignKey = null; foreach (var otherForeignKey in rootForeignKey.DeclaringEntityType .FindRowInternalForeignKeys(storeObject) .SelectMany(fk => fk.PrincipalEntityType.GetForeignKeys())) @@ -148,7 +150,7 @@ public static string GetDefaultName( /// /// The foreign key. /// The value to set. - public static void SetConstraintName([NotNull] this IMutableForeignKey foreignKey, [CanBeNull] string value) + public static void SetConstraintName([NotNull] this IMutableForeignKey foreignKey, [CanBeNull] string? value) => foreignKey.SetOrRemoveAnnotation( RelationalAnnotationNames.Name, Check.NullButNotEmpty(value, nameof(value))); @@ -160,9 +162,9 @@ public static void SetConstraintName([NotNull] this IMutableForeignKey foreignKe /// The value to set. /// Indicates whether the configuration was specified using a data annotation. /// The configured name. - public static string SetConstraintName( + public static string? SetConstraintName( [NotNull] this IConventionForeignKey foreignKey, - [CanBeNull] string value, + [CanBeNull] string? value, bool fromDataAnnotation = false) { foreignKey.SetOrRemoveAnnotation( @@ -188,7 +190,7 @@ public static string SetConstraintName( /// The foreign key. /// The foreign key constraints to which the foreign key is mapped. public static IEnumerable GetMappedConstraints([NotNull] this IForeignKey foreignKey) - => (IEnumerable)foreignKey[RelationalAnnotationNames.ForeignKeyMappings] + => (IEnumerable?)foreignKey[RelationalAnnotationNames.ForeignKeyMappings] ?? Enumerable.Empty(); /// @@ -203,7 +205,7 @@ public static IEnumerable GetMappedConstraints([NotNull] /// The foreign key. /// The identifier of the containing store object. /// The foreign key if found, or if none was found. - public static IForeignKey FindSharedObjectRootForeignKey( + public static IForeignKey? FindSharedObjectRootForeignKey( [NotNull] this IForeignKey foreignKey, in StoreObjectIdentifier storeObject) { @@ -211,14 +213,14 @@ public static IForeignKey FindSharedObjectRootForeignKey( var foreignKeyName = foreignKey.GetConstraintName( storeObject, - StoreObjectIdentifier.Table(foreignKey.PrincipalEntityType.GetTableName(), foreignKey.PrincipalEntityType.GetSchema())); + StoreObjectIdentifier.Table(foreignKey.PrincipalEntityType.GetTableName()!, foreignKey.PrincipalEntityType.GetSchema())); var rootForeignKey = foreignKey; // Limit traversal to avoid getting stuck in a cycle (validation will throw for these later) // Using a hashset is detrimental to the perf when there are no cycles for (var i = 0; i < Metadata.Internal.RelationalEntityTypeExtensions.MaxEntityTypesSharingTable; i++) { - IForeignKey linkedForeignKey = null; + IForeignKey? linkedForeignKey = null; foreach (var otherForeignKey in rootForeignKey.DeclaringEntityType .FindRowInternalForeignKeys(storeObject) .SelectMany(fk => fk.PrincipalEntityType.GetForeignKeys())) @@ -226,7 +228,7 @@ public static IForeignKey FindSharedObjectRootForeignKey( if (otherForeignKey.GetConstraintName( storeObject, StoreObjectIdentifier.Table( - otherForeignKey.PrincipalEntityType.GetTableName(), + otherForeignKey.PrincipalEntityType.GetTableName()!, otherForeignKey.PrincipalEntityType.GetSchema())) == foreignKeyName) { @@ -258,10 +260,10 @@ public static IForeignKey FindSharedObjectRootForeignKey( /// The foreign key. /// The identifier of the containing store object. /// The foreign key if found, or if none was found. - public static IMutableForeignKey FindSharedObjectRootForeignKey( + public static IMutableForeignKey? FindSharedObjectRootForeignKey( [NotNull] this IMutableForeignKey foreignKey, in StoreObjectIdentifier storeObject) - => (IMutableForeignKey)((IForeignKey)foreignKey).FindSharedObjectRootForeignKey(storeObject); + => (IMutableForeignKey?)((IForeignKey)foreignKey).FindSharedObjectRootForeignKey(storeObject); /// /// @@ -275,9 +277,9 @@ public static IMutableForeignKey FindSharedObjectRootForeignKey( /// The foreign key. /// The identifier of the containing store object. /// The foreign key if found, or if none was found. - public static IConventionForeignKey FindSharedObjectRootForeignKey( + public static IConventionForeignKey? FindSharedObjectRootForeignKey( [NotNull] this IConventionForeignKey foreignKey, in StoreObjectIdentifier storeObject) - => (IConventionForeignKey)((IForeignKey)foreignKey).FindSharedObjectRootForeignKey(storeObject); + => (IConventionForeignKey?)((IForeignKey)foreignKey).FindSharedObjectRootForeignKey(storeObject); } } diff --git a/src/EFCore.Relational/Extensions/RelationalIndexBuilderExtensions.cs b/src/EFCore.Relational/Extensions/RelationalIndexBuilderExtensions.cs index 6a7da9f78f2..b3e06cd5f20 100644 --- a/src/EFCore.Relational/Extensions/RelationalIndexBuilderExtensions.cs +++ b/src/EFCore.Relational/Extensions/RelationalIndexBuilderExtensions.cs @@ -7,6 +7,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + // ReSharper disable once CheckNamespace namespace Microsoft.EntityFrameworkCore { @@ -21,7 +23,7 @@ public static class RelationalIndexBuilderExtensions /// The builder for the index being configured. /// The name of the index. /// A builder to further configure the index. - public static IndexBuilder HasDatabaseName([NotNull] this IndexBuilder indexBuilder, [CanBeNull] string name) + public static IndexBuilder HasDatabaseName([NotNull] this IndexBuilder indexBuilder, [CanBeNull] string? name) { indexBuilder.Metadata.SetDatabaseName(name); @@ -35,7 +37,7 @@ public static IndexBuilder HasDatabaseName([NotNull] this IndexBuilder indexBuil /// The name of the index. /// A builder to further configure the index. [Obsolete("Use HasDatabaseName() instead.")] - public static IndexBuilder HasName([NotNull] this IndexBuilder indexBuilder, [CanBeNull] string name) + public static IndexBuilder HasName([NotNull] this IndexBuilder indexBuilder, [CanBeNull] string? name) => HasDatabaseName(indexBuilder, name); /// @@ -47,7 +49,7 @@ public static IndexBuilder HasName([NotNull] this IndexBuilder indexBuilder, [Ca /// A builder to further configure the index. public static IndexBuilder HasDatabaseName( [NotNull] this IndexBuilder indexBuilder, - [CanBeNull] string name) + [CanBeNull] string? name) { indexBuilder.Metadata.SetDatabaseName(name); @@ -62,7 +64,7 @@ public static IndexBuilder HasDatabaseName( /// The name of the index. /// A builder to further configure the index. [Obsolete("Use HasDatabaseName() instead.")] - public static IndexBuilder HasName([NotNull] this IndexBuilder indexBuilder, [CanBeNull] string name) + public static IndexBuilder HasName([NotNull] this IndexBuilder indexBuilder, [CanBeNull] string? name) => indexBuilder.HasDatabaseName(name); /// @@ -75,9 +77,9 @@ public static IndexBuilder HasName([NotNull] this IndexBuilder /// The same builder instance if the configuration was applied, /// otherwise. /// - public static IConventionIndexBuilder HasDatabaseName( + public static IConventionIndexBuilder? HasDatabaseName( [NotNull] this IConventionIndexBuilder indexBuilder, - [CanBeNull] string name, + [CanBeNull] string? name, bool fromDataAnnotation = false) { if (indexBuilder.CanSetDatabaseName(name, fromDataAnnotation)) @@ -100,9 +102,9 @@ public static IConventionIndexBuilder HasDatabaseName( /// otherwise. /// [Obsolete("Use HasDatabaseName() instead.")] - public static IConventionIndexBuilder HasName( + public static IConventionIndexBuilder? HasName( [NotNull] this IConventionIndexBuilder indexBuilder, - [CanBeNull] string name, + [CanBeNull] string? name, bool fromDataAnnotation = false) => indexBuilder.HasDatabaseName(name, fromDataAnnotation); @@ -115,7 +117,7 @@ public static IConventionIndexBuilder HasName( /// if the given name can be set for the index. public static bool CanSetDatabaseName( [NotNull] this IConventionIndexBuilder indexBuilder, - [CanBeNull] string name, + [CanBeNull] string? name, bool fromDataAnnotation = false) => indexBuilder.CanSetAnnotation(RelationalAnnotationNames.Name, name, fromDataAnnotation); @@ -129,7 +131,7 @@ public static bool CanSetDatabaseName( [Obsolete("Use CanSetDatabaseName() instead.")] public static bool CanSetName( [NotNull] this IConventionIndexBuilder indexBuilder, - [CanBeNull] string name, + [CanBeNull] string? name, bool fromDataAnnotation = false) => CanSetDatabaseName(indexBuilder, name, fromDataAnnotation); @@ -139,7 +141,7 @@ public static bool CanSetName( /// The builder for the index being configured. /// The filter expression for the index. /// A builder to further configure the index. - public static IndexBuilder HasFilter([NotNull] this IndexBuilder indexBuilder, [CanBeNull] string sql) + public static IndexBuilder HasFilter([NotNull] this IndexBuilder indexBuilder, [CanBeNull] string? sql) { Check.NotNull(indexBuilder, nameof(indexBuilder)); Check.NullButNotEmpty(sql, nameof(sql)); @@ -156,7 +158,7 @@ public static IndexBuilder HasFilter([NotNull] this IndexBuilder indexBuilder, [ /// The builder for the index being configured. /// The filter expression for the index. /// A builder to further configure the index. - public static IndexBuilder HasFilter([NotNull] this IndexBuilder indexBuilder, [CanBeNull] string sql) + public static IndexBuilder HasFilter([NotNull] this IndexBuilder indexBuilder, [CanBeNull] string? sql) => (IndexBuilder)HasFilter((IndexBuilder)indexBuilder, sql); /// @@ -169,9 +171,9 @@ public static IndexBuilder HasFilter([NotNull] this IndexBuild /// The same builder instance if the configuration was applied, /// otherwise. /// - public static IConventionIndexBuilder HasFilter( + public static IConventionIndexBuilder? HasFilter( [NotNull] this IConventionIndexBuilder indexBuilder, - [CanBeNull] string sql, + [CanBeNull] string? sql, bool fromDataAnnotation = false) { if (indexBuilder.CanSetFilter(sql, fromDataAnnotation)) @@ -192,7 +194,7 @@ public static IConventionIndexBuilder HasFilter( /// if the given name can be set for the index. public static bool CanSetFilter( [NotNull] this IConventionIndexBuilder indexBuilder, - [CanBeNull] string sql, + [CanBeNull] string? sql, bool fromDataAnnotation = false) => indexBuilder.CanSetAnnotation(RelationalAnnotationNames.Filter, sql, fromDataAnnotation); } diff --git a/src/EFCore.Relational/Extensions/RelationalIndexExtensions.cs b/src/EFCore.Relational/Extensions/RelationalIndexExtensions.cs index ec4fcab8cf1..1f8ad74164a 100644 --- a/src/EFCore.Relational/Extensions/RelationalIndexExtensions.cs +++ b/src/EFCore.Relational/Extensions/RelationalIndexExtensions.cs @@ -10,6 +10,8 @@ using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + // ReSharper disable once CheckNamespace namespace Microsoft.EntityFrameworkCore { @@ -24,7 +26,7 @@ public static class RelationalIndexExtensions /// The index. /// The name of the index in the database. public static string GetDatabaseName([NotNull] this IIndex index) - => (string)index[RelationalAnnotationNames.Name] + => (string?)index[RelationalAnnotationNames.Name] ?? index.Name ?? index.GetDefaultDatabaseName(); @@ -43,8 +45,8 @@ public static string GetName([NotNull] this IIndex index) /// The index. /// The identifier of the store object. /// The name of the index in the database. - public static string GetDatabaseName([NotNull] this IIndex index, in StoreObjectIdentifier storeObject) - => (string)index[RelationalAnnotationNames.Name] + public static string? GetDatabaseName([NotNull] this IIndex index, in StoreObjectIdentifier storeObject) + => (string?)index[RelationalAnnotationNames.Name] ?? index.Name ?? index.GetDefaultDatabaseName(storeObject); @@ -82,7 +84,7 @@ public static string GetDefaultName([NotNull] this IIndex index) /// The index. /// The identifier of the store object. /// The default name that would be used for this index. - public static string GetDefaultDatabaseName([NotNull] this IIndex index, in StoreObjectIdentifier storeObject) + public static string? GetDefaultDatabaseName([NotNull] this IIndex index, in StoreObjectIdentifier storeObject) { var columnNames = index.Properties.GetColumnNames(storeObject); if (columnNames == null) @@ -96,7 +98,7 @@ public static string GetDefaultDatabaseName([NotNull] this IIndex index, in Stor // Using a hashset is detrimental to the perf when there are no cycles for (var i = 0; i < Metadata.Internal.RelationalEntityTypeExtensions.MaxEntityTypesSharingTable; i++) { - IIndex linkedIndex = null; + IIndex? linkedIndex = null; foreach (var otherIndex in rootIndex.DeclaringEntityType .FindRowInternalForeignKeys(storeObject) .SelectMany(fk => fk.PrincipalEntityType.GetIndexes())) @@ -138,7 +140,7 @@ public static string GetDefaultDatabaseName([NotNull] this IIndex index, in Stor /// /// The index. /// The value to set. - public static void SetDatabaseName([NotNull] this IMutableIndex index, [CanBeNull] string name) + public static void SetDatabaseName([NotNull] this IMutableIndex index, [CanBeNull] string? name) { index.SetOrRemoveAnnotation( RelationalAnnotationNames.Name, @@ -151,7 +153,7 @@ public static void SetDatabaseName([NotNull] this IMutableIndex index, [CanBeNul /// The index. /// The value to set. [Obsolete("Use SetDatabaseName() instead.")] - public static void SetName([NotNull] this IMutableIndex index, [CanBeNull] string name) + public static void SetName([NotNull] this IMutableIndex index, [CanBeNull] string? name) => SetDatabaseName(index, name); /// @@ -161,9 +163,9 @@ public static void SetName([NotNull] this IMutableIndex index, [CanBeNull] strin /// The value to set. /// Indicates whether the configuration was specified using a data annotation. /// The configured value. - public static string SetDatabaseName( + public static string? SetDatabaseName( [NotNull] this IConventionIndex index, - [CanBeNull] string name, + [CanBeNull] string? name, bool fromDataAnnotation = false) { index.SetOrRemoveAnnotation( @@ -181,7 +183,7 @@ public static string SetDatabaseName( /// The value to set. /// Indicates whether the configuration was specified using a data annotation. [Obsolete("Use SetDatabaseName() instead.")] - public static void SetName([NotNull] this IConventionIndex index, [CanBeNull] string name, bool fromDataAnnotation = false) + public static void SetName([NotNull] this IConventionIndex index, [CanBeNull] string? name, bool fromDataAnnotation = false) => SetDatabaseName(index, name, fromDataAnnotation); /// @@ -206,11 +208,8 @@ public static void SetName([NotNull] this IConventionIndex index, [CanBeNull] st /// /// The index. /// The index filter expression. - public static string GetFilter([NotNull] this IIndex index) - { - var annotation = index.FindAnnotation(RelationalAnnotationNames.Filter); - return annotation != null ? (string)annotation.Value : null; - } + public static string? GetFilter([NotNull] this IIndex index) + => (string?)index.FindAnnotation(RelationalAnnotationNames.Filter)?.Value; /// /// Returns the index filter expression. @@ -218,7 +217,7 @@ public static string GetFilter([NotNull] this IIndex index) /// The index. /// The identifier of the containing store object. /// The index filter expression. - public static string GetFilter([NotNull] this IIndex index, in StoreObjectIdentifier storeObject) + public static string? GetFilter([NotNull] this IIndex index, in StoreObjectIdentifier storeObject) { var annotation = index.FindAnnotation(RelationalAnnotationNames.Filter); if (annotation != null) @@ -235,7 +234,7 @@ public static string GetFilter([NotNull] this IIndex index, in StoreObjectIdenti /// /// The index. /// The value to set. - public static void SetFilter([NotNull] this IMutableIndex index, [CanBeNull] string value) + public static void SetFilter([NotNull] this IMutableIndex index, [CanBeNull] string? value) => index.SetAnnotation( RelationalAnnotationNames.Filter, Check.NullButNotEmpty(value, nameof(value))); @@ -247,7 +246,7 @@ public static void SetFilter([NotNull] this IMutableIndex index, [CanBeNull] str /// The value to set. /// Indicates whether the configuration was specified using a data annotation. /// The configured value. - public static string SetFilter([NotNull] this IConventionIndex index, [CanBeNull] string value, bool fromDataAnnotation = false) + public static string? SetFilter([NotNull] this IConventionIndex index, [CanBeNull] string? value, bool fromDataAnnotation = false) { index.SetAnnotation( RelationalAnnotationNames.Filter, @@ -271,7 +270,7 @@ public static string SetFilter([NotNull] this IConventionIndex index, [CanBeNull /// The index. /// The table indexes to which the index is mapped. public static IEnumerable GetMappedTableIndexes([NotNull] this IIndex index) - => (IEnumerable)index[RelationalAnnotationNames.TableIndexMappings] + => (IEnumerable?)index[RelationalAnnotationNames.TableIndexMappings] ?? Enumerable.Empty(); /// @@ -286,7 +285,7 @@ public static IEnumerable GetMappedTableIndexes([NotNull] this IInd /// The index. /// The identifier of the containing store object. /// The index found, or if none was found. - public static IIndex FindSharedObjectRootIndex([NotNull] this IIndex index, in StoreObjectIdentifier storeObject) + public static IIndex? FindSharedObjectRootIndex([NotNull] this IIndex index, in StoreObjectIdentifier storeObject) { Check.NotNull(index, nameof(index)); @@ -297,7 +296,7 @@ public static IIndex FindSharedObjectRootIndex([NotNull] this IIndex index, in S // Using a hashset is detrimental to the perf when there are no cycles for (var i = 0; i < Metadata.Internal.RelationalEntityTypeExtensions.MaxEntityTypesSharingTable; i++) { - IIndex linkedIndex = null; + IIndex? linkedIndex = null; foreach (var otherIndex in rootIndex.DeclaringEntityType .FindRowInternalForeignKeys(storeObject) .SelectMany(fk => fk.PrincipalEntityType.GetIndexes())) @@ -332,10 +331,10 @@ public static IIndex FindSharedObjectRootIndex([NotNull] this IIndex index, in S /// The index. /// The identifier of the containing store object. /// The index found, or if none was found. - public static IMutableIndex FindSharedObjectRootIndex( + public static IMutableIndex? FindSharedObjectRootIndex( [NotNull] this IMutableIndex index, in StoreObjectIdentifier storeObject) - => (IMutableIndex)((IIndex)index).FindSharedObjectRootIndex(storeObject); + => (IMutableIndex?)((IIndex)index).FindSharedObjectRootIndex(storeObject); /// /// @@ -349,9 +348,9 @@ public static IMutableIndex FindSharedObjectRootIndex( /// The index. /// The identifier of the containing store object. /// The index found, or if none was found. - public static IConventionIndex FindSharedObjectRootIndex( + public static IConventionIndex? FindSharedObjectRootIndex( [NotNull] this IConventionIndex index, in StoreObjectIdentifier storeObject) - => (IConventionIndex)((IIndex)index).FindSharedObjectRootIndex(storeObject); + => (IConventionIndex?)((IIndex)index).FindSharedObjectRootIndex(storeObject); } } diff --git a/src/EFCore.Relational/Extensions/RelationalKeyBuilderExtensions.cs b/src/EFCore.Relational/Extensions/RelationalKeyBuilderExtensions.cs index 3a931fd5644..8968164cc21 100644 --- a/src/EFCore.Relational/Extensions/RelationalKeyBuilderExtensions.cs +++ b/src/EFCore.Relational/Extensions/RelationalKeyBuilderExtensions.cs @@ -6,6 +6,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + // ReSharper disable once CheckNamespace namespace Microsoft.EntityFrameworkCore { @@ -20,7 +22,7 @@ public static class RelationalKeyBuilderExtensions /// The builder for the key being configured. /// The name of the key. /// The same builder instance so that multiple calls can be chained. - public static KeyBuilder HasName([NotNull] this KeyBuilder keyBuilder, [CanBeNull] string name) + public static KeyBuilder HasName([NotNull] this KeyBuilder keyBuilder, [CanBeNull] string? name) { Check.NotNull(keyBuilder, nameof(keyBuilder)); Check.NullButNotEmpty(name, nameof(name)); @@ -38,7 +40,7 @@ public static KeyBuilder HasName([NotNull] this KeyBuilder keyBuilder, [CanBeNul /// The same builder instance so that multiple calls can be chained. public static KeyBuilder HasName( [NotNull] this KeyBuilder keyBuilder, - [CanBeNull] string name) + [CanBeNull] string? name) => (KeyBuilder)HasName((KeyBuilder)keyBuilder, name); /// @@ -51,9 +53,9 @@ public static KeyBuilder HasName( /// The same builder instance if the configuration was applied, /// otherwise. /// - public static IConventionKeyBuilder HasName( + public static IConventionKeyBuilder? HasName( [NotNull] this IConventionKeyBuilder keyBuilder, - [CanBeNull] string name, + [CanBeNull] string? name, bool fromDataAnnotation = false) { if (keyBuilder.CanSetName(name, fromDataAnnotation)) @@ -74,7 +76,7 @@ public static IConventionKeyBuilder HasName( /// if the given name can be set for the key constraint. public static bool CanSetName( [NotNull] this IConventionKeyBuilder keyBuilder, - [CanBeNull] string name, + [CanBeNull] string? name, bool fromDataAnnotation = false) => keyBuilder.CanSetAnnotation(RelationalAnnotationNames.Name, name, fromDataAnnotation); } diff --git a/src/EFCore.Relational/Extensions/RelationalKeyExtensions.cs b/src/EFCore.Relational/Extensions/RelationalKeyExtensions.cs index 30a3fc47244..90b87736472 100644 --- a/src/EFCore.Relational/Extensions/RelationalKeyExtensions.cs +++ b/src/EFCore.Relational/Extensions/RelationalKeyExtensions.cs @@ -9,6 +9,8 @@ using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + // ReSharper disable once CheckNamespace namespace Microsoft.EntityFrameworkCore { @@ -22,8 +24,8 @@ public static class RelationalKeyExtensions /// /// The key. /// The key constraint name for this key. - public static string GetName([NotNull] this IKey key) - => key.GetName(StoreObjectIdentifier.Table(key.DeclaringEntityType.GetTableName(), key.DeclaringEntityType.GetSchema())); + public static string? GetName([NotNull] this IKey key) + => key.GetName(StoreObjectIdentifier.Table(key.DeclaringEntityType.GetTableName()!, key.DeclaringEntityType.GetSchema())); /// /// Returns the key constraint name for this key for a particular table. @@ -31,8 +33,8 @@ public static string GetName([NotNull] this IKey key) /// The key. /// The identifier of the containing store object. /// The key constraint name for this key. - public static string GetName([NotNull] this IKey key, in StoreObjectIdentifier storeObject) - => (string)key[RelationalAnnotationNames.Name] + public static string? GetName([NotNull] this IKey key, in StoreObjectIdentifier storeObject) + => (string?)key[RelationalAnnotationNames.Name] ?? key.GetDefaultName(storeObject); /// @@ -42,21 +44,15 @@ public static string GetName([NotNull] this IKey key, in StoreObjectIdentifier s /// The default key constraint name that would be used for this key. public static string GetDefaultName([NotNull] this IKey key) { - string name = null; var tableName = key.DeclaringEntityType.GetTableName(); - if (key.IsPrimaryKey()) - { - name = "PK_" + tableName; - } - else - { - name = new StringBuilder() + var name = key.IsPrimaryKey() + ? "PK_" + tableName + : new StringBuilder() .Append("AK_") .Append(tableName) .Append("_") .AppendJoin(key.Properties.Select(p => p.GetColumnBaseName()), "_") .ToString(); - } return Uniquifier.Truncate(name, key.DeclaringEntityType.Model.GetMaxIdentifierLength()); } @@ -67,9 +63,9 @@ public static string GetDefaultName([NotNull] this IKey key) /// The key. /// The identifier of the containing store object. /// The default key constraint name that would be used for this key. - public static string GetDefaultName([NotNull] this IKey key, in StoreObjectIdentifier storeObject) + public static string? GetDefaultName([NotNull] this IKey key, in StoreObjectIdentifier storeObject) { - string name = null; + string? name; if (key.IsPrimaryKey()) { var rootKey = key; @@ -77,7 +73,7 @@ public static string GetDefaultName([NotNull] this IKey key, in StoreObjectIdent // Using a hashset is detrimental to the perf when there are no cycles for (var i = 0; i < Metadata.Internal.RelationalEntityTypeExtensions.MaxEntityTypesSharingTable; i++) { - var linkingFk = rootKey.DeclaringEntityType.FindRowInternalForeignKeys(storeObject) + var linkingFk = rootKey!.DeclaringEntityType.FindRowInternalForeignKeys(storeObject) .FirstOrDefault(); if (linkingFk == null) { @@ -109,7 +105,7 @@ public static string GetDefaultName([NotNull] this IKey key, in StoreObjectIdent // Using a hashset is detrimental to the perf when there are no cycles for (var i = 0; i < Metadata.Internal.RelationalEntityTypeExtensions.MaxEntityTypesSharingTable; i++) { - IKey linkedKey = null; + IKey? linkedKey = null; foreach (var otherKey in rootKey.DeclaringEntityType .FindRowInternalForeignKeys(storeObject) .SelectMany(fk => fk.PrincipalEntityType.GetKeys())) @@ -152,7 +148,7 @@ public static string GetDefaultName([NotNull] this IKey key, in StoreObjectIdent /// /// The key. /// The value to set. - public static void SetName([NotNull] this IMutableKey key, [CanBeNull] string name) + public static void SetName([NotNull] this IMutableKey key, [CanBeNull] string? name) => key.SetOrRemoveAnnotation( RelationalAnnotationNames.Name, Check.NullButNotEmpty(name, nameof(name))); @@ -164,7 +160,7 @@ public static void SetName([NotNull] this IMutableKey key, [CanBeNull] string na /// The value to set. /// Indicates whether the configuration was specified using a data annotation. /// The configured name. - public static string SetName([NotNull] this IConventionKey key, [CanBeNull] string name, bool fromDataAnnotation = false) + public static string? SetName([NotNull] this IConventionKey key, [CanBeNull] string? name, bool fromDataAnnotation = false) { key.SetOrRemoveAnnotation( RelationalAnnotationNames.Name, @@ -188,7 +184,7 @@ public static string SetName([NotNull] this IConventionKey key, [CanBeNull] stri /// The key. /// The unique constraints to which the key is mapped. public static IEnumerable GetMappedConstraints([NotNull] this IKey key) - => (IEnumerable)key[RelationalAnnotationNames.UniqueConstraintMappings] + => (IEnumerable?)key[RelationalAnnotationNames.UniqueConstraintMappings] ?? Enumerable.Empty(); /// @@ -203,7 +199,7 @@ public static IEnumerable GetMappedConstraints([NotNull] this /// The key. /// The identifier of the containing store object. /// The key found, or if none was found. - public static IKey FindSharedObjectRootKey([NotNull] this IKey key, in StoreObjectIdentifier storeObject) + public static IKey? FindSharedObjectRootKey([NotNull] this IKey key, in StoreObjectIdentifier storeObject) { Check.NotNull(key, nameof(key)); @@ -214,7 +210,7 @@ public static IKey FindSharedObjectRootKey([NotNull] this IKey key, in StoreObje // Using a hashset is detrimental to the perf when there are no cycles for (var i = 0; i < Metadata.Internal.RelationalEntityTypeExtensions.MaxEntityTypesSharingTable; i++) { - IKey linkedKey = null; + IKey? linkedKey = null; foreach (var otherKey in rootKey.DeclaringEntityType .FindRowInternalForeignKeys(storeObject) .SelectMany(fk => fk.PrincipalEntityType.GetKeys())) @@ -249,10 +245,10 @@ public static IKey FindSharedObjectRootKey([NotNull] this IKey key, in StoreObje /// The key. /// The identifier of the containing store object. /// The key found, or if none was found. - public static IMutableKey FindSharedObjectRootKey( + public static IMutableKey? FindSharedObjectRootKey( [NotNull] this IMutableKey key, in StoreObjectIdentifier storeObject) - => (IMutableKey)((IKey)key).FindSharedObjectRootKey(storeObject); + => (IMutableKey?)((IKey)key).FindSharedObjectRootKey(storeObject); /// /// @@ -266,9 +262,9 @@ public static IMutableKey FindSharedObjectRootKey( /// The key. /// The identifier of the containing store object. /// The key found, or if none was found. - public static IConventionKey FindSharedObjectRootKey( + public static IConventionKey? FindSharedObjectRootKey( [NotNull] this IConventionKey key, in StoreObjectIdentifier storeObject) - => (IConventionKey)((IKey)key).FindSharedObjectRootKey(storeObject); + => (IConventionKey?)((IKey)key).FindSharedObjectRootKey(storeObject); } } diff --git a/src/EFCore.Relational/Extensions/RelationalModelBuilderExtensions.cs b/src/EFCore.Relational/Extensions/RelationalModelBuilderExtensions.cs index 72f8fa66938..40915978bd9 100644 --- a/src/EFCore.Relational/Extensions/RelationalModelBuilderExtensions.cs +++ b/src/EFCore.Relational/Extensions/RelationalModelBuilderExtensions.cs @@ -11,6 +11,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Internal; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + // ReSharper disable once CheckNamespace namespace Microsoft.EntityFrameworkCore { @@ -29,7 +31,7 @@ public static class RelationalModelBuilderExtensions public static SequenceBuilder HasSequence( [NotNull] this ModelBuilder modelBuilder, [NotNull] string name, - [CanBeNull] string schema = null) + [CanBeNull] string? schema = null) => new( HasSequence( Check.NotNull(modelBuilder, nameof(modelBuilder)).Model, @@ -61,7 +63,7 @@ public static ModelBuilder HasSequence( public static ModelBuilder HasSequence( [NotNull] this ModelBuilder modelBuilder, [NotNull] string name, - [CanBeNull] string schema, + [CanBeNull] string? schema, [NotNull] Action builderAction) { Check.NotNull(builderAction, nameof(builderAction)); @@ -83,7 +85,7 @@ public static SequenceBuilder HasSequence( [NotNull] this ModelBuilder modelBuilder, [NotNull] Type type, [NotNull] string name, - [CanBeNull] string schema = null) + [CanBeNull] string? schema = null) { Check.NotNull(modelBuilder, nameof(modelBuilder)); Check.NotNull(type, nameof(type)); @@ -122,7 +124,7 @@ public static ModelBuilder HasSequence( [NotNull] this ModelBuilder modelBuilder, [NotNull] Type type, [NotNull] string name, - [CanBeNull] string schema, + [CanBeNull] string? schema, [NotNull] Action builderAction) { Check.NotNull(builderAction, nameof(builderAction)); @@ -143,7 +145,7 @@ public static ModelBuilder HasSequence( public static SequenceBuilder HasSequence( [NotNull] this ModelBuilder modelBuilder, [NotNull] string name, - [CanBeNull] string schema = null) + [CanBeNull] string? schema = null) { Check.NotNull(modelBuilder, nameof(modelBuilder)); @@ -179,7 +181,7 @@ public static ModelBuilder HasSequence( public static ModelBuilder HasSequence( [NotNull] this ModelBuilder modelBuilder, [NotNull] string name, - [CanBeNull] string schema, + [CanBeNull] string? schema, [NotNull] Action builderAction) { Check.NotNull(builderAction, nameof(builderAction)); @@ -200,7 +202,7 @@ public static ModelBuilder HasSequence( public static IConventionSequenceBuilder HasSequence( [NotNull] this IConventionModelBuilder modelBuilder, [NotNull] string name, - [CanBeNull] string schema = null, + [CanBeNull] string? schema = null, bool fromDataAnnotation = false) => HasSequence( (IMutableModel)Check.NotNull(modelBuilder, nameof(modelBuilder)).Metadata, @@ -211,7 +213,7 @@ public static IConventionSequenceBuilder HasSequence( private static Sequence HasSequence( IMutableModel model, string name, - string schema, + string? schema, ConfigurationSource configurationSource) { Check.NotEmpty(name, nameof(name)); @@ -334,7 +336,7 @@ public static IConventionDbFunctionBuilder HasDbFunction( /// A builder to further configure the function. public static IConventionDbFunctionBuilder HasDbFunction( [NotNull] this IConventionModelBuilder modelBuilder, - [NotNull] string name, + [CanBeNull] string? name, [NotNull] Type returnType, bool fromDataAnnotation = false) { @@ -364,7 +366,7 @@ public static IConventionDbFunctionBuilder HasDbFunction( /// The same builder instance so that multiple calls can be chained. public static ModelBuilder HasDefaultSchema( [NotNull] this ModelBuilder modelBuilder, - [CanBeNull] string schema) + [CanBeNull] string? schema) { Check.NotNull(modelBuilder, nameof(modelBuilder)); Check.NullButNotEmpty(schema, nameof(schema)); @@ -385,9 +387,9 @@ public static ModelBuilder HasDefaultSchema( /// The same builder instance if the configuration was applied, /// otherwise. /// - public static IConventionModelBuilder HasDefaultSchema( + public static IConventionModelBuilder? HasDefaultSchema( [NotNull] this IConventionModelBuilder modelBuilder, - [CanBeNull] string schema, + [CanBeNull] string? schema, bool fromDataAnnotation = false) { if (modelBuilder.CanSetDefaultSchema(schema, fromDataAnnotation)) @@ -409,7 +411,7 @@ public static IConventionModelBuilder HasDefaultSchema( /// if the given schema can be set as default. public static bool CanSetDefaultSchema( [NotNull] this IConventionModelBuilder modelBuilder, - [CanBeNull] string schema, + [CanBeNull] string? schema, bool fromDataAnnotation = false) { Check.NotNull(modelBuilder, nameof(modelBuilder)); @@ -428,7 +430,7 @@ public static bool CanSetDefaultSchema( /// The same builder instance if the configuration was applied, /// otherwise. /// - public static IConventionModelBuilder HasMaxIdentifierLength( + public static IConventionModelBuilder? HasMaxIdentifierLength( [NotNull] this IConventionModelBuilder modelBuilder, int? length, bool fromDataAnnotation = false) @@ -468,7 +470,7 @@ public static bool CanSetMaxIdentifierLength( /// The same builder instance so that multiple calls can be chained. public static ModelBuilder UseCollation( [NotNull] this ModelBuilder modelBuilder, - [CanBeNull] string collation) + [CanBeNull] string? collation) { Check.NotNull(modelBuilder, nameof(modelBuilder)); Check.NullButNotEmpty(collation, nameof(collation)); @@ -488,9 +490,9 @@ public static ModelBuilder UseCollation( /// The same builder instance if the configuration was applied, /// otherwise. /// - public static IConventionModelBuilder UseCollation( + public static IConventionModelBuilder? UseCollation( [NotNull] this IConventionModelBuilder modelBuilder, - [CanBeNull] string collation, + [CanBeNull] string? collation, bool fromDataAnnotation = false) { if (modelBuilder.CanSetCollation(collation, fromDataAnnotation)) @@ -512,7 +514,7 @@ public static IConventionModelBuilder UseCollation( /// if the given collation can be set as default. public static bool CanSetCollation( [NotNull] this IConventionModelBuilder modelBuilder, - [CanBeNull] string collation, + [CanBeNull] string? collation, bool fromDataAnnotation = false) { Check.NotNull(modelBuilder, nameof(modelBuilder)); diff --git a/src/EFCore.Relational/Extensions/RelationalModelExtensions.cs b/src/EFCore.Relational/Extensions/RelationalModelExtensions.cs index 45f0fa3696b..64f24cd5582 100644 --- a/src/EFCore.Relational/Extensions/RelationalModelExtensions.cs +++ b/src/EFCore.Relational/Extensions/RelationalModelExtensions.cs @@ -235,7 +235,7 @@ public static void SetMaxIdentifierLength([NotNull] this IMutableModel model, in /// The sequence name. /// The schema name, or to use the default schema. /// The sequence. - public static IMutableSequence? AddSequence( + public static IMutableSequence AddSequence( [NotNull] this IMutableModel model, [NotNull] string name, [CanBeNull] string? schema = null) @@ -376,9 +376,9 @@ public static IEnumerable GetSequences([NotNull] this IConv /// The model to add the function to. /// The for the method that is mapped to the function. /// The new . - public static IMutableDbFunction? AddDbFunction([NotNull] this IMutableModel model, [NotNull] MethodInfo methodInfo) + public static IMutableDbFunction AddDbFunction([NotNull] this IMutableModel model, [NotNull] MethodInfo methodInfo) => DbFunction.AddDbFunction( - model, Check.NotNull(methodInfo, nameof(methodInfo)), ConfigurationSource.Explicit); + model, Check.NotNull(methodInfo, nameof(methodInfo)), ConfigurationSource.Explicit)!; /// /// Creates an mapped to the given method. @@ -387,7 +387,7 @@ public static IEnumerable GetSequences([NotNull] this IConv /// The for the method that is mapped to the function. /// Indicates whether the configuration was specified using a data annotation. /// The new . - public static IConventionDbFunction? AddDbFunction( + public static IConventionDbFunction AddDbFunction( [NotNull] this IConventionModel model, [NotNull] MethodInfo methodInfo, bool fromDataAnnotation = false) @@ -402,7 +402,7 @@ public static IEnumerable GetSequences([NotNull] this IConv /// The model name of the function. /// The function return type. /// The new . - public static IMutableDbFunction? AddDbFunction( + public static IMutableDbFunction AddDbFunction( [NotNull] this IMutableModel model, [NotNull] string name, [NotNull] Type returnType) @@ -417,7 +417,7 @@ public static IEnumerable GetSequences([NotNull] this IConv /// The function return type. /// Indicates whether the configuration was specified using a data annotation. /// The new . - public static IConventionDbFunction? AddDbFunction( + public static IConventionDbFunction AddDbFunction( [NotNull] this IConventionModel model, [NotNull] string name, [NotNull] Type returnType, diff --git a/src/EFCore.Relational/Extensions/RelationalOwnedNavigationBuilderExtensions.cs b/src/EFCore.Relational/Extensions/RelationalOwnedNavigationBuilderExtensions.cs index bdc637d7269..418005a4ed4 100644 --- a/src/EFCore.Relational/Extensions/RelationalOwnedNavigationBuilderExtensions.cs +++ b/src/EFCore.Relational/Extensions/RelationalOwnedNavigationBuilderExtensions.cs @@ -7,6 +7,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Internal; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + // ReSharper disable once CheckNamespace namespace Microsoft.EntityFrameworkCore { @@ -25,7 +27,7 @@ public static class RelationalOwnedNavigationBuilderExtensions public static OwnedNavigationBuilder HasCheckConstraint( [NotNull] this OwnedNavigationBuilder ownedNavigationBuilder, [NotNull] string name, - [CanBeNull] string sql) + [CanBeNull] string? sql) { Check.NotNull(ownedNavigationBuilder, nameof(ownedNavigationBuilder)); Check.NotEmpty(name, nameof(name)); @@ -65,7 +67,7 @@ public static OwnedNavigationBuilder HasCheckConstraint( public static OwnedNavigationBuilder HasCheckConstraint( [NotNull] this OwnedNavigationBuilder ownedNavigationBuilder, [NotNull] string name, - [CanBeNull] string sql) + [CanBeNull] string? sql) where TEntity : class where TDependentEntity : class => (OwnedNavigationBuilder) diff --git a/src/EFCore.Relational/Extensions/RelationalPropertyBuilderExtensions.cs b/src/EFCore.Relational/Extensions/RelationalPropertyBuilderExtensions.cs index 8c029f7db6e..a1d9779f4ee 100644 --- a/src/EFCore.Relational/Extensions/RelationalPropertyBuilderExtensions.cs +++ b/src/EFCore.Relational/Extensions/RelationalPropertyBuilderExtensions.cs @@ -8,6 +8,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Internal; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + // ReSharper disable once CheckNamespace namespace Microsoft.EntityFrameworkCore { @@ -24,7 +26,7 @@ public static class RelationalPropertyBuilderExtensions /// The same builder instance so that multiple calls can be chained. public static PropertyBuilder HasColumnName( [NotNull] this PropertyBuilder propertyBuilder, - [CanBeNull] string name) + [CanBeNull] string? name) { Check.NotNull(propertyBuilder, nameof(propertyBuilder)); Check.NullButNotEmpty(name, nameof(name)); @@ -43,7 +45,7 @@ public static PropertyBuilder HasColumnName( /// The same builder instance so that multiple calls can be chained. public static PropertyBuilder HasColumnName( [NotNull] this PropertyBuilder propertyBuilder, - [CanBeNull] string name) + [CanBeNull] string? name) => (PropertyBuilder)HasColumnName((PropertyBuilder)propertyBuilder, name); /// @@ -56,9 +58,9 @@ public static PropertyBuilder HasColumnName( /// The same builder instance if the configuration was applied, /// otherwise. /// - public static IConventionPropertyBuilder HasColumnName( + public static IConventionPropertyBuilder? HasColumnName( [NotNull] this IConventionPropertyBuilder propertyBuilder, - [CanBeNull] string name, + [CanBeNull] string? name, bool fromDataAnnotation = false) { if (!propertyBuilder.CanSetColumnName(name, fromDataAnnotation)) @@ -81,9 +83,9 @@ public static IConventionPropertyBuilder HasColumnName( /// The same builder instance if the configuration was applied, /// otherwise. /// - public static IConventionPropertyBuilder HasColumnName( + public static IConventionPropertyBuilder? HasColumnName( [NotNull] this IConventionPropertyBuilder propertyBuilder, - [CanBeNull] string name, + [CanBeNull] string? name, in StoreObjectIdentifier storeObject, bool fromDataAnnotation = false) { @@ -105,7 +107,7 @@ public static IConventionPropertyBuilder HasColumnName( /// if the property can be mapped to the given column. public static bool CanSetColumnName( [NotNull] this IConventionPropertyBuilder propertyBuilder, - [CanBeNull] string name, + [CanBeNull] string? name, bool fromDataAnnotation = false) => propertyBuilder.CanSetAnnotation(RelationalAnnotationNames.ColumnName, name, fromDataAnnotation); @@ -119,7 +121,7 @@ public static bool CanSetColumnName( /// if the property can be mapped to the given column. public static bool CanSetColumnName( [NotNull] this IConventionPropertyBuilder propertyBuilder, - [CanBeNull] string name, + [CanBeNull] string? name, in StoreObjectIdentifier storeObject, bool fromDataAnnotation = false) { @@ -139,7 +141,7 @@ public static bool CanSetColumnName( /// The same builder instance so that multiple calls can be chained. public static PropertyBuilder HasColumnType( [NotNull] this PropertyBuilder propertyBuilder, - [CanBeNull] string typeName) + [CanBeNull] string? typeName) { Check.NotNull(propertyBuilder, nameof(propertyBuilder)); Check.NullButNotEmpty(typeName, nameof(typeName)); @@ -159,7 +161,7 @@ public static PropertyBuilder HasColumnType( /// The same builder instance so that multiple calls can be chained. public static PropertyBuilder HasColumnType( [NotNull] this PropertyBuilder propertyBuilder, - [CanBeNull] string typeName) + [CanBeNull] string? typeName) => (PropertyBuilder)HasColumnType((PropertyBuilder)propertyBuilder, typeName); /// @@ -173,9 +175,9 @@ public static PropertyBuilder HasColumnType( /// The same builder instance if the configuration was applied, /// otherwise. /// - public static IConventionPropertyBuilder HasColumnType( + public static IConventionPropertyBuilder? HasColumnType( [NotNull] this IConventionPropertyBuilder propertyBuilder, - [CanBeNull] string typeName, + [CanBeNull] string? typeName, bool fromDataAnnotation = false) { if (!propertyBuilder.CanSetColumnType(typeName, fromDataAnnotation)) @@ -196,7 +198,7 @@ public static IConventionPropertyBuilder HasColumnType( /// if the given data type can be set for the property. public static bool CanSetColumnType( [NotNull] this IConventionPropertyBuilder propertyBuilder, - [CanBeNull] string typeName, + [CanBeNull] string? typeName, bool fromDataAnnotation = false) => propertyBuilder.CanSetAnnotation(RelationalAnnotationNames.ColumnType, typeName, fromDataAnnotation); @@ -239,7 +241,7 @@ public static PropertyBuilder IsFixedLength( /// The same builder instance if the configuration was applied, /// otherwise. /// - public static IConventionPropertyBuilder IsFixedLength( + public static IConventionPropertyBuilder? IsFixedLength( [NotNull] this IConventionPropertyBuilder propertyBuilder, bool? fixedLength, bool fromDataAnnotation = false) @@ -296,7 +298,7 @@ public static PropertyBuilder HasDefaultValueSql([NotNull] this PropertyBuilder /// The same builder instance so that multiple calls can be chained. public static PropertyBuilder HasDefaultValueSql( [NotNull] this PropertyBuilder propertyBuilder, - [CanBeNull] string sql) + [CanBeNull] string? sql) { Check.NotNull(propertyBuilder, nameof(propertyBuilder)); Check.NullButNotEmpty(sql, nameof(sql)); @@ -333,7 +335,7 @@ public static PropertyBuilder HasDefaultValueSql( /// The same builder instance so that multiple calls can be chained. public static PropertyBuilder HasDefaultValueSql( [NotNull] this PropertyBuilder propertyBuilder, - [CanBeNull] string sql) + [CanBeNull] string? sql) => (PropertyBuilder)HasDefaultValueSql((PropertyBuilder)propertyBuilder, sql); /// @@ -346,9 +348,9 @@ public static PropertyBuilder HasDefaultValueSql( /// The same builder instance if the configuration was applied, /// otherwise. /// - public static IConventionPropertyBuilder HasDefaultValueSql( + public static IConventionPropertyBuilder? HasDefaultValueSql( [NotNull] this IConventionPropertyBuilder propertyBuilder, - [CanBeNull] string sql, + [CanBeNull] string? sql, bool fromDataAnnotation = false) { if (!propertyBuilder.CanSetDefaultValueSql(sql, fromDataAnnotation)) @@ -369,7 +371,7 @@ public static IConventionPropertyBuilder HasDefaultValueSql( /// if the given default value expression can be set for the column. public static bool CanSetDefaultValueSql( [NotNull] this IConventionPropertyBuilder propertyBuilder, - [CanBeNull] string sql, + [CanBeNull] string? sql, bool fromDataAnnotation = false) => propertyBuilder.CanSetAnnotation( RelationalAnnotationNames.DefaultValueSql, @@ -405,7 +407,7 @@ public static PropertyBuilder HasComputedColumnSql([NotNull] this PropertyBuilde /// The same builder instance so that multiple calls can be chained. public static PropertyBuilder HasComputedColumnSql( [NotNull] this PropertyBuilder propertyBuilder, - [CanBeNull] string sql) + [CanBeNull] string? sql) => HasComputedColumnSql(propertyBuilder, sql, null); /// @@ -421,7 +423,7 @@ public static PropertyBuilder HasComputedColumnSql( /// The same builder instance so that multiple calls can be chained. public static PropertyBuilder HasComputedColumnSql( [NotNull] this PropertyBuilder propertyBuilder, - [CanBeNull] string sql, + [CanBeNull] string? sql, bool? stored) { Check.NotNull(propertyBuilder, nameof(propertyBuilder)); @@ -463,7 +465,7 @@ public static PropertyBuilder HasComputedColumnSql( /// The same builder instance so that multiple calls can be chained. public static PropertyBuilder HasComputedColumnSql( [NotNull] this PropertyBuilder propertyBuilder, - [CanBeNull] string sql) + [CanBeNull] string? sql) => HasComputedColumnSql(propertyBuilder, sql, null); /// @@ -480,7 +482,7 @@ public static PropertyBuilder HasComputedColumnSql( /// The same builder instance so that multiple calls can be chained. public static PropertyBuilder HasComputedColumnSql( [NotNull] this PropertyBuilder propertyBuilder, - [CanBeNull] string sql, + [CanBeNull] string? sql, bool? stored) => (PropertyBuilder)HasComputedColumnSql((PropertyBuilder)propertyBuilder, sql, stored); @@ -494,9 +496,9 @@ public static PropertyBuilder HasComputedColumnSql( /// The same builder instance if the configuration was applied, /// otherwise. /// - public static IConventionPropertyBuilder HasComputedColumnSql( + public static IConventionPropertyBuilder? HasComputedColumnSql( [NotNull] this IConventionPropertyBuilder propertyBuilder, - [CanBeNull] string sql, + [CanBeNull] string? sql, bool fromDataAnnotation = false) { if (!propertyBuilder.CanSetComputedColumnSql(sql, fromDataAnnotation)) @@ -521,7 +523,7 @@ public static IConventionPropertyBuilder HasComputedColumnSql( /// /// The same builder instance if the configuration was applied, otherwise. /// - public static IConventionPropertyBuilder IsStoredComputedColumn( + public static IConventionPropertyBuilder? IsStoredComputedColumn( [NotNull] this IConventionPropertyBuilder propertyBuilder, bool? stored, bool fromDataAnnotation = false) @@ -544,7 +546,7 @@ public static IConventionPropertyBuilder IsStoredComputedColumn( /// if the given computed value SQL expression can be set for the column. public static bool CanSetComputedColumnSql( [NotNull] this IConventionPropertyBuilder propertyBuilder, - [CanBeNull] string sql, + [CanBeNull] string? sql, bool fromDataAnnotation = false) => propertyBuilder.CanSetAnnotation( RelationalAnnotationNames.ComputedColumnSql, @@ -602,7 +604,7 @@ public static PropertyBuilder HasDefaultValue([NotNull] this PropertyBuilder pro /// The same builder instance so that multiple calls can be chained. public static PropertyBuilder HasDefaultValue( [NotNull] this PropertyBuilder propertyBuilder, - [CanBeNull] object value) + [CanBeNull] object? value) { Check.NotNull(propertyBuilder, nameof(propertyBuilder)); @@ -639,7 +641,7 @@ public static PropertyBuilder HasDefaultValue( /// The same builder instance so that multiple calls can be chained. public static PropertyBuilder HasDefaultValue( [NotNull] this PropertyBuilder propertyBuilder, - [CanBeNull] object value) + [CanBeNull] object? value) => (PropertyBuilder)HasDefaultValue((PropertyBuilder)propertyBuilder, value); /// @@ -652,9 +654,9 @@ public static PropertyBuilder HasDefaultValue( /// The same builder instance if the configuration was applied, /// otherwise. /// - public static IConventionPropertyBuilder HasDefaultValue( + public static IConventionPropertyBuilder? HasDefaultValue( [NotNull] this IConventionPropertyBuilder propertyBuilder, - [CanBeNull] object value, + [CanBeNull] object? value, bool fromDataAnnotation = false) { if (!propertyBuilder.CanSetDefaultValue(value, fromDataAnnotation)) @@ -675,7 +677,7 @@ public static IConventionPropertyBuilder HasDefaultValue( /// if the given value can be set as default for the column. public static bool CanSetDefaultValue( [NotNull] this IConventionPropertyBuilder propertyBuilder, - [CanBeNull] object value, + [CanBeNull] object? value, bool fromDataAnnotation = false) => propertyBuilder.CanSetAnnotation( RelationalAnnotationNames.DefaultValue, @@ -690,7 +692,7 @@ public static bool CanSetDefaultValue( /// The same builder instance so that multiple calls can be chained. public static PropertyBuilder HasComment( [NotNull] this PropertyBuilder propertyBuilder, - [CanBeNull] string comment) + [CanBeNull] string? comment) { Check.NotNull(propertyBuilder, nameof(propertyBuilder)); @@ -708,7 +710,7 @@ public static PropertyBuilder HasComment( /// The same builder instance so that multiple calls can be chained. public static PropertyBuilder HasComment( [NotNull] this PropertyBuilder propertyBuilder, - [CanBeNull] string comment) + [CanBeNull] string? comment) => (PropertyBuilder)HasComment((PropertyBuilder)propertyBuilder, comment); /// @@ -721,9 +723,9 @@ public static PropertyBuilder HasComment( /// The same builder instance if the configuration was applied, /// otherwise. /// - public static IConventionPropertyBuilder HasComment( + public static IConventionPropertyBuilder? HasComment( [NotNull] this IConventionPropertyBuilder propertyBuilder, - [CanBeNull] string comment, + [CanBeNull] string? comment, bool fromDataAnnotation = false) { if (!propertyBuilder.CanSetComment(comment, fromDataAnnotation)) @@ -744,7 +746,7 @@ public static IConventionPropertyBuilder HasComment( /// if the given value can be set as default for the column. public static bool CanSetComment( [NotNull] this IConventionPropertyBuilder propertyBuilder, - [CanBeNull] string comment, + [CanBeNull] string? comment, bool fromDataAnnotation = false) => propertyBuilder.CanSetAnnotation( RelationalAnnotationNames.Comment, @@ -758,7 +760,7 @@ public static bool CanSetComment( /// The builder for the property being configured. /// The collation for the column. /// The same builder instance so that multiple calls can be chained. - public static PropertyBuilder UseCollation([NotNull] this PropertyBuilder propertyBuilder, [CanBeNull] string collation) + public static PropertyBuilder UseCollation([NotNull] this PropertyBuilder propertyBuilder, [CanBeNull] string? collation) { Check.NotNull(propertyBuilder, nameof(propertyBuilder)); Check.NullButNotEmpty(collation, nameof(collation)); @@ -777,7 +779,7 @@ public static PropertyBuilder UseCollation([NotNull] this PropertyBuilder proper /// The same builder instance so that multiple calls can be chained. public static PropertyBuilder UseCollation( [NotNull] this PropertyBuilder propertyBuilder, - [CanBeNull] string collation) + [CanBeNull] string? collation) => (PropertyBuilder)UseCollation((PropertyBuilder)propertyBuilder, collation); /// @@ -791,9 +793,9 @@ public static PropertyBuilder UseCollation( /// The same builder instance if the configuration was applied, /// otherwise. /// - public static IConventionPropertyBuilder UseCollation( + public static IConventionPropertyBuilder? UseCollation( [NotNull] this IConventionPropertyBuilder propertyBuilder, - [CanBeNull] string collation, + [CanBeNull] string? collation, bool fromDataAnnotation = false) { if (propertyBuilder.CanSetCollation(collation, fromDataAnnotation)) @@ -815,7 +817,7 @@ public static IConventionPropertyBuilder UseCollation( /// if the given value can be set as default for the column. public static bool CanSetCollation( [NotNull] this IConventionPropertyBuilder propertyBuilder, - [CanBeNull] string collation, + [CanBeNull] string? collation, bool fromDataAnnotation = false) { Check.NotNull(propertyBuilder, nameof(propertyBuilder)); diff --git a/src/EFCore.Relational/Extensions/RelationalPropertyExtensions.cs b/src/EFCore.Relational/Extensions/RelationalPropertyExtensions.cs index eb1392c43a2..123e6421ded 100644 --- a/src/EFCore.Relational/Extensions/RelationalPropertyExtensions.cs +++ b/src/EFCore.Relational/Extensions/RelationalPropertyExtensions.cs @@ -15,6 +15,8 @@ using Microsoft.EntityFrameworkCore.Storage; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + // ReSharper disable once CheckNamespace namespace Microsoft.EntityFrameworkCore { @@ -30,10 +32,7 @@ public static class RelationalPropertyExtensions /// The name of the table column to which the property is mapped. [Obsolete("Use the overload that takes a StoreObjectIdentifier")] public static string GetColumnName([NotNull] this IProperty property) - { - var annotation = property.FindAnnotation(RelationalAnnotationNames.ColumnName); - return annotation != null ? (string)annotation.Value : property.GetDefaultColumnName(); - } + => (string?)property.FindAnnotation(RelationalAnnotationNames.ColumnName)?.Value ?? property.GetDefaultColumnName(); /// /// Returns the base name of the column to which the property would be mapped. @@ -41,10 +40,7 @@ public static string GetColumnName([NotNull] this IProperty property) /// The property. /// The the base name of the column to which the property would be mapped. public static string GetColumnBaseName([NotNull] this IProperty property) - { - var annotation = property.FindAnnotation(RelationalAnnotationNames.ColumnName); - return annotation != null ? (string)annotation.Value : property.GetDefaultColumnBaseName(); - } + => (string?)property.FindAnnotation(RelationalAnnotationNames.ColumnName)?.Value ?? property.GetDefaultColumnBaseName(); /// /// Returns the name of the column to which the property is mapped for a particular table. @@ -52,7 +48,7 @@ public static string GetColumnBaseName([NotNull] this IProperty property) /// The property. /// The identifier of the table-like store object containing the column. /// The name of the column to which the property is mapped. - public static string GetColumnName([NotNull] this IProperty property, in StoreObjectIdentifier storeObject) + public static string? GetColumnName([NotNull] this IProperty property, in StoreObjectIdentifier storeObject) { Check.NotNull(property, nameof(property)); @@ -128,17 +124,17 @@ public static string GetDefaultColumnName([NotNull] this IProperty property, in var sharedTablePrincipalPrimaryKeyProperty = FindSharedObjectRootPrimaryKeyProperty(property, storeObject); if (sharedTablePrincipalPrimaryKeyProperty != null) { - return sharedTablePrincipalPrimaryKeyProperty.GetColumnName(storeObject); + return sharedTablePrincipalPrimaryKeyProperty.GetColumnName(storeObject)!; } var sharedTablePrincipalConcurrencyProperty = FindSharedObjectRootConcurrencyTokenProperty(property, storeObject); if (sharedTablePrincipalConcurrencyProperty != null) { - return sharedTablePrincipalConcurrencyProperty.GetColumnName(storeObject); + return sharedTablePrincipalConcurrencyProperty.GetColumnName(storeObject)!; } var entityType = property.DeclaringEntityType; - StringBuilder builder = null; + StringBuilder? builder = null; while (true) { var ownership = entityType.GetForeignKeys().SingleOrDefault(fk => fk.IsOwnership); @@ -190,7 +186,7 @@ public static string GetDefaultColumnName([NotNull] this IProperty property, in } builder.Insert(0, "_"); - builder.Insert(0, ownership.PrincipalToDependent.Name); + builder.Insert(0, ownership.PrincipalToDependent!.Name); entityType = ownerType; } @@ -211,7 +207,7 @@ public static string GetDefaultColumnName([NotNull] this IProperty property, in /// /// The property. /// The name to set. - public static void SetColumnName([NotNull] this IMutableProperty property, [CanBeNull] string name) + public static void SetColumnName([NotNull] this IMutableProperty property, [CanBeNull] string? name) => property.SetOrRemoveAnnotation( RelationalAnnotationNames.ColumnName, Check.NullButNotEmpty(name, nameof(name))); @@ -223,9 +219,9 @@ public static void SetColumnName([NotNull] this IMutableProperty property, [CanB /// The name to set. /// Indicates whether the configuration was specified using a data annotation. /// The configured value. - public static string SetColumnName( + public static string? SetColumnName( [NotNull] this IConventionProperty property, - [CanBeNull] string name, + [CanBeNull] string? name, bool fromDataAnnotation = false) { property.SetOrRemoveAnnotation( @@ -244,7 +240,7 @@ public static string SetColumnName( /// The identifier of the table-like store object containing the column. public static void SetColumnName( [NotNull] this IMutableProperty property, - [CanBeNull] string name, + [CanBeNull] string? name, in StoreObjectIdentifier storeObject) => RelationalPropertyOverrides.GetOrCreate(property, storeObject) .SetColumnName(name, ConfigurationSource.Explicit); @@ -257,9 +253,9 @@ public static void SetColumnName( /// The identifier of the table-like store object containing the column. /// Indicates whether the configuration was specified using a data annotation. /// The configured value. - public static string SetColumnName( + public static string? SetColumnName( [NotNull] this IConventionProperty property, - [CanBeNull] string name, + [CanBeNull] string? name, in StoreObjectIdentifier storeObject, bool fromDataAnnotation = false) => RelationalPropertyOverrides.GetOrCreate(property, storeObject) @@ -289,11 +285,11 @@ public static string SetColumnName( /// /// The property. /// The database type of the column to which the property is mapped. - public static string GetColumnType([NotNull] this IProperty property) + public static string? GetColumnType([NotNull] this IProperty property) { Check.NotNull(property, nameof(property)); - return (string)(property.FindRelationalTypeMapping()?.StoreType + return (string?)(property.FindRelationalTypeMapping()?.StoreType ?? property.FindAnnotation(RelationalAnnotationNames.ColumnType)?.Value); } @@ -303,7 +299,7 @@ public static string GetColumnType([NotNull] this IProperty property) /// The property. /// The identifier of the table-like store object containing the column. /// The database type of the column to which the property is mapped. - public static string GetColumnType([NotNull] this IProperty property, in StoreObjectIdentifier storeObject) + public static string? GetColumnType([NotNull] this IProperty property, in StoreObjectIdentifier storeObject) { var annotation = property.FindAnnotation(RelationalAnnotationNames.ColumnType); if (annotation != null) @@ -314,7 +310,7 @@ public static string GetColumnType([NotNull] this IProperty property, in StoreOb return GetDefaultColumnType(property, storeObject); } - private static string GetDefaultColumnType(IProperty property, in StoreObjectIdentifier storeObject) + private static string? GetDefaultColumnType(IProperty property, in StoreObjectIdentifier storeObject) { var sharedTableRootProperty = property.FindSharedStoreObjectRootProperty(storeObject); return sharedTableRootProperty != null @@ -327,7 +323,7 @@ private static string GetDefaultColumnType(IProperty property, in StoreObjectIde /// /// The property. /// The value to set. - public static void SetColumnType([NotNull] this IMutableProperty property, [CanBeNull] string value) + public static void SetColumnType([NotNull] this IMutableProperty property, [CanBeNull] string? value) => property.SetOrRemoveAnnotation( RelationalAnnotationNames.ColumnType, Check.NullButNotEmpty(value, nameof(value))); @@ -339,9 +335,9 @@ public static void SetColumnType([NotNull] this IMutableProperty property, [CanB /// The value to set. /// Indicates whether the configuration was specified using a data annotation. /// The configured value. - public static string SetColumnType( + public static string? SetColumnType( [NotNull] this IConventionProperty property, - [CanBeNull] string value, + [CanBeNull] string? value, bool fromDataAnnotation = false) { property.SetOrRemoveAnnotation( @@ -366,7 +362,7 @@ public static string SetColumnType( /// The property. /// The default columns to which the property would be mapped. public static IEnumerable GetDefaultColumnMappings([NotNull] this IProperty property) - => (IEnumerable)property[RelationalAnnotationNames.DefaultColumnMappings] + => (IEnumerable?)property[RelationalAnnotationNames.DefaultColumnMappings] ?? Enumerable.Empty(); /// @@ -375,7 +371,7 @@ public static IEnumerable GetDefaultColumnMappings([NotNull] /// The property. /// The table columns to which the property is mapped. public static IEnumerable GetTableColumnMappings([NotNull] this IProperty property) - => (IEnumerable)property[RelationalAnnotationNames.TableColumnMappings] + => (IEnumerable?)property[RelationalAnnotationNames.TableColumnMappings] ?? Enumerable.Empty(); /// @@ -384,7 +380,7 @@ public static IEnumerable GetTableColumnMappings([NotNull] this /// The property. /// The view columns to which the property is mapped. public static IEnumerable GetViewColumnMappings([NotNull] this IProperty property) - => (IEnumerable)property[RelationalAnnotationNames.ViewColumnMappings] + => (IEnumerable?)property[RelationalAnnotationNames.ViewColumnMappings] ?? Enumerable.Empty(); /// @@ -393,7 +389,7 @@ public static IEnumerable GetViewColumnMappings([NotNull] th /// The property. /// The SQL query columns to which the property is mapped. public static IEnumerable GetSqlQueryColumnMappings([NotNull] this IProperty property) - => (IEnumerable)property[RelationalAnnotationNames.SqlQueryColumnMappings] + => (IEnumerable?)property[RelationalAnnotationNames.SqlQueryColumnMappings] ?? Enumerable.Empty(); /// @@ -402,7 +398,7 @@ public static IEnumerable GetSqlQueryColumnMappings([Not /// The property. /// The function columns to which the property is mapped. public static IEnumerable GetFunctionColumnMappings([NotNull] this IProperty property) - => (IEnumerable)property[RelationalAnnotationNames.FunctionColumnMappings] + => (IEnumerable?)property[RelationalAnnotationNames.FunctionColumnMappings] ?? Enumerable.Empty(); /// @@ -411,7 +407,7 @@ public static IEnumerable GetFunctionColumnMappings([Not /// The property. /// The identifier of the table-like store object containing the column. /// The column to which the property is mapped. - public static IColumnBase FindColumn([NotNull] this IProperty property, in StoreObjectIdentifier storeObject) + public static IColumnBase? FindColumn([NotNull] this IProperty property, in StoreObjectIdentifier storeObject) { switch (storeObject.StoreObjectType) { @@ -465,11 +461,8 @@ public static IColumnBase FindColumn([NotNull] this IProperty property, in Store /// /// The property. /// The SQL expression that is used as the default value for the column this property is mapped to. - public static string GetDefaultValueSql([NotNull] this IProperty property) - { - var annotation = property.FindAnnotation(RelationalAnnotationNames.DefaultValueSql); - return annotation != null ? (string)annotation.Value : null; - } + public static string? GetDefaultValueSql([NotNull] this IProperty property) + => (string?)property.FindAnnotation(RelationalAnnotationNames.DefaultValueSql)?.Value; /// /// Returns the SQL expression that is used as the default value for the column this property is mapped to. @@ -477,7 +470,7 @@ public static string GetDefaultValueSql([NotNull] this IProperty property) /// The property. /// The identifier of the table-like store object containing the column. /// The SQL expression that is used as the default value for the column this property is mapped to. - public static string GetDefaultValueSql([NotNull] this IProperty property, in StoreObjectIdentifier storeObject) + public static string? GetDefaultValueSql([NotNull] this IProperty property, in StoreObjectIdentifier storeObject) { var annotation = property.FindAnnotation(RelationalAnnotationNames.DefaultValueSql); if (annotation != null) @@ -499,7 +492,7 @@ public static string GetDefaultValueSql([NotNull] this IProperty property, in St /// /// The property. /// The value to set. - public static void SetDefaultValueSql([NotNull] this IMutableProperty property, [CanBeNull] string value) + public static void SetDefaultValueSql([NotNull] this IMutableProperty property, [CanBeNull] string? value) => property.SetOrRemoveAnnotation( RelationalAnnotationNames.DefaultValueSql, value); @@ -511,9 +504,9 @@ public static void SetDefaultValueSql([NotNull] this IMutableProperty property, /// The value to set. /// Indicates whether the configuration was specified using a data annotation. /// The configured value. - public static string SetDefaultValueSql( + public static string? SetDefaultValueSql( [NotNull] this IConventionProperty property, - [CanBeNull] string value, + [CanBeNull] string? value, bool fromDataAnnotation = false) { property.SetOrRemoveAnnotation( @@ -537,16 +530,8 @@ public static string SetDefaultValueSql( /// /// The property. /// The SQL expression that is used as the computed value for the column this property is mapped to. - public static string GetComputedColumnSql([NotNull] this IProperty property) - { - var annotation = property.FindAnnotation(RelationalAnnotationNames.ComputedColumnSql); - if (annotation != null) - { - return (string)annotation.Value; - } - - return null; - } + public static string? GetComputedColumnSql([NotNull] this IProperty property) + => (string?)property.FindAnnotation(RelationalAnnotationNames.ComputedColumnSql)?.Value; /// /// Returns the SQL expression that is used as the computed value for the column this property is mapped to. @@ -554,7 +539,7 @@ public static string GetComputedColumnSql([NotNull] this IProperty property) /// The property. /// The identifier of the table-like store object containing the column. /// The SQL expression that is used as the computed value for the column this property is mapped to. - public static string GetComputedColumnSql([NotNull] this IProperty property, in StoreObjectIdentifier storeObject) + public static string? GetComputedColumnSql([NotNull] this IProperty property, in StoreObjectIdentifier storeObject) { var annotation = property.FindAnnotation(RelationalAnnotationNames.ComputedColumnSql); if (annotation != null) @@ -576,7 +561,7 @@ public static string GetComputedColumnSql([NotNull] this IProperty property, in /// /// The property. /// The value to set. - public static void SetComputedColumnSql([NotNull] this IMutableProperty property, [CanBeNull] string value) + public static void SetComputedColumnSql([NotNull] this IMutableProperty property, [CanBeNull] string? value) => property.SetOrRemoveAnnotation( RelationalAnnotationNames.ComputedColumnSql, value); @@ -588,9 +573,9 @@ public static void SetComputedColumnSql([NotNull] this IMutableProperty property /// The value to set. /// Indicates whether the configuration was specified using a data annotation. /// The configured value. - public static string SetComputedColumnSql( + public static string? SetComputedColumnSql( [NotNull] this IConventionProperty property, - [CanBeNull] string value, + [CanBeNull] string? value, bool fromDataAnnotation = false) { property.SetOrRemoveAnnotation( @@ -619,10 +604,7 @@ public static string SetComputedColumnSql( /// or calculated when it is read. /// public static bool? GetIsStored([NotNull] this IProperty property) - { - var annotation = property.FindAnnotation(RelationalAnnotationNames.IsStored); - return annotation != null ? (bool?)annotation.Value : null; - } + => (bool?)property.FindAnnotation(RelationalAnnotationNames.IsStored)?.Value; /// /// Gets whether the value of the computed column this property is mapped to is stored in the database, or calculated when @@ -658,9 +640,7 @@ public static string SetComputedColumnSql( /// The property. /// The value to set. public static void SetIsStored([NotNull] this IMutableProperty property, bool? value) - => property.SetOrRemoveAnnotation( - RelationalAnnotationNames.IsStored, - value); + => property.SetOrRemoveAnnotation(RelationalAnnotationNames.IsStored, value); /// /// Sets whether the value of the computed column this property is mapped to is stored in the database, or calculated when @@ -693,11 +673,8 @@ public static void SetIsStored([NotNull] this IMutableProperty property, bool? v /// /// The property. /// The object that is used as the default value for the column this property is mapped to. - public static object GetDefaultValue([NotNull] this IProperty property) - { - var annotation = property.FindAnnotation(RelationalAnnotationNames.DefaultValue); - return annotation != null ? annotation.Value : null; - } + public static object? GetDefaultValue([NotNull] this IProperty property) + => property.FindAnnotation(RelationalAnnotationNames.DefaultValue)?.Value; /// /// Returns the object that is used as the default value for the column this property is mapped to. @@ -705,7 +682,7 @@ public static object GetDefaultValue([NotNull] this IProperty property) /// The property. /// The identifier of the table-like store object containing the column. /// The object that is used as the default value for the column this property is mapped to. - public static object GetDefaultValue([NotNull] this IProperty property, in StoreObjectIdentifier storeObject) + public static object? GetDefaultValue([NotNull] this IProperty property, in StoreObjectIdentifier storeObject) { var annotation = property.FindAnnotation(RelationalAnnotationNames.DefaultValue); if (annotation != null) @@ -727,7 +704,7 @@ public static object GetDefaultValue([NotNull] this IProperty property, in Store /// /// The property. /// The value to set. - public static void SetDefaultValue([NotNull] this IMutableProperty property, [CanBeNull] object value) + public static void SetDefaultValue([NotNull] this IMutableProperty property, [CanBeNull] object? value) => property.SetOrRemoveAnnotation(RelationalAnnotationNames.DefaultValue, ConvertDefaultValue(property, value)); /// @@ -737,9 +714,9 @@ public static void SetDefaultValue([NotNull] this IMutableProperty property, [Ca /// The value to set. /// Indicates whether the configuration was specified using a data annotation. /// The configured value. - public static object SetDefaultValue( + public static object? SetDefaultValue( [NotNull] this IConventionProperty property, - [CanBeNull] object value, + [CanBeNull] object? value, bool fromDataAnnotation = false) { property.SetOrRemoveAnnotation( @@ -748,7 +725,7 @@ public static object SetDefaultValue( return value; } - private static object ConvertDefaultValue([NotNull] IProperty property, [CanBeNull] object value) + private static object? ConvertDefaultValue([NotNull] IProperty property, [CanBeNull] object? value) { if (value == null || value == DBNull.Value) @@ -871,10 +848,7 @@ private static object ConvertDefaultValue([NotNull] IProperty property, [CanBeNu /// The property. /// A flag indicating if the property as capable of storing only fixed-length data, such as strings. public static bool? IsFixedLength([NotNull] this IProperty property) - { - var annotation = property.FindAnnotation(RelationalAnnotationNames.IsFixedLength); - return annotation != null ? (bool?)annotation.Value : null; - } + => (bool?)property.FindAnnotation(RelationalAnnotationNames.IsFixedLength)?.Value; /// /// Returns a flag indicating if the property as capable of storing only fixed-length data, such as strings. @@ -1004,11 +978,8 @@ private static bool IsOptionalSharingDependent(IEntityType entityType, in StoreO /// /// The property. /// The comment for the column this property is mapped to. - public static string GetComment([NotNull] this IProperty property) - { - var annotation = property.FindAnnotation(RelationalAnnotationNames.Comment); - return annotation != null ? (string)annotation.Value : null; - } + public static string? GetComment([NotNull] this IProperty property) + => (string?)property.FindAnnotation(RelationalAnnotationNames.Comment)?.Value; /// /// Returns the comment for the column this property is mapped to. @@ -1016,7 +987,7 @@ public static string GetComment([NotNull] this IProperty property) /// The property. /// The identifier of the table-like store object containing the column. /// The comment for the column this property is mapped to. - public static string GetComment([NotNull] this IProperty property, in StoreObjectIdentifier storeObject) + public static string? GetComment([NotNull] this IProperty property, in StoreObjectIdentifier storeObject) { var annotation = property.FindAnnotation(RelationalAnnotationNames.Comment); if (annotation != null) @@ -1038,7 +1009,7 @@ public static string GetComment([NotNull] this IProperty property, in StoreObjec /// /// The property. /// The comment for the column. - public static void SetComment([NotNull] this IMutableProperty property, [CanBeNull] string comment) + public static void SetComment([NotNull] this IMutableProperty property, [CanBeNull] string? comment) => property.SetOrRemoveAnnotation(RelationalAnnotationNames.Comment, comment); /// @@ -1048,9 +1019,9 @@ public static void SetComment([NotNull] this IMutableProperty property, [CanBeNu /// The comment for the column. /// Indicates whether the configuration was specified using a data annotation. /// The configured value. - public static string SetComment( + public static string? SetComment( [NotNull] this IConventionProperty property, - [CanBeNull] string comment, + [CanBeNull] string? comment, bool fromDataAnnotation = false) { property.SetOrRemoveAnnotation(RelationalAnnotationNames.Comment, comment, fromDataAnnotation); @@ -1072,11 +1043,8 @@ public static string SetComment( /// /// The property. /// The collation for the column this property is mapped to. - public static string GetCollation([NotNull] this IProperty property) - { - var annotation = property.FindAnnotation(RelationalAnnotationNames.Collation); - return annotation != null ? (string)annotation.Value : null; - } + public static string? GetCollation([NotNull] this IProperty property) + => (string?)property.FindAnnotation(RelationalAnnotationNames.Collation)?.Value; /// /// Returns the collation to be used for the column. @@ -1084,7 +1052,7 @@ public static string GetCollation([NotNull] this IProperty property) /// The property. /// The identifier of the table-like store object containing the column. /// The collation for the column this property is mapped to. - public static string GetCollation([NotNull] this IProperty property, in StoreObjectIdentifier storeObject) + public static string? GetCollation([NotNull] this IProperty property, in StoreObjectIdentifier storeObject) { var annotation = property.FindAnnotation(RelationalAnnotationNames.Collation); if (annotation != null) @@ -1106,7 +1074,7 @@ public static string GetCollation([NotNull] this IProperty property, in StoreObj /// /// The property. /// The collation for the column. - public static void SetCollation([NotNull] this IMutableProperty property, [CanBeNull] string collation) + public static void SetCollation([NotNull] this IMutableProperty property, [CanBeNull] string? collation) => property.SetOrRemoveAnnotation(RelationalAnnotationNames.Collation, collation); /// @@ -1116,9 +1084,9 @@ public static void SetCollation([NotNull] this IMutableProperty property, [CanBe /// The collation for the column. /// Indicates whether the configuration was specified using a data annotation. /// The configured value. - public static string SetCollation( + public static string? SetCollation( [NotNull] this IConventionProperty property, - [CanBeNull] string collation, + [CanBeNull] string? collation, bool fromDataAnnotation = false) { property.SetOrRemoveAnnotation(RelationalAnnotationNames.Collation, collation, fromDataAnnotation); @@ -1149,7 +1117,7 @@ public static RelationalTypeMapping GetRelationalTypeMapping([NotNull] this IPro /// The type mapping, or if none was found. [DebuggerStepThrough] [Obsolete("Use FindRelationalTypeMapping")] - public static RelationalTypeMapping FindRelationalMapping([NotNull] this IProperty property) + public static RelationalTypeMapping? FindRelationalMapping([NotNull] this IProperty property) => property.FindRelationalTypeMapping(); /// @@ -1158,8 +1126,8 @@ public static RelationalTypeMapping FindRelationalMapping([NotNull] this IProper /// The property. /// The type mapping, or if none was found. [DebuggerStepThrough] - public static RelationalTypeMapping FindRelationalTypeMapping([NotNull] this IProperty property) - => (RelationalTypeMapping)property.FindTypeMapping(); + public static RelationalTypeMapping? FindRelationalTypeMapping([NotNull] this IProperty property) + => (RelationalTypeMapping?)property.FindTypeMapping(); /// /// Returns the for the given property on a finalized model. @@ -1167,7 +1135,7 @@ public static RelationalTypeMapping FindRelationalTypeMapping([NotNull] this IPr /// The property. /// The identifier of the table-like store object containing the column. /// The type mapping, or if none was found. - public static RelationalTypeMapping FindRelationalTypeMapping( + public static RelationalTypeMapping? FindRelationalTypeMapping( [NotNull] this IProperty property, in StoreObjectIdentifier storeObject) => property.FindRelationalTypeMapping(); @@ -1184,7 +1152,7 @@ public static RelationalTypeMapping FindRelationalTypeMapping( /// The property. /// The identifier of the table-like store object containing the column. /// The property found, or if none was found. - public static IProperty FindSharedStoreObjectRootProperty( + public static IProperty? FindSharedStoreObjectRootProperty( [NotNull] this IProperty property, in StoreObjectIdentifier storeObject) => FindSharedObjectRootProperty(property, storeObject); @@ -1201,10 +1169,10 @@ public static IProperty FindSharedStoreObjectRootProperty( /// The property. /// The identifier of the table-like store object containing the column. /// The property found, or if none was found. - public static IMutableProperty FindSharedStoreObjectRootProperty( + public static IMutableProperty? FindSharedStoreObjectRootProperty( [NotNull] this IMutableProperty property, in StoreObjectIdentifier storeObject) - => (IMutableProperty)FindSharedObjectRootProperty(property, storeObject); + => (IMutableProperty?)FindSharedObjectRootProperty(property, storeObject); /// /// @@ -1218,12 +1186,12 @@ public static IMutableProperty FindSharedStoreObjectRootProperty( /// The property. /// The identifier of the table-like store object containing the column. /// The property found, or if none was found. - public static IConventionProperty FindSharedStoreObjectRootProperty( + public static IConventionProperty? FindSharedStoreObjectRootProperty( [NotNull] this IConventionProperty property, in StoreObjectIdentifier storeObject) - => (IConventionProperty)FindSharedObjectRootProperty(property, storeObject); + => (IConventionProperty?)FindSharedObjectRootProperty(property, storeObject); - private static IProperty FindSharedObjectRootProperty([NotNull] IProperty property, in StoreObjectIdentifier storeObject) + private static IProperty? FindSharedObjectRootProperty([NotNull] IProperty property, in StoreObjectIdentifier storeObject) { Check.NotNull(property, nameof(property)); @@ -1242,7 +1210,7 @@ private static IProperty FindSharedObjectRootProperty([NotNull] IProperty proper // Using a hashset is detrimental to the perf when there are no cycles for (var i = 0; i < Metadata.Internal.RelationalEntityTypeExtensions.MaxEntityTypesSharingTable; i++) { - IProperty linkedProperty = null; + IProperty? linkedProperty = null; foreach (var p in rootProperty.DeclaringEntityType .FindRowInternalForeignKeys(storeObject) .SelectMany(fk => fk.PrincipalEntityType.GetProperties())) @@ -1265,7 +1233,7 @@ private static IProperty FindSharedObjectRootProperty([NotNull] IProperty proper return rootProperty == property ? null : rootProperty; } - private static IProperty FindSharedObjectRootPrimaryKeyProperty([NotNull] IProperty property, in StoreObjectIdentifier storeObject) + private static IProperty? FindSharedObjectRootPrimaryKeyProperty([NotNull] IProperty property, in StoreObjectIdentifier storeObject) { if (!property.IsPrimaryKey()) { @@ -1291,7 +1259,7 @@ private static IProperty FindSharedObjectRootPrimaryKeyProperty([NotNull] IPrope return principalProperty == property ? null : principalProperty; } - private static IProperty FindSharedObjectRootConcurrencyTokenProperty( + private static IProperty? FindSharedObjectRootConcurrencyTokenProperty( [NotNull] IProperty property, in StoreObjectIdentifier storeObject) { @@ -1335,7 +1303,7 @@ private static IProperty FindSharedObjectRootConcurrencyTokenProperty( /// The property. /// The identifier of the table-like store object containing the column. /// An object that stores property facet overrides. - public static IAnnotatable FindOverrides([NotNull] this IProperty property, in StoreObjectIdentifier storeObject) + public static IAnnotatable? FindOverrides([NotNull] this IProperty property, in StoreObjectIdentifier storeObject) => RelationalPropertyOverrides.Find(property, storeObject); /// diff --git a/src/EFCore.Relational/Metadata/Builders/DbFunctionBuilder.cs b/src/EFCore.Relational/Metadata/Builders/DbFunctionBuilder.cs index bb69a0497bf..cb26118aa0e 100644 --- a/src/EFCore.Relational/Metadata/Builders/DbFunctionBuilder.cs +++ b/src/EFCore.Relational/Metadata/Builders/DbFunctionBuilder.cs @@ -7,6 +7,8 @@ using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Query.SqlExpressions; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Builders { /// @@ -39,7 +41,7 @@ public DbFunctionBuilder([NotNull] IMutableDbFunction function) /// /// The schema of the function in the database. /// The same builder instance so that multiple configuration calls can be chained. - public new virtual DbFunctionBuilder HasSchema([CanBeNull] string schema) + public new virtual DbFunctionBuilder HasSchema([CanBeNull] string? schema) => (DbFunctionBuilder)base.HasSchema(schema); /// @@ -67,7 +69,7 @@ public virtual DbFunctionBuilderBase IsNullable(bool nullable = true) /// /// The return store type of the function in the database. /// The same builder instance so that multiple configuration calls can be chained. - public virtual DbFunctionBuilder HasStoreType([CanBeNull] string storeType) + public virtual DbFunctionBuilder HasStoreType([CanBeNull] string? storeType) { Builder.HasStoreType(storeType, ConfigurationSource.Explicit); diff --git a/src/EFCore.Relational/Metadata/Builders/DbFunctionBuilderBase.cs b/src/EFCore.Relational/Metadata/Builders/DbFunctionBuilderBase.cs index e9527f38c42..4c48c001bea 100644 --- a/src/EFCore.Relational/Metadata/Builders/DbFunctionBuilderBase.cs +++ b/src/EFCore.Relational/Metadata/Builders/DbFunctionBuilderBase.cs @@ -9,6 +9,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Internal; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Builders { /// @@ -68,7 +70,7 @@ public virtual DbFunctionBuilderBase HasName([NotNull] string name) /// /// The schema of the function in the database. /// The same builder instance so that multiple configuration calls can be chained. - public virtual DbFunctionBuilderBase HasSchema([CanBeNull] string schema) + public virtual DbFunctionBuilderBase HasSchema([CanBeNull] string? schema) { Builder.HasSchema(schema, ConfigurationSource.Explicit); @@ -103,7 +105,7 @@ public virtual DbFunctionParameterBuilder HasParameter([NotNull] string name) /// /// A string that represents the current object. [EditorBrowsable(EditorBrowsableState.Never)] - public override string ToString() + public override string? ToString() => base.ToString(); /// @@ -113,7 +115,7 @@ public override string ToString() /// if the specified object is equal to the current object; otherwise, . [EditorBrowsable(EditorBrowsableState.Never)] // ReSharper disable once BaseObjectEqualsIsObjectEquals - public override bool Equals(object obj) + public override bool Equals(object? obj) => base.Equals(obj); /// diff --git a/src/EFCore.Relational/Metadata/Builders/DbFunctionParameterBuilder.cs b/src/EFCore.Relational/Metadata/Builders/DbFunctionParameterBuilder.cs index 2a45412830a..463d9f845fa 100644 --- a/src/EFCore.Relational/Metadata/Builders/DbFunctionParameterBuilder.cs +++ b/src/EFCore.Relational/Metadata/Builders/DbFunctionParameterBuilder.cs @@ -9,6 +9,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Internal; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Builders { /// @@ -33,7 +35,7 @@ public DbFunctionParameterBuilder([NotNull] IMutableDbFunctionParameter paramete { Check.NotNull(parameter, nameof(parameter)); - Builder = ((DbFunctionParameter)parameter).Builder; + Builder = ((DbFunctionParameter)parameter).Builder!; } private InternalDbFunctionParameterBuilder Builder { [DebuggerStepThrough] get; } @@ -56,7 +58,7 @@ public virtual IMutableDbFunctionParameter Metadata /// /// The store type of the function parameter in the database. /// The same builder instance so that further configuration calls can be chained. - public virtual DbFunctionParameterBuilder HasStoreType([CanBeNull] string storeType) + public virtual DbFunctionParameterBuilder HasStoreType([CanBeNull] string? storeType) { Builder.HasStoreType(storeType, ConfigurationSource.Explicit); @@ -82,7 +84,7 @@ public virtual DbFunctionParameterBuilder PropagatesNullability(bool propagatesN /// /// A string that represents the current object. [EditorBrowsable(EditorBrowsableState.Never)] - public override string ToString() + public override string? ToString() => base.ToString(); /// @@ -92,7 +94,7 @@ public override string ToString() /// if the specified object is equal to the current object; otherwise, . [EditorBrowsable(EditorBrowsableState.Never)] // ReSharper disable once BaseObjectEqualsIsObjectEquals - public override bool Equals(object obj) + public override bool Equals(object? obj) => base.Equals(obj); /// diff --git a/src/EFCore.Relational/Metadata/Builders/IConventionDbFunctionBuilder.cs b/src/EFCore.Relational/Metadata/Builders/IConventionDbFunctionBuilder.cs index 46d173d189a..12f13948909 100644 --- a/src/EFCore.Relational/Metadata/Builders/IConventionDbFunctionBuilder.cs +++ b/src/EFCore.Relational/Metadata/Builders/IConventionDbFunctionBuilder.cs @@ -7,6 +7,8 @@ using Microsoft.EntityFrameworkCore.Query.SqlExpressions; using Microsoft.EntityFrameworkCore.Storage; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Builders { /// @@ -28,7 +30,7 @@ public interface IConventionDbFunctionBuilder : IConventionAnnotatableBuilder /// The same builder instance if the configuration was applied, /// otherwise. /// - IConventionDbFunctionBuilder HasName([CanBeNull] string name, bool fromDataAnnotation = false); + IConventionDbFunctionBuilder? HasName([CanBeNull] string? name, bool fromDataAnnotation = false); /// /// Returns a value indicating whether the given name can be set for the database function. @@ -36,7 +38,7 @@ public interface IConventionDbFunctionBuilder : IConventionAnnotatableBuilder /// The name of the function in the database. /// Indicates whether the configuration was specified using a data annotation. /// if the given name can be set for the database function. - bool CanSetName([CanBeNull] string name, bool fromDataAnnotation = false); + bool CanSetName([CanBeNull] string? name, bool fromDataAnnotation = false); /// /// Sets the schema of the database function. @@ -47,7 +49,7 @@ public interface IConventionDbFunctionBuilder : IConventionAnnotatableBuilder /// The same builder instance if the configuration was applied, /// otherwise. /// - IConventionDbFunctionBuilder HasSchema([CanBeNull] string schema, bool fromDataAnnotation = false); + IConventionDbFunctionBuilder? HasSchema([CanBeNull] string? schema, bool fromDataAnnotation = false); /// /// Returns a value indicating whether the given schema can be set for the database function. @@ -55,7 +57,7 @@ public interface IConventionDbFunctionBuilder : IConventionAnnotatableBuilder /// The schema of the function in the database. /// Indicates whether the configuration was specified using a data annotation. /// if the given schema can be set for the database function. - bool CanSetSchema([CanBeNull] string schema, bool fromDataAnnotation = false); + bool CanSetSchema([CanBeNull] string? schema, bool fromDataAnnotation = false); /// /// Sets the value indicating whether the database function is built-in or not. @@ -66,7 +68,7 @@ public interface IConventionDbFunctionBuilder : IConventionAnnotatableBuilder /// The same builder instance if the configuration was applied, /// otherwise. /// - IConventionDbFunctionBuilder IsBuiltIn(bool builtIn, bool fromDataAnnotation = false); + IConventionDbFunctionBuilder? IsBuiltIn(bool builtIn, bool fromDataAnnotation = false); /// /// Returns a value indicating whether the given built-in can be set for the database function. @@ -85,7 +87,7 @@ public interface IConventionDbFunctionBuilder : IConventionAnnotatableBuilder /// The same builder instance if the configuration was applied, /// otherwise. /// - IConventionDbFunctionBuilder IsNullable(bool nullable, bool fromDataAnnotation = false); + IConventionDbFunctionBuilder? IsNullable(bool nullable, bool fromDataAnnotation = false); /// /// Returns a value indicating whether the given nullable can be set for the database function. @@ -104,7 +106,7 @@ public interface IConventionDbFunctionBuilder : IConventionAnnotatableBuilder /// The same builder instance if the configuration was applied, /// otherwise. /// - IConventionDbFunctionBuilder HasStoreType([CanBeNull] string storeType, bool fromDataAnnotation = false); + IConventionDbFunctionBuilder? HasStoreType([CanBeNull] string? storeType, bool fromDataAnnotation = false); /// /// Returns a value indicating whether the given store type can be set for the database function. @@ -112,7 +114,7 @@ public interface IConventionDbFunctionBuilder : IConventionAnnotatableBuilder /// The store type of the function in the database. /// Indicates whether the configuration was specified using a data annotation. /// if the given store type can be set for the database function. - bool CanSetStoreType([CanBeNull] string storeType, bool fromDataAnnotation = false); + bool CanSetStoreType([CanBeNull] string? storeType, bool fromDataAnnotation = false); /// /// Sets the return type mapping of the database function. @@ -123,7 +125,7 @@ public interface IConventionDbFunctionBuilder : IConventionAnnotatableBuilder /// The same builder instance if the configuration was applied, /// otherwise. /// - IConventionDbFunctionBuilder HasTypeMapping([CanBeNull] RelationalTypeMapping typeMapping, bool fromDataAnnotation = false); + IConventionDbFunctionBuilder? HasTypeMapping([CanBeNull] RelationalTypeMapping? typeMapping, bool fromDataAnnotation = false); /// /// Returns a value indicating whether the given return type mapping can be set for the database function. @@ -131,7 +133,7 @@ public interface IConventionDbFunctionBuilder : IConventionAnnotatableBuilder /// The return type mapping of the function in the database. /// Indicates whether the configuration was specified using a data annotation. /// if the given return type mapping can be set for the database function. - bool CanSetTypeMapping([CanBeNull] RelationalTypeMapping typeMapping, bool fromDataAnnotation = false); + bool CanSetTypeMapping([CanBeNull] RelationalTypeMapping? typeMapping, bool fromDataAnnotation = false); /// /// @@ -150,8 +152,8 @@ public interface IConventionDbFunctionBuilder : IConventionAnnotatableBuilder /// The same builder instance if the configuration was applied, /// otherwise. /// - IConventionDbFunctionBuilder HasTranslation( - [CanBeNull] Func, SqlExpression> translation, + IConventionDbFunctionBuilder? HasTranslation( + [CanBeNull] Func, SqlExpression>? translation, bool fromDataAnnotation = false); /// @@ -161,7 +163,7 @@ IConventionDbFunctionBuilder HasTranslation( /// Indicates whether the configuration was specified using a data annotation. /// if the given translation can be set for the database function. bool CanSetTranslation( - [CanBeNull] Func, SqlExpression> translation, + [CanBeNull] Func, SqlExpression>? translation, bool fromDataAnnotation = false); /// diff --git a/src/EFCore.Relational/Metadata/Builders/IConventionDbFunctionParameterBuilder.cs b/src/EFCore.Relational/Metadata/Builders/IConventionDbFunctionParameterBuilder.cs index a4e8252b673..b37d69b9da7 100644 --- a/src/EFCore.Relational/Metadata/Builders/IConventionDbFunctionParameterBuilder.cs +++ b/src/EFCore.Relational/Metadata/Builders/IConventionDbFunctionParameterBuilder.cs @@ -4,6 +4,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Storage; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Builders { /// @@ -21,8 +23,8 @@ public interface IConventionDbFunctionParameterBuilder : IConventionAnnotatableB /// /// The store type of the function parameter in the database. /// Indicates whether the configuration was specified using a data annotation. - /// The same builder instance if the configuration was applied; null otherwise. - IConventionDbFunctionParameterBuilder HasStoreType([CanBeNull] string storeType, bool fromDataAnnotation = false); + /// The same builder instance if the configuration was applied; otherwise. + IConventionDbFunctionParameterBuilder? HasStoreType([CanBeNull] string? storeType, bool fromDataAnnotation = false); /// /// Returns a value indicating whether the store type can be set for this property @@ -31,16 +33,16 @@ public interface IConventionDbFunctionParameterBuilder : IConventionAnnotatableB /// The store type of the function parameter in the database. /// Indicates whether the configuration was specified using a data annotation. /// if the store type can be set for this property. - bool CanSetStoreType([CanBeNull] string storeType, bool fromDataAnnotation = false); + bool CanSetStoreType([CanBeNull] string? storeType, bool fromDataAnnotation = false); /// /// Sets the of the function parameter. /// /// The type mapping to use for the function parameter. /// Indicates whether the configuration was specified using a data annotation. - /// The same builder instance if the configuration was applied; null otherwise. - IConventionDbFunctionParameterBuilder HasTypeMapping( - [CanBeNull] RelationalTypeMapping typeMapping, + /// The same builder instance if the configuration was applied; otherwise. + IConventionDbFunctionParameterBuilder? HasTypeMapping( + [CanBeNull] RelationalTypeMapping? typeMapping, bool fromDataAnnotation = false); /// @@ -50,6 +52,6 @@ IConventionDbFunctionParameterBuilder HasTypeMapping( /// The type mapping to use for the function parameter. /// Indicates whether the configuration was specified using a data annotation. /// if the type mapping can be set for this property. - bool CanSetTypeMapping([CanBeNull] RelationalTypeMapping typeMapping, bool fromDataAnnotation = false); + bool CanSetTypeMapping([CanBeNull] RelationalTypeMapping? typeMapping, bool fromDataAnnotation = false); } } diff --git a/src/EFCore.Relational/Metadata/Builders/IConventionSequenceBuilder.cs b/src/EFCore.Relational/Metadata/Builders/IConventionSequenceBuilder.cs index e5f787e15a1..876e74680ab 100644 --- a/src/EFCore.Relational/Metadata/Builders/IConventionSequenceBuilder.cs +++ b/src/EFCore.Relational/Metadata/Builders/IConventionSequenceBuilder.cs @@ -4,6 +4,8 @@ using System; using JetBrains.Annotations; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Builders { /// @@ -25,7 +27,7 @@ public interface IConventionSequenceBuilder : IConventionAnnotatableBuilder /// The same builder instance if the configuration was applied, /// otherwise. /// - IConventionSequenceBuilder HasType([CanBeNull] Type type, bool fromDataAnnotation = false); + IConventionSequenceBuilder? HasType([CanBeNull] Type? type, bool fromDataAnnotation = false); /// /// Returns a value indicating whether the given type can be set for the sequence. @@ -33,7 +35,7 @@ public interface IConventionSequenceBuilder : IConventionAnnotatableBuilder /// The type of values returned by the sequence. /// Indicates whether the configuration was specified using a data annotation. /// if the given type can be set for the sequence. - bool CanSetType([CanBeNull] Type type, bool fromDataAnnotation = false); + bool CanSetType([CanBeNull] Type? type, bool fromDataAnnotation = false); /// /// Sets the sequence to increment by the given amount when generating each next value. @@ -44,7 +46,7 @@ public interface IConventionSequenceBuilder : IConventionAnnotatableBuilder /// The same builder instance if the configuration was applied, /// otherwise. /// - IConventionSequenceBuilder IncrementsBy(int? increment, bool fromDataAnnotation = false); + IConventionSequenceBuilder? IncrementsBy(int? increment, bool fromDataAnnotation = false); /// /// Returns a value indicating whether the given increment can be set for the sequence. @@ -63,7 +65,7 @@ public interface IConventionSequenceBuilder : IConventionAnnotatableBuilder /// The same builder instance if the configuration was applied, /// otherwise. /// - IConventionSequenceBuilder StartsAt(long? startValue, bool fromDataAnnotation = false); + IConventionSequenceBuilder? StartsAt(long? startValue, bool fromDataAnnotation = false); /// /// Returns a value indicating whether the given starting value can be set for the sequence. @@ -82,7 +84,7 @@ public interface IConventionSequenceBuilder : IConventionAnnotatableBuilder /// The same builder instance if the configuration was applied, /// otherwise. /// - IConventionSequenceBuilder HasMax(long? maximum, bool fromDataAnnotation = false); + IConventionSequenceBuilder? HasMax(long? maximum, bool fromDataAnnotation = false); /// /// Returns a value indicating whether the given maximum value can be set for the sequence. @@ -101,7 +103,7 @@ public interface IConventionSequenceBuilder : IConventionAnnotatableBuilder /// The same builder instance if the configuration was applied, /// otherwise. /// - IConventionSequenceBuilder HasMin(long? minimum, bool fromDataAnnotation = false); + IConventionSequenceBuilder? HasMin(long? minimum, bool fromDataAnnotation = false); /// /// Returns a value indicating whether the given minimum value can be set for the sequence. @@ -121,7 +123,7 @@ public interface IConventionSequenceBuilder : IConventionAnnotatableBuilder /// The same builder instance if the configuration was applied, /// otherwise. /// - IConventionSequenceBuilder IsCyclic(bool? cyclic, bool fromDataAnnotation = false); + IConventionSequenceBuilder? IsCyclic(bool? cyclic, bool fromDataAnnotation = false); /// /// Returns a value indicating whether the given cyclicity can be set for the sequence. diff --git a/src/EFCore.Relational/Metadata/Builders/SequenceBuilder.cs b/src/EFCore.Relational/Metadata/Builders/SequenceBuilder.cs index 052dfbc3f8b..1498ec69b29 100644 --- a/src/EFCore.Relational/Metadata/Builders/SequenceBuilder.cs +++ b/src/EFCore.Relational/Metadata/Builders/SequenceBuilder.cs @@ -9,6 +9,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Internal; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Builders { /// @@ -110,7 +112,7 @@ public virtual SequenceBuilder IsCyclic(bool cyclic = true) /// /// A string that represents the current object. [EditorBrowsable(EditorBrowsableState.Never)] - public override string ToString() + public override string? ToString() => base.ToString(); /// @@ -120,7 +122,7 @@ public override string ToString() /// if the specified object is equal to the current object; otherwise, . [EditorBrowsable(EditorBrowsableState.Never)] // ReSharper disable once BaseObjectEqualsIsObjectEquals - public override bool Equals(object obj) + public override bool Equals(object? obj) => base.Equals(obj); /// diff --git a/src/EFCore.Relational/Metadata/Builders/TableBuilder.cs b/src/EFCore.Relational/Metadata/Builders/TableBuilder.cs index 1a8101095d3..667ff6340d4 100644 --- a/src/EFCore.Relational/Metadata/Builders/TableBuilder.cs +++ b/src/EFCore.Relational/Metadata/Builders/TableBuilder.cs @@ -6,6 +6,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Infrastructure; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Builders { /// @@ -23,7 +25,7 @@ public class TableBuilder /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [EntityFrameworkInternal] - public TableBuilder([NotNull] string name, [CanBeNull] string schema, [NotNull] IMutableEntityType entityType) + public TableBuilder([NotNull] string name, [CanBeNull] string? schema, [NotNull] IMutableEntityType entityType) { EntityType = entityType; } @@ -48,7 +50,7 @@ public virtual TableBuilder ExcludeFromMigrations(bool excluded = true) /// /// A string that represents the current object. [EditorBrowsable(EditorBrowsableState.Never)] - public override string ToString() + public override string? ToString() => base.ToString(); /// @@ -57,7 +59,7 @@ public override string ToString() /// The object to compare with the current object. /// if the specified object is equal to the current object; otherwise, . [EditorBrowsable(EditorBrowsableState.Never)] - public override bool Equals(object obj) + public override bool Equals(object? obj) => base.Equals(obj); /// diff --git a/src/EFCore.Relational/Metadata/Builders/TableBuilder`.cs b/src/EFCore.Relational/Metadata/Builders/TableBuilder`.cs index 3abfff21e74..301f3ec2eaf 100644 --- a/src/EFCore.Relational/Metadata/Builders/TableBuilder`.cs +++ b/src/EFCore.Relational/Metadata/Builders/TableBuilder`.cs @@ -4,6 +4,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Infrastructure; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Builders { /// @@ -23,7 +25,7 @@ public class TableBuilder : TableBuilder /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [EntityFrameworkInternal] - public TableBuilder([NotNull] string name, [CanBeNull] string schema, [NotNull] IMutableEntityType entityType) + public TableBuilder([NotNull] string name, [CanBeNull] string? schema, [NotNull] IMutableEntityType entityType) : base(name, schema, entityType) { } diff --git a/src/EFCore.Relational/Metadata/Builders/TableValuedFunctionBuilder.cs b/src/EFCore.Relational/Metadata/Builders/TableValuedFunctionBuilder.cs index 6ed5c1fd3c9..7615b673451 100644 --- a/src/EFCore.Relational/Metadata/Builders/TableValuedFunctionBuilder.cs +++ b/src/EFCore.Relational/Metadata/Builders/TableValuedFunctionBuilder.cs @@ -4,6 +4,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Infrastructure; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Builders { /// @@ -36,7 +38,7 @@ public TableValuedFunctionBuilder([NotNull] IMutableDbFunction function) /// /// The schema of the function in the database. /// The same builder instance so that multiple configuration calls can be chained. - public new virtual TableValuedFunctionBuilder HasSchema([CanBeNull] string schema) + public new virtual TableValuedFunctionBuilder HasSchema([CanBeNull] string? schema) => (TableValuedFunctionBuilder)base.HasSchema(schema); } } diff --git a/src/EFCore.Relational/Metadata/Conventions/DbFunctionTypeMappingConvention.cs b/src/EFCore.Relational/Metadata/Conventions/DbFunctionTypeMappingConvention.cs index 71572aadc61..46b471a136f 100644 --- a/src/EFCore.Relational/Metadata/Conventions/DbFunctionTypeMappingConvention.cs +++ b/src/EFCore.Relational/Metadata/Conventions/DbFunctionTypeMappingConvention.cs @@ -7,6 +7,8 @@ using Microsoft.EntityFrameworkCore.Storage; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// @@ -44,7 +46,7 @@ public virtual void ProcessModelFinalizing( // TODO: This check needs to be updated to skip over enumerable parameter of aggregate. foreach (var parameter in dbFunction.Parameters) { - parameter.Builder.HasTypeMapping( + parameter.Builder!.HasTypeMapping( !string.IsNullOrEmpty(parameter.StoreType) ? _relationalTypeMappingSource.FindMapping(parameter.StoreType) : _relationalTypeMappingSource.FindMapping(parameter.ClrType)); diff --git a/src/EFCore.Relational/Metadata/Conventions/EntityTypeHierarchyMappingConvention.cs b/src/EFCore.Relational/Metadata/Conventions/EntityTypeHierarchyMappingConvention.cs index 21f6b1342ec..412d78a7953 100644 --- a/src/EFCore.Relational/Metadata/Conventions/EntityTypeHierarchyMappingConvention.cs +++ b/src/EFCore.Relational/Metadata/Conventions/EntityTypeHierarchyMappingConvention.cs @@ -7,6 +7,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// @@ -50,7 +52,7 @@ public virtual void ProcessModelFinalizing( && !entityType.FindDeclaredForeignKeys(pk.Properties) .Any(fk => fk.PrincipalKey.IsPrimaryKey() && fk.PrincipalEntityType.IsAssignableFrom(entityType))) { - entityType.Builder.HasRelationship(entityType.BaseType, pk.Properties, entityType.BaseType.FindPrimaryKey()) + entityType.Builder.HasRelationship(entityType.BaseType, pk.Properties, entityType.BaseType.FindPrimaryKey()!)! .IsUnique(true); } diff --git a/src/EFCore.Relational/Metadata/Conventions/Infrastructure/RelationalConventionSetBuilder.cs b/src/EFCore.Relational/Metadata/Conventions/Infrastructure/RelationalConventionSetBuilder.cs index 7fa15a200fd..676c00f7e91 100644 --- a/src/EFCore.Relational/Metadata/Conventions/Infrastructure/RelationalConventionSetBuilder.cs +++ b/src/EFCore.Relational/Metadata/Conventions/Infrastructure/RelationalConventionSetBuilder.cs @@ -5,6 +5,8 @@ using Microsoft.EntityFrameworkCore.Utilities; using Microsoft.Extensions.DependencyInjection; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure { /// diff --git a/src/EFCore.Relational/Metadata/Conventions/Infrastructure/RelationalConventionSetBuilderDependencies.cs b/src/EFCore.Relational/Metadata/Conventions/Infrastructure/RelationalConventionSetBuilderDependencies.cs index 46b2e28feba..e3c71fc1452 100644 --- a/src/EFCore.Relational/Metadata/Conventions/Infrastructure/RelationalConventionSetBuilderDependencies.cs +++ b/src/EFCore.Relational/Metadata/Conventions/Infrastructure/RelationalConventionSetBuilderDependencies.cs @@ -6,6 +6,8 @@ using Microsoft.EntityFrameworkCore.Utilities; using Microsoft.Extensions.DependencyInjection; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure { /// diff --git a/src/EFCore.Relational/Metadata/Conventions/RelationalColumnAttributeConvention.cs b/src/EFCore.Relational/Metadata/Conventions/RelationalColumnAttributeConvention.cs index a7275a67ae0..f2777eaea29 100644 --- a/src/EFCore.Relational/Metadata/Conventions/RelationalColumnAttributeConvention.cs +++ b/src/EFCore.Relational/Metadata/Conventions/RelationalColumnAttributeConvention.cs @@ -7,6 +7,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// diff --git a/src/EFCore.Relational/Metadata/Conventions/RelationalColumnCommentAttributeConvention.cs b/src/EFCore.Relational/Metadata/Conventions/RelationalColumnCommentAttributeConvention.cs index f6f50f0741b..e2f64e89d34 100644 --- a/src/EFCore.Relational/Metadata/Conventions/RelationalColumnCommentAttributeConvention.cs +++ b/src/EFCore.Relational/Metadata/Conventions/RelationalColumnCommentAttributeConvention.cs @@ -6,6 +6,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// diff --git a/src/EFCore.Relational/Metadata/Conventions/RelationalDbFunctionAttributeConvention.cs b/src/EFCore.Relational/Metadata/Conventions/RelationalDbFunctionAttributeConvention.cs index 499d090ad28..f9148066750 100644 --- a/src/EFCore.Relational/Metadata/Conventions/RelationalDbFunctionAttributeConvention.cs +++ b/src/EFCore.Relational/Metadata/Conventions/RelationalDbFunctionAttributeConvention.cs @@ -7,6 +7,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// diff --git a/src/EFCore.Relational/Metadata/Conventions/RelationalMaxIdentifierLengthConvention.cs b/src/EFCore.Relational/Metadata/Conventions/RelationalMaxIdentifierLengthConvention.cs index b8b61188626..c6f696afc41 100644 --- a/src/EFCore.Relational/Metadata/Conventions/RelationalMaxIdentifierLengthConvention.cs +++ b/src/EFCore.Relational/Metadata/Conventions/RelationalMaxIdentifierLengthConvention.cs @@ -5,6 +5,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// diff --git a/src/EFCore.Relational/Metadata/Conventions/RelationalModelConvention.cs b/src/EFCore.Relational/Metadata/Conventions/RelationalModelConvention.cs index 365a20fddfb..3d8e7dcfc4c 100644 --- a/src/EFCore.Relational/Metadata/Conventions/RelationalModelConvention.cs +++ b/src/EFCore.Relational/Metadata/Conventions/RelationalModelConvention.cs @@ -5,6 +5,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata.Internal; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// diff --git a/src/EFCore.Relational/Metadata/Conventions/RelationalQueryFilterRewritingConvention.cs b/src/EFCore.Relational/Metadata/Conventions/RelationalQueryFilterRewritingConvention.cs index 9aad20eed92..47ff3d83192 100644 --- a/src/EFCore.Relational/Metadata/Conventions/RelationalQueryFilterRewritingConvention.cs +++ b/src/EFCore.Relational/Metadata/Conventions/RelationalQueryFilterRewritingConvention.cs @@ -10,6 +10,8 @@ using Microsoft.EntityFrameworkCore.Query.Internal; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// @@ -80,7 +82,7 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp if (methodName == nameof(RelationalQueryableExtensions.FromSqlRaw)) { - sql = (string)((ConstantExpression)methodCallExpression.Arguments[1]).Value; + sql = (string)((ConstantExpression)methodCallExpression.Arguments[1]).Value!; argument = methodCallExpression.Arguments[2]; } else diff --git a/src/EFCore.Relational/Metadata/Conventions/RelationalTableAttributeConvention.cs b/src/EFCore.Relational/Metadata/Conventions/RelationalTableAttributeConvention.cs index c32c7214ebc..ee2b64f90d9 100644 --- a/src/EFCore.Relational/Metadata/Conventions/RelationalTableAttributeConvention.cs +++ b/src/EFCore.Relational/Metadata/Conventions/RelationalTableAttributeConvention.cs @@ -6,6 +6,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// diff --git a/src/EFCore.Relational/Metadata/Conventions/RelationalTableCommentAttributeConvention.cs b/src/EFCore.Relational/Metadata/Conventions/RelationalTableCommentAttributeConvention.cs index 98055cbb0ea..8011e9de48e 100644 --- a/src/EFCore.Relational/Metadata/Conventions/RelationalTableCommentAttributeConvention.cs +++ b/src/EFCore.Relational/Metadata/Conventions/RelationalTableCommentAttributeConvention.cs @@ -5,6 +5,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// diff --git a/src/EFCore.Relational/Metadata/Conventions/RelationalValueGenerationConvention.cs b/src/EFCore.Relational/Metadata/Conventions/RelationalValueGenerationConvention.cs index c4bfa170505..a2be599a241 100644 --- a/src/EFCore.Relational/Metadata/Conventions/RelationalValueGenerationConvention.cs +++ b/src/EFCore.Relational/Metadata/Conventions/RelationalValueGenerationConvention.cs @@ -6,6 +6,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// @@ -41,8 +43,8 @@ public RelationalValueGenerationConvention( public virtual void ProcessPropertyAnnotationChanged( IConventionPropertyBuilder propertyBuilder, string name, - IConventionAnnotation annotation, - IConventionAnnotation oldAnnotation, + IConventionAnnotation? annotation, + IConventionAnnotation? oldAnnotation, IConventionContext context) { var property = propertyBuilder.Metadata; @@ -67,8 +69,8 @@ public virtual void ProcessPropertyAnnotationChanged( public virtual void ProcessEntityTypeAnnotationChanged( IConventionEntityTypeBuilder entityTypeBuilder, string name, - IConventionAnnotation annotation, - IConventionAnnotation oldAnnotation, + IConventionAnnotation? annotation, + IConventionAnnotation? oldAnnotation, IConventionContext context) { if (name == RelationalAnnotationNames.TableName) @@ -76,7 +78,7 @@ public virtual void ProcessEntityTypeAnnotationChanged( var schema = entityTypeBuilder.Metadata.GetSchema(); ProcessTableChanged( entityTypeBuilder, - (string)oldAnnotation?.Value ?? entityTypeBuilder.Metadata.GetDefaultTableName(), + (string?)oldAnnotation?.Value ?? entityTypeBuilder.Metadata.GetDefaultTableName(), schema, entityTypeBuilder.Metadata.GetTableName(), schema); @@ -87,7 +89,7 @@ public virtual void ProcessEntityTypeAnnotationChanged( ProcessTableChanged( entityTypeBuilder, tableName, - (string)oldAnnotation?.Value ?? entityTypeBuilder.Metadata.GetDefaultSchema(), + (string?)oldAnnotation?.Value ?? entityTypeBuilder.Metadata.GetDefaultSchema(), tableName, entityTypeBuilder.Metadata.GetSchema()); } @@ -95,10 +97,10 @@ public virtual void ProcessEntityTypeAnnotationChanged( private void ProcessTableChanged( IConventionEntityTypeBuilder entityTypeBuilder, - string oldTable, - string oldSchema, - string newTable, - string newSchema) + string? oldTable, + string? oldSchema, + string? newTable, + string? newSchema) { var primaryKey = entityTypeBuilder.Metadata.FindPrimaryKey(); if (primaryKey == null) @@ -122,7 +124,7 @@ private void ProcessTableChanged( foreach (var property in primaryKey.Properties) { - property.Builder.ValueGenerated(GetValueGenerated(property, StoreObjectIdentifier.Table(newTable, newSchema))); + property.Builder.ValueGenerated(GetValueGenerated(property, StoreObjectIdentifier.Table(newTable!, newSchema))); } } diff --git a/src/EFCore.Relational/Metadata/Conventions/SequenceUniquificationConvention.cs b/src/EFCore.Relational/Metadata/Conventions/SequenceUniquificationConvention.cs index c0bc8e2d55c..2591fecb7cc 100644 --- a/src/EFCore.Relational/Metadata/Conventions/SequenceUniquificationConvention.cs +++ b/src/EFCore.Relational/Metadata/Conventions/SequenceUniquificationConvention.cs @@ -9,6 +9,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata.Internal; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// @@ -41,7 +43,7 @@ public virtual void ProcessModelFinalizing( { var model = modelBuilder.Metadata; var modelSequences = - (SortedDictionary<(string Name, string Schema), Sequence>)model[RelationalAnnotationNames.Sequences]; + (SortedDictionary<(string Name, string Schema), Sequence>?)model[RelationalAnnotationNames.Sequences]; if (modelSequences != null) { diff --git a/src/EFCore.Relational/Metadata/Conventions/SharedTableConvention.cs b/src/EFCore.Relational/Metadata/Conventions/SharedTableConvention.cs index 52af47d29b6..b4531f39857 100644 --- a/src/EFCore.Relational/Metadata/Conventions/SharedTableConvention.cs +++ b/src/EFCore.Relational/Metadata/Conventions/SharedTableConvention.cs @@ -11,6 +11,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata.Internal; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// @@ -41,7 +43,7 @@ public virtual void ProcessModelFinalizing( IConventionContext context) { var maxLength = modelBuilder.Metadata.GetMaxIdentifierLength(); - var tables = new Dictionary<(string TableName, string Schema), List>(); + var tables = new Dictionary<(string TableName, string? Schema), List>(); TryUniquifyTableNames(modelBuilder.Metadata, tables, maxLength); @@ -68,20 +70,22 @@ public virtual void ProcessModelFinalizing( private static void TryUniquifyTableNames( IConventionModel model, - Dictionary<(string Name, string Schema), List> tables, + Dictionary<(string Name, string? Schema), List> tables, int maxLength) { - Dictionary<(string Name, string Schema), Dictionary<(string Name, string Schema), List>> clashingTables + Dictionary<(string Name, string? Schema), Dictionary<(string Name, string? Schema), List>>? clashingTables = null; foreach (var entityType in model.GetEntityTypes()) { - var table = (Name: entityType.GetTableName(), Schema: entityType.GetSchema()); - if (table.Name == null + var tableName = entityType.GetTableName(); + if (tableName == null || entityType.FindPrimaryKey() == null) { continue; } + var table = (Name: tableName, Schema: entityType.GetSchema()); + if (!tables.TryGetValue(table, out var entityTypes)) { entityTypes = new List(); @@ -101,22 +105,17 @@ private static void TryUniquifyTableNames( if (table.Name.Length == maxLength) { - var originalName = entityType.GetDefaultTableName(truncate: false); + var originalName = entityType.GetDefaultTableName(truncate: false)!; if (originalName.Length == maxLength) { continue; } - if (clashingTables == null) - { - clashingTables = - new Dictionary<(string Name, string Schema), - Dictionary<(string Name, string Schema), List>>(); - } + clashingTables ??= new(); if (!clashingTables.TryGetValue(table, out var clashingSubTables)) { - clashingSubTables = new Dictionary<(string Name, string Schema), List>(); + clashingSubTables = new Dictionary<(string Name, string? Schema), List>(); clashingTables[table] = clashingSubTables; } @@ -174,9 +173,9 @@ private static void TryUniquifyColumnNames( continue; } - var identifyingMemberInfo = property.PropertyInfo ?? (MemberInfo)property.FieldInfo; + var identifyingMemberInfo = property.PropertyInfo ?? (MemberInfo?)property.FieldInfo; if ((identifyingMemberInfo != null - && identifyingMemberInfo.IsSameAs(otherProperty.PropertyInfo ?? (MemberInfo)otherProperty.FieldInfo)) + && identifyingMemberInfo.IsSameAs(otherProperty.PropertyInfo ?? (MemberInfo?)otherProperty.FieldInfo)) || (property.IsPrimaryKey() && otherProperty.IsPrimaryKey()) || (property.IsConcurrencyToken && otherProperty.IsConcurrencyToken) || (!property.Builder.CanSetColumnName(null) && !otherProperty.Builder.CanSetColumnName(null))) @@ -223,7 +222,7 @@ private static void TryUniquifyColumnNames( } } - private static string TryUniquify( + private static string? TryUniquify( IConventionProperty property, string columnName, Dictionary properties, @@ -310,7 +309,7 @@ protected virtual bool AreCompatible( in StoreObjectIdentifier storeObject) => key.AreCompatible(duplicateKey, storeObject, shouldThrow: false); - private static string TryUniquify( + private static string? TryUniquify( IConventionKey key, string keyName, Dictionary keys, @@ -380,7 +379,7 @@ protected virtual bool AreCompatible( in StoreObjectIdentifier storeObject) => index.AreCompatible(duplicateIndex, storeObject, shouldThrow: false); - private static string TryUniquify( + private static string? TryUniquify( IConventionIndex index, string indexName, Dictionary indexes, @@ -471,7 +470,7 @@ protected virtual bool AreCompatible( in StoreObjectIdentifier storeObject) => foreignKey.AreCompatible(duplicateForeignKey, storeObject, shouldThrow: false); - private static string TryUniquify( + private static string? TryUniquify( IConventionForeignKey foreignKey, string foreignKeyName, Dictionary foreignKeys, diff --git a/src/EFCore.Relational/Metadata/Conventions/StoreGenerationConvention.cs b/src/EFCore.Relational/Metadata/Conventions/StoreGenerationConvention.cs index 229944fb229..4eacadf829e 100644 --- a/src/EFCore.Relational/Metadata/Conventions/StoreGenerationConvention.cs +++ b/src/EFCore.Relational/Metadata/Conventions/StoreGenerationConvention.cs @@ -7,6 +7,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// @@ -42,8 +44,8 @@ public StoreGenerationConvention( public virtual void ProcessPropertyAnnotationChanged( IConventionPropertyBuilder propertyBuilder, string name, - IConventionAnnotation annotation, - IConventionAnnotation oldAnnotation, + IConventionAnnotation? annotation, + IConventionAnnotation? oldAnnotation, IConventionContext context) { if (annotation == null diff --git a/src/EFCore.Relational/Metadata/Conventions/TableNameFromDbSetConvention.cs b/src/EFCore.Relational/Metadata/Conventions/TableNameFromDbSetConvention.cs index 8b30cc06273..e2f3d586fa0 100644 --- a/src/EFCore.Relational/Metadata/Conventions/TableNameFromDbSetConvention.cs +++ b/src/EFCore.Relational/Metadata/Conventions/TableNameFromDbSetConvention.cs @@ -7,6 +7,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// @@ -26,7 +28,7 @@ public TableNameFromDbSetConvention( [NotNull] RelationalConventionSetBuilderDependencies relationalDependencies) { _sets = new Dictionary(); - List ambiguousTypes = null; + List? ambiguousTypes = null; foreach (var set in dependencies.SetFinder.FindSets(dependencies.ContextType)) { if (!_sets.ContainsKey(set.Type)) @@ -69,8 +71,8 @@ public TableNameFromDbSetConvention( /// Additional information associated with convention execution. public virtual void ProcessEntityTypeBaseTypeChanged( IConventionEntityTypeBuilder entityTypeBuilder, - IConventionEntityType newBaseType, - IConventionEntityType oldBaseType, + IConventionEntityType? newBaseType, + IConventionEntityType? oldBaseType, IConventionContext context) { var entityType = entityTypeBuilder.Metadata; diff --git a/src/EFCore.Relational/Metadata/Conventions/TableSharingConcurrencyTokenConvention.cs b/src/EFCore.Relational/Metadata/Conventions/TableSharingConcurrencyTokenConvention.cs index 4728edf5892..14331c19421 100644 --- a/src/EFCore.Relational/Metadata/Conventions/TableSharingConcurrencyTokenConvention.cs +++ b/src/EFCore.Relational/Metadata/Conventions/TableSharingConcurrencyTokenConvention.cs @@ -8,6 +8,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// @@ -43,7 +45,7 @@ public virtual void ProcessModelFinalizing( IConventionModelBuilder modelBuilder, IConventionContext context) { - var tableToEntityTypes = new Dictionary<(string Name, string Schema), List>(); + var tableToEntityTypes = new Dictionary<(string Name, string? Schema), List>(); foreach (var entityType in modelBuilder.Metadata.GetEntityTypes()) { var tableName = entityType.GetTableName(); @@ -78,7 +80,7 @@ public virtual void ProcessModelFinalizing( var concurrencyColumnName = concurrencyColumn.Key; var propertiesMappedToConcurrencyColumn = concurrencyColumn.Value; - Dictionary entityTypesMissingConcurrencyColumn = null; + Dictionary? entityTypesMissingConcurrencyColumn = null; foreach (var entityType in mappedTypes) { var foundMappedProperty = !IsConcurrencyTokenMissing(propertiesMappedToConcurrencyColumn, entityType, mappedTypes) @@ -114,10 +116,10 @@ public virtual void ProcessModelFinalizing( entityTypeToExampleProperty.Key.Builder.CreateUniqueProperty( exampleProperty.ClrType, ConcurrencyPropertyPrefix + exampleProperty.Name, - !exampleProperty.IsNullable) - .HasColumnName(concurrencyColumnName) - .HasColumnType(exampleProperty.GetColumnType()) - .IsConcurrencyToken(true) + !exampleProperty.IsNullable)! + .HasColumnName(concurrencyColumnName)! + .HasColumnType(exampleProperty.GetColumnType())! + .IsConcurrencyToken(true)! .ValueGenerated(exampleProperty.ValueGenerated); } } @@ -131,7 +133,7 @@ public virtual void ProcessModelFinalizing( /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [EntityFrameworkInternal] - public static Dictionary> GetConcurrencyTokensMap( + public static Dictionary>? GetConcurrencyTokensMap( in StoreObjectIdentifier storeObject, [NotNull] IReadOnlyList mappedTypes) { @@ -140,7 +142,7 @@ public static Dictionary> GetConcurrencyTokensMap( return null; } - Dictionary> concurrencyColumns = null; + Dictionary>? concurrencyColumns = null; var nonHierarchyTypesCount = 0; foreach (var entityType in mappedTypes) { @@ -212,7 +214,7 @@ public static bool IsConcurrencyTokenMissing( continue; } - var linkingFks = declaringEntityType.FindForeignKeys(declaringEntityType.FindPrimaryKey().Properties) + var linkingFks = declaringEntityType.FindForeignKeys(declaringEntityType.FindPrimaryKey()!.Properties) .Where( fk => fk.PrincipalKey.IsPrimaryKey() && mappedTypes.Contains(fk.PrincipalEntityType)).ToList(); diff --git a/src/EFCore.Relational/Metadata/Conventions/TableValuedDbFunctionConvention.cs b/src/EFCore.Relational/Metadata/Conventions/TableValuedDbFunctionConvention.cs index 55e9126740d..28eb480a9dc 100644 --- a/src/EFCore.Relational/Metadata/Conventions/TableValuedDbFunctionConvention.cs +++ b/src/EFCore.Relational/Metadata/Conventions/TableValuedDbFunctionConvention.cs @@ -9,6 +9,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// @@ -59,7 +61,7 @@ private void ProcessDbFunctionAdded( return; } - var elementType = function.ReturnType.TryGetElementType(typeof(IQueryable<>)); + var elementType = function.ReturnType.TryGetElementType(typeof(IQueryable<>))!; if (!elementType.IsValidEntityType()) { throw new InvalidOperationException( @@ -76,7 +78,7 @@ private void ProcessDbFunctionAdded( return; } - IConventionEntityTypeBuilder entityTypeBuilder; + IConventionEntityTypeBuilder? entityTypeBuilder; if (entityType != null) { entityTypeBuilder = entityType.Builder; diff --git a/src/EFCore.Relational/Metadata/IConventionDbFunction.cs b/src/EFCore.Relational/Metadata/IConventionDbFunction.cs index 3d9fb45a5f7..586fe1f31e9 100644 --- a/src/EFCore.Relational/Metadata/IConventionDbFunction.cs +++ b/src/EFCore.Relational/Metadata/IConventionDbFunction.cs @@ -26,7 +26,13 @@ public interface IConventionDbFunction : IConventionAnnotatable, IDbFunction /// /// Gets the builder that can be used to configure this function. /// - new IConventionDbFunctionBuilder? Builder { get; } + /// If the function has been removed from the model. + new IConventionDbFunctionBuilder Builder { get; } + + /// + /// Indicates whether this function is in a model, i.e. hasn't been removed from one. + /// + new bool IsInModel { get; } /// /// Gets the configuration source for this function. diff --git a/src/EFCore.Relational/Metadata/IConventionSequence.cs b/src/EFCore.Relational/Metadata/IConventionSequence.cs index d257b9e2da3..e1ed31e3681 100644 --- a/src/EFCore.Relational/Metadata/IConventionSequence.cs +++ b/src/EFCore.Relational/Metadata/IConventionSequence.cs @@ -23,7 +23,13 @@ public interface IConventionSequence : ISequence, IConventionAnnotatable /// /// Gets the builder that can be used to configure this sequence. /// - new IConventionSequenceBuilder? Builder { get; } + /// If the sequence has been removed from the model. + new IConventionSequenceBuilder Builder { get; } + + /// + /// Indicates whether this sequence is in a model, i.e. hasn't been removed from one. + /// + new bool IsInModel { get; } /// /// Gets the configuration source for this . diff --git a/src/EFCore.Relational/Metadata/Internal/DbFunction.cs b/src/EFCore.Relational/Metadata/Internal/DbFunction.cs index 5241269c35f..2f8b79fe263 100644 --- a/src/EFCore.Relational/Metadata/Internal/DbFunction.cs +++ b/src/EFCore.Relational/Metadata/Internal/DbFunction.cs @@ -38,6 +38,7 @@ public class DbFunction : ConventionAnnotatable, IMutableDbFunction, IConvention private string? _storeType; private RelationalTypeMapping? _typeMapping; private Func, SqlExpression>? _translation; + private InternalDbFunctionBuilder? _builder; private ConfigurationSource _configurationSource; private ConfigurationSource? _schemaConfigurationSource; @@ -114,7 +115,7 @@ public DbFunction( ReturnType = returnType; Model = model; _configurationSource = configurationSource; - Builder = new InternalDbFunctionBuilder(this, ((IConventionModel)model).Builder); + _builder = new InternalDbFunctionBuilder(this, ((IConventionModel)model).Builder); _parameters = parameters == null ? new List() : parameters @@ -156,7 +157,28 @@ private static string GetFunctionName(MethodInfo methodInfo, ParameterInfo[] par /// 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. /// - public virtual InternalDbFunctionBuilder? Builder { get; private set; } + public virtual InternalDbFunctionBuilder Builder + { + [DebuggerStepThrough] get => _builder ?? throw new InvalidOperationException(CoreStrings.ObjectRemovedFromModel); + } + + /// + /// 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. + /// + public virtual bool IsInModel + => _builder is not null; + + /// + /// 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. + /// + public virtual void SetRemovedFromModel() + => _builder = null; /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -199,7 +221,7 @@ public static IEnumerable GetDbFunctions([NotNull] IModel model) /// 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. /// - public static DbFunction? AddDbFunction( + public static DbFunction AddDbFunction( [NotNull] IMutableModel model, [NotNull] MethodInfo methodInfo, ConfigurationSource configurationSource) @@ -216,7 +238,7 @@ public static IEnumerable GetDbFunctions([NotNull] IModel model) /// 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. /// - public static DbFunction? AddDbFunction( + public static DbFunction AddDbFunction( [NotNull] IMutableModel model, [NotNull] string name, [NotNull] Type returnType, @@ -248,7 +270,7 @@ private static SortedDictionary GetOrCreateFunctions(IMutabl if (functions.TryGetValue(name, out var function)) { functions.Remove(name); - function.Builder = null; + function.SetRemovedFromModel(); return function; } @@ -271,7 +293,7 @@ private static SortedDictionary GetOrCreateFunctions(IMutabl && functions.TryGetValue(name, out var function)) { functions.Remove(name); - function.Builder = null; + function.SetRemovedFromModel(); } return null; @@ -602,7 +624,7 @@ public override string ToString() => this.ToDebugString(MetadataDebugStringOptions.SingleLineDefault); /// - IConventionDbFunctionBuilder? IConventionDbFunction.Builder + IConventionDbFunctionBuilder IConventionDbFunction.Builder { [DebuggerStepThrough] get => Builder; diff --git a/src/EFCore.Relational/Metadata/Internal/DbFunctionParameter.cs b/src/EFCore.Relational/Metadata/Internal/DbFunctionParameter.cs index 7e59923cfdd..a70b1a4a67e 100644 --- a/src/EFCore.Relational/Metadata/Internal/DbFunctionParameter.cs +++ b/src/EFCore.Relational/Metadata/Internal/DbFunctionParameter.cs @@ -50,7 +50,7 @@ public DbFunctionParameter( Name = name; Function = function; ClrType = clrType; - Builder = new InternalDbFunctionParameterBuilder(this, function.Builder!.ModelBuilder); + Builder = new InternalDbFunctionParameterBuilder(this, function.Builder.ModelBuilder); } /// diff --git a/src/EFCore.Relational/Metadata/Internal/InternalDbFunctionBuilder.cs b/src/EFCore.Relational/Metadata/Internal/InternalDbFunctionBuilder.cs index 0c85c84fcb5..d7329eaef30 100644 --- a/src/EFCore.Relational/Metadata/Internal/InternalDbFunctionBuilder.cs +++ b/src/EFCore.Relational/Metadata/Internal/InternalDbFunctionBuilder.cs @@ -258,22 +258,22 @@ IConventionDbFunction IConventionDbFunctionBuilder.Metadata /// [DebuggerStepThrough] - IConventionDbFunctionBuilder? IConventionDbFunctionBuilder.HasName(string name, bool fromDataAnnotation) + IConventionDbFunctionBuilder? IConventionDbFunctionBuilder.HasName(string? name, bool fromDataAnnotation) => HasName(name, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// [DebuggerStepThrough] - bool IConventionDbFunctionBuilder.CanSetName(string name, bool fromDataAnnotation) + bool IConventionDbFunctionBuilder.CanSetName(string? name, bool fromDataAnnotation) => CanSetName(name, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// [DebuggerStepThrough] - IConventionDbFunctionBuilder? IConventionDbFunctionBuilder.HasSchema(string schema, bool fromDataAnnotation) + IConventionDbFunctionBuilder? IConventionDbFunctionBuilder.HasSchema(string? schema, bool fromDataAnnotation) => HasSchema(schema, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// [DebuggerStepThrough] - bool IConventionDbFunctionBuilder.CanSetSchema(string schema, bool fromDataAnnotation) + bool IConventionDbFunctionBuilder.CanSetSchema(string? schema, bool fromDataAnnotation) => CanSetSchema(schema, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// @@ -298,35 +298,35 @@ bool IConventionDbFunctionBuilder.CanSetIsNullable(bool nullable, bool fromDataA /// [DebuggerStepThrough] - IConventionDbFunctionBuilder? IConventionDbFunctionBuilder.HasStoreType(string storeType, bool fromDataAnnotation) + IConventionDbFunctionBuilder? IConventionDbFunctionBuilder.HasStoreType(string? storeType, bool fromDataAnnotation) => HasStoreType(storeType, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// [DebuggerStepThrough] - bool IConventionDbFunctionBuilder.CanSetStoreType(string storeType, bool fromDataAnnotation) + bool IConventionDbFunctionBuilder.CanSetStoreType(string? storeType, bool fromDataAnnotation) => CanSetStoreType(storeType, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// [DebuggerStepThrough] - IConventionDbFunctionBuilder? IConventionDbFunctionBuilder.HasTypeMapping(RelationalTypeMapping typeMapping, bool fromDataAnnotation) + IConventionDbFunctionBuilder? IConventionDbFunctionBuilder.HasTypeMapping(RelationalTypeMapping? typeMapping, bool fromDataAnnotation) => HasTypeMapping(typeMapping, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// [DebuggerStepThrough] - bool IConventionDbFunctionBuilder.CanSetTypeMapping(RelationalTypeMapping typeMapping, bool fromDataAnnotation) + bool IConventionDbFunctionBuilder.CanSetTypeMapping(RelationalTypeMapping? typeMapping, bool fromDataAnnotation) => CanSetTypeMapping(typeMapping, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// [DebuggerStepThrough] IConventionDbFunctionBuilder? IConventionDbFunctionBuilder.HasTranslation( - Func, SqlExpression> translation, + Func, SqlExpression>? translation, bool fromDataAnnotation) => HasTranslation(translation, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// [DebuggerStepThrough] bool IConventionDbFunctionBuilder.CanSetTranslation( - Func, SqlExpression> translation, + Func, SqlExpression>? translation, bool fromDataAnnotation) => CanSetTranslation(translation, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); diff --git a/src/EFCore.Relational/Metadata/Internal/InternalDbFunctionParameterBuilder.cs b/src/EFCore.Relational/Metadata/Internal/InternalDbFunctionParameterBuilder.cs index 8b517209726..fff480229fa 100644 --- a/src/EFCore.Relational/Metadata/Internal/InternalDbFunctionParameterBuilder.cs +++ b/src/EFCore.Relational/Metadata/Internal/InternalDbFunctionParameterBuilder.cs @@ -131,24 +131,24 @@ IConventionDbFunctionParameter IConventionDbFunctionParameterBuilder.Metadata /// [DebuggerStepThrough] - IConventionDbFunctionParameterBuilder? IConventionDbFunctionParameterBuilder.HasStoreType(string storeType, bool fromDataAnnotation) + IConventionDbFunctionParameterBuilder? IConventionDbFunctionParameterBuilder.HasStoreType(string? storeType, bool fromDataAnnotation) => HasStoreType(storeType, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// [DebuggerStepThrough] - bool IConventionDbFunctionParameterBuilder.CanSetStoreType(string storeType, bool fromDataAnnotation) + bool IConventionDbFunctionParameterBuilder.CanSetStoreType(string? storeType, bool fromDataAnnotation) => CanSetStoreType(storeType, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// [DebuggerStepThrough] IConventionDbFunctionParameterBuilder? IConventionDbFunctionParameterBuilder.HasTypeMapping( - RelationalTypeMapping typeMapping, + RelationalTypeMapping? typeMapping, bool fromDataAnnotation) => HasTypeMapping(typeMapping, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// [DebuggerStepThrough] - bool IConventionDbFunctionParameterBuilder.CanSetTypeMapping(RelationalTypeMapping typeMapping, bool fromDataAnnotation) + bool IConventionDbFunctionParameterBuilder.CanSetTypeMapping(RelationalTypeMapping? typeMapping, bool fromDataAnnotation) => CanSetTypeMapping(typeMapping, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); } } diff --git a/src/EFCore.Relational/Metadata/Internal/InternalSequenceBuilder.cs b/src/EFCore.Relational/Metadata/Internal/InternalSequenceBuilder.cs index edfef805cbe..4f28b01d348 100644 --- a/src/EFCore.Relational/Metadata/Internal/InternalSequenceBuilder.cs +++ b/src/EFCore.Relational/Metadata/Internal/InternalSequenceBuilder.cs @@ -206,12 +206,12 @@ IConventionSequence IConventionSequenceBuilder.Metadata /// [DebuggerStepThrough] - IConventionSequenceBuilder? IConventionSequenceBuilder.HasType(Type type, bool fromDataAnnotation) + IConventionSequenceBuilder? IConventionSequenceBuilder.HasType(Type? type, bool fromDataAnnotation) => HasType(type, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// [DebuggerStepThrough] - bool IConventionSequenceBuilder.CanSetType(Type type, bool fromDataAnnotation) + bool IConventionSequenceBuilder.CanSetType(Type? type, bool fromDataAnnotation) => CanSetType(type, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// diff --git a/src/EFCore.Relational/Metadata/Internal/RelationalModel.cs b/src/EFCore.Relational/Metadata/Internal/RelationalModel.cs index e7936e59292..a3ef6d364b8 100644 --- a/src/EFCore.Relational/Metadata/Internal/RelationalModel.cs +++ b/src/EFCore.Relational/Metadata/Internal/RelationalModel.cs @@ -113,7 +113,7 @@ public RelationalModel([NotNull] IModel model) /// public static IModel Add( [NotNull] IConventionModel model, - [CanBeNull] IRelationalAnnotationProvider relationalAnnotationProvider) + [CanBeNull] IRelationalAnnotationProvider? relationalAnnotationProvider) { if (model.FindAnnotation(RelationalAnnotationNames.RelationalModel) != null) { @@ -254,7 +254,7 @@ private static void AddDefaultMappings(RelationalModel databaseModel, IConventio var column = (ColumnBase?)defaultTable.FindColumn(columnName); if (column == null) { - column = new ColumnBase(columnName, property.GetColumnType(), defaultTable); + column = new ColumnBase(columnName, property.GetColumnType()!, defaultTable); column.IsNullable = property.IsColumnNullable(); defaultTable.Columns.Add(columnName, column); } @@ -264,7 +264,7 @@ private static void AddDefaultMappings(RelationalModel databaseModel, IConventio } var columnMapping = new ColumnMappingBase( - property, column, property.FindRelationalTypeMapping(), tableMapping); + property, column, property.FindRelationalTypeMapping()!, tableMapping); tableMapping.ColumnMappings.Add(columnMapping); column.PropertyMappings.Add(columnMapping); @@ -348,7 +348,7 @@ private static void AddTables(RelationalModel databaseModel, IConventionEntityTy var column = (Column?)table.FindColumn(columnName); if (column == null) { - column = new Column(columnName, property.GetColumnType(mappedTable), table); + column = new Column(columnName, property.GetColumnType(mappedTable)!, table); column.IsNullable = property.IsColumnNullable(mappedTable); table.Columns.Add(columnName, column); } @@ -358,7 +358,7 @@ private static void AddTables(RelationalModel databaseModel, IConventionEntityTy } var columnMapping = new ColumnMapping( - property, column, property.FindRelationalTypeMapping(mappedTable), tableMapping); + property, column, property.FindRelationalTypeMapping(mappedTable)!, tableMapping); tableMapping.ColumnMappings.Add(columnMapping); column.PropertyMappings.Add(columnMapping); @@ -439,7 +439,7 @@ private static void AddViews(RelationalModel databaseModel, IConventionEntityTyp var column = (ViewColumn?)view.FindColumn(columnName); if (column == null) { - column = new ViewColumn(columnName, property.GetColumnType(mappedView), view); + column = new ViewColumn(columnName, property.GetColumnType(mappedView)!, view); column.IsNullable = property.IsColumnNullable(mappedView); view.Columns.Add(columnName, column); } @@ -449,7 +449,7 @@ private static void AddViews(RelationalModel databaseModel, IConventionEntityTyp } var columnMapping = new ViewColumnMapping( - property, column, property.FindRelationalTypeMapping(mappedView), viewMapping); + property, column, property.FindRelationalTypeMapping(mappedView)!, viewMapping); viewMapping.ColumnMappings.Add(columnMapping); column.PropertyMappings.Add(columnMapping); @@ -545,7 +545,7 @@ private static void AddSqlQueries(RelationalModel databaseModel, IConventionEnti var column = (SqlQueryColumn?)sqlQuery.FindColumn(columnName); if (column == null) { - column = new SqlQueryColumn(columnName, property.GetColumnType(mappedQuery), sqlQuery); + column = new SqlQueryColumn(columnName, property.GetColumnType(mappedQuery)!, sqlQuery); column.IsNullable = property.IsColumnNullable(mappedQuery); sqlQuery.Columns.Add(columnName, column); } @@ -555,7 +555,7 @@ private static void AddSqlQueries(RelationalModel databaseModel, IConventionEnti } var columnMapping = new SqlQueryColumnMapping( - property, column, property.FindRelationalTypeMapping(mappedQuery), queryMapping); + property, column, property.FindRelationalTypeMapping(mappedQuery)!, queryMapping); queryMapping.ColumnMappings.Add(columnMapping); column.PropertyMappings.Add(columnMapping); @@ -695,7 +695,7 @@ private static FunctionMapping CreateFunctionMapping( var column = (FunctionColumn?)storeFunction.FindColumn(columnName); if (column == null) { - column = new FunctionColumn(columnName, property.GetColumnType(mappedFunction), storeFunction); + column = new FunctionColumn(columnName, property.GetColumnType(mappedFunction)!, storeFunction); column.IsNullable = property.IsColumnNullable(mappedFunction); storeFunction.Columns.Add(columnName, column); } @@ -705,7 +705,7 @@ private static FunctionMapping CreateFunctionMapping( } var columnMapping = new FunctionColumnMapping( - property, column, property.FindRelationalTypeMapping(mappedFunction), functionMapping); + property, column, property.FindRelationalTypeMapping(mappedFunction)!, functionMapping); functionMapping.ColumnMappings.Add(columnMapping); column.PropertyMappings.Add(columnMapping); diff --git a/src/EFCore.Relational/Metadata/Internal/Sequence.cs b/src/EFCore.Relational/Metadata/Internal/Sequence.cs index 4ba4397a891..a5798286166 100644 --- a/src/EFCore.Relational/Metadata/Internal/Sequence.cs +++ b/src/EFCore.Relational/Metadata/Internal/Sequence.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Globalization; using System.Linq; using System.Text; @@ -32,6 +33,7 @@ public class Sequence : ConventionAnnotatable, IMutableSequence, IConventionSequ private long? _maxValue; private Type? _type; private bool? _isCyclic; + private InternalSequenceBuilder? _builder; private ConfigurationSource _configurationSource; private ConfigurationSource? _startValueConfigurationSource; @@ -108,7 +110,7 @@ public Sequence( Name = name; _schema = schema; _configurationSource = configurationSource; - Builder = new InternalSequenceBuilder(this, ((IConventionModel)model).Builder); + _builder = new InternalSequenceBuilder(this, ((IConventionModel)model).Builder); } /// @@ -135,7 +137,7 @@ public Sequence([NotNull] IModel model, [NotNull] string annotationName) _maxValue = data.MaxValue; _type = data.ClrType; _isCyclic = data.IsCyclic; - Builder = new InternalSequenceBuilder(this, ((IConventionModel)model).Builder); + _builder = new InternalSequenceBuilder(this, ((IConventionModel)model).Builder); } /// @@ -173,7 +175,7 @@ public static IEnumerable GetSequences([NotNull] IModel model) /// 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. /// - public static Sequence? AddSequence( + public static Sequence AddSequence( [NotNull] IMutableModel model, [NotNull] string name, [CanBeNull] string? schema, @@ -239,7 +241,7 @@ public static IEnumerable GetSequences([NotNull] IModel model) } sequences.Remove((name, schema)); - sequence.Builder = null; + sequence.SetRemovedFromModel(); return sequence; } @@ -250,7 +252,28 @@ public static IEnumerable GetSequences([NotNull] IModel model) /// 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. /// - public virtual InternalSequenceBuilder? Builder { get; private set; } + public virtual InternalSequenceBuilder Builder + { + [DebuggerStepThrough] get => _builder ?? throw new InvalidOperationException(CoreStrings.ObjectRemovedFromModel); + } + + /// + /// 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. + /// + public virtual bool IsInModel + => _builder is not null; + + /// + /// 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. + /// + public virtual void SetRemovedFromModel() + => _builder = null; /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -586,7 +609,7 @@ public override string ToString() /// 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. /// - IConventionSequenceBuilder? IConventionSequence.Builder + IConventionSequenceBuilder IConventionSequence.Builder => Builder; /// diff --git a/src/EFCore.Relational/Metadata/Internal/View.cs b/src/EFCore.Relational/Metadata/Internal/View.cs index fa93761b265..f25914f55be 100644 --- a/src/EFCore.Relational/Metadata/Internal/View.cs +++ b/src/EFCore.Relational/Metadata/Internal/View.cs @@ -25,7 +25,7 @@ public class View : TableBase, IView /// 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. /// - public View([NotNull] string name, [CanBeNull] string schema, [NotNull] RelationalModel model) + public View([NotNull] string name, [CanBeNull] string? schema, [NotNull] RelationalModel model) : base(name, schema, model) { } diff --git a/src/EFCore.Relational/Query/Internal/FromSqlQueryingEnumerable.cs b/src/EFCore.Relational/Query/Internal/FromSqlQueryingEnumerable.cs index 5f61ea4f7ba..1b34616fd67 100644 --- a/src/EFCore.Relational/Query/Internal/FromSqlQueryingEnumerable.cs +++ b/src/EFCore.Relational/Query/Internal/FromSqlQueryingEnumerable.cs @@ -125,7 +125,7 @@ public virtual string ToQueryString() /// 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. /// - public static int[] BuildIndexMap([CanBeNull] IReadOnlyList columnNames, [NotNull] DbDataReader dataReader) + public static int[] BuildIndexMap([NotNull] IReadOnlyList columnNames, [NotNull] DbDataReader dataReader) { var readerColumns = Enumerable.Range(0, dataReader.FieldCount) .ToDictionary(dataReader.GetName, i => i, StringComparer.OrdinalIgnoreCase); diff --git a/src/EFCore.Relational/Query/RelationalCollectionShaperExpression.cs b/src/EFCore.Relational/Query/RelationalCollectionShaperExpression.cs index 4b349e0037a..574563b4ac6 100644 --- a/src/EFCore.Relational/Query/RelationalCollectionShaperExpression.cs +++ b/src/EFCore.Relational/Query/RelationalCollectionShaperExpression.cs @@ -42,7 +42,7 @@ public RelationalCollectionShaperExpression( [NotNull] Expression outerIdentifier, [NotNull] Expression selfIdentifier, [NotNull] Expression innerShaper, - [CanBeNull] INavigation navigation, + [CanBeNull] INavigation? navigation, [NotNull] Type elementType) : this( collectionId, parentIdentifier, outerIdentifier, selfIdentifier, diff --git a/src/EFCore.Relational/Query/SqlExpressions/SelectExpression.cs b/src/EFCore.Relational/Query/SqlExpressions/SelectExpression.cs index 5593c92425d..b7e5fae29ca 100644 --- a/src/EFCore.Relational/Query/SqlExpressions/SelectExpression.cs +++ b/src/EFCore.Relational/Query/SqlExpressions/SelectExpression.cs @@ -2522,7 +2522,7 @@ when _subquery.ContainsTableReference(columnExpression.Table): private void AddJoin( JoinType joinType, SelectExpression innerSelectExpression, - Type transparentIdentifierType, + Type? transparentIdentifierType, SqlExpression? joinPredicate) { AddJoin(joinType, ref innerSelectExpression, joinPredicate); @@ -2570,7 +2570,7 @@ private void AddJoin( public void AddInnerJoin( [NotNull] SelectExpression innerSelectExpression, [NotNull] SqlExpression joinPredicate, - [CanBeNull] Type transparentIdentifierType) + [CanBeNull] Type? transparentIdentifierType) { Check.NotNull(innerSelectExpression, nameof(innerSelectExpression)); Check.NotNull(joinPredicate, nameof(joinPredicate)); @@ -2588,7 +2588,7 @@ public void AddInnerJoin( public void AddLeftJoin( [NotNull] SelectExpression innerSelectExpression, [NotNull] SqlExpression joinPredicate, - [CanBeNull] Type transparentIdentifierType) + [CanBeNull] Type? transparentIdentifierType) { Check.NotNull(innerSelectExpression, nameof(innerSelectExpression)); Check.NotNull(joinPredicate, nameof(joinPredicate)); @@ -2602,7 +2602,7 @@ public void AddLeftJoin( /// A to join with. /// The type of the result generated after performing the join. [Obsolete("Use the other overloads.")] - public void AddCrossJoin([NotNull] SelectExpression innerSelectExpression, [CanBeNull] Type transparentIdentifierType) + public void AddCrossJoin([NotNull] SelectExpression innerSelectExpression, [CanBeNull] Type? transparentIdentifierType) { Check.NotNull(innerSelectExpression, nameof(innerSelectExpression)); @@ -2615,7 +2615,7 @@ public void AddCrossJoin([NotNull] SelectExpression innerSelectExpression, [CanB /// A to join with. /// The type of the result generated after performing the join. [Obsolete("Use the other overloads.")] - public void AddCrossApply([NotNull] SelectExpression innerSelectExpression, [CanBeNull] Type transparentIdentifierType) + public void AddCrossApply([NotNull] SelectExpression innerSelectExpression, [CanBeNull] Type? transparentIdentifierType) { Check.NotNull(innerSelectExpression, nameof(innerSelectExpression)); @@ -2628,7 +2628,7 @@ public void AddCrossApply([NotNull] SelectExpression innerSelectExpression, [Can /// A to join with. /// The type of the result generated after performing the join. [Obsolete("Use the other overloads.")] - public void AddOuterApply([NotNull] SelectExpression innerSelectExpression, [CanBeNull] Type transparentIdentifierType) + public void AddOuterApply([NotNull] SelectExpression innerSelectExpression, [CanBeNull] Type? transparentIdentifierType) { Check.NotNull(innerSelectExpression, nameof(innerSelectExpression)); @@ -3107,14 +3107,14 @@ private bool Equals(SelectExpression selectExpression) public SelectExpression Update( [NotNull] IReadOnlyList projections, [NotNull] IReadOnlyList tables, - [CanBeNull] SqlExpression predicate, + [CanBeNull] SqlExpression? predicate, [NotNull] IReadOnlyList groupBy, - [CanBeNull] SqlExpression having, + [CanBeNull] SqlExpression? having, [NotNull] IReadOnlyList orderings, - [CanBeNull] SqlExpression limit, - [CanBeNull] SqlExpression offset, + [CanBeNull] SqlExpression? limit, + [CanBeNull] SqlExpression? offset, bool distinct, - [CanBeNull] string alias) + [CanBeNull] string? alias) { Check.NotNull(projections, nameof(projections)); Check.NotNull(tables, nameof(tables)); diff --git a/src/EFCore.Relational/Query/SqlExpressions/SqlFunctionExpression.cs b/src/EFCore.Relational/Query/SqlExpressions/SqlFunctionExpression.cs index 716d21725ff..cd4a09b5979 100644 --- a/src/EFCore.Relational/Query/SqlExpressions/SqlFunctionExpression.cs +++ b/src/EFCore.Relational/Query/SqlExpressions/SqlFunctionExpression.cs @@ -425,7 +425,7 @@ public override int GetHashCode() public static SqlFunctionExpression CreateNiladic( [NotNull] string name, [NotNull] Type type, - [CanBeNull] RelationalTypeMapping typeMapping) + [CanBeNull] RelationalTypeMapping? typeMapping) => new(name, nullable: true, type, typeMapping); /// @@ -441,7 +441,7 @@ public static SqlFunctionExpression CreateNiladic( [NotNull] string schema, [NotNull] string name, [NotNull] Type type, - [CanBeNull] RelationalTypeMapping typeMapping) + [CanBeNull] RelationalTypeMapping? typeMapping) => new(schema, name, nullable: true, type, typeMapping); /// @@ -457,7 +457,7 @@ public static SqlFunctionExpression CreateNiladic( [NotNull] SqlExpression instance, [NotNull] string name, [NotNull] Type type, - [CanBeNull] RelationalTypeMapping typeMapping) + [CanBeNull] RelationalTypeMapping? typeMapping) => new(instance, name, nullable: true, instancePropagatesNullability: false, type, typeMapping); /// @@ -475,7 +475,7 @@ public static SqlFunctionExpression Create( [NotNull] string name, [NotNull] IEnumerable arguments, [NotNull] Type type, - [CanBeNull] RelationalTypeMapping typeMapping) + [CanBeNull] RelationalTypeMapping? typeMapping) => new( instance, name, @@ -499,7 +499,7 @@ public static SqlFunctionExpression Create( [NotNull] string name, [NotNull] IEnumerable arguments, [NotNull] Type type, - [CanBeNull] RelationalTypeMapping typeMapping) + [CanBeNull] RelationalTypeMapping? typeMapping) => new(name, arguments, nullable: true, argumentsPropagateNullability: arguments.Select(a => false), type, typeMapping); /// @@ -517,7 +517,7 @@ public static SqlFunctionExpression Create( [NotNull] string name, [NotNull] IEnumerable arguments, [NotNull] Type type, - [CanBeNull] RelationalTypeMapping typeMapping) + [CanBeNull] RelationalTypeMapping? typeMapping) => new(schema, name, arguments, nullable: true, argumentsPropagateNullability: arguments.Select(a => false), type, typeMapping); #endregion diff --git a/src/EFCore.Relational/Storage/RelationalTypeMapping.cs b/src/EFCore.Relational/Storage/RelationalTypeMapping.cs index 1bc61939d35..a4e11997f85 100644 --- a/src/EFCore.Relational/Storage/RelationalTypeMapping.cs +++ b/src/EFCore.Relational/Storage/RelationalTypeMapping.cs @@ -216,7 +216,7 @@ public RelationalTypeMappingParameters WithScale(int? scale) /// /// The converter. /// The new parameter object. - public RelationalTypeMappingParameters WithComposedConverter([CanBeNull] ValueConverter converter) + public RelationalTypeMappingParameters WithComposedConverter([CanBeNull] ValueConverter? converter) => new( CoreParameters.WithComposedConverter(converter), StoreType, @@ -399,7 +399,7 @@ public virtual RelationalTypeMapping Clone(int? precision, int? scale) /// /// The converter to use. /// A new type mapping - public override CoreTypeMapping Clone(ValueConverter converter) + public override CoreTypeMapping Clone(ValueConverter? converter) => Clone(Parameters.WithComposedConverter(converter)); /// diff --git a/src/EFCore.SqlServer/Extensions/SqlServerEntityTypeBuilderExtensions.cs b/src/EFCore.SqlServer/Extensions/SqlServerEntityTypeBuilderExtensions.cs index 1ed6a484690..82e55cfaba6 100644 --- a/src/EFCore.SqlServer/Extensions/SqlServerEntityTypeBuilderExtensions.cs +++ b/src/EFCore.SqlServer/Extensions/SqlServerEntityTypeBuilderExtensions.cs @@ -6,6 +6,8 @@ using Microsoft.EntityFrameworkCore.SqlServer.Metadata.Internal; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + // ReSharper disable once CheckNamespace namespace Microsoft.EntityFrameworkCore { @@ -87,7 +89,7 @@ public static OwnedNavigationBuilder IsMemoryOptimized< /// The same builder instance if the configuration was applied, /// otherwise. /// - public static IConventionEntityTypeBuilder IsMemoryOptimized( + public static IConventionEntityTypeBuilder? IsMemoryOptimized( [NotNull] this IConventionEntityTypeBuilder entityTypeBuilder, bool? memoryOptimized, bool fromDataAnnotation = false) diff --git a/src/EFCore.SqlServer/Extensions/SqlServerEntityTypeExtensions.cs b/src/EFCore.SqlServer/Extensions/SqlServerEntityTypeExtensions.cs index 709d12e08f8..a844912caad 100644 --- a/src/EFCore.SqlServer/Extensions/SqlServerEntityTypeExtensions.cs +++ b/src/EFCore.SqlServer/Extensions/SqlServerEntityTypeExtensions.cs @@ -5,6 +5,8 @@ using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.SqlServer.Metadata.Internal; +#nullable enable + // ReSharper disable once CheckNamespace namespace Microsoft.EntityFrameworkCore { diff --git a/src/EFCore.SqlServer/Extensions/SqlServerIndexBuilderExtensions.cs b/src/EFCore.SqlServer/Extensions/SqlServerIndexBuilderExtensions.cs index a2482a99d7d..914a55c20e0 100644 --- a/src/EFCore.SqlServer/Extensions/SqlServerIndexBuilderExtensions.cs +++ b/src/EFCore.SqlServer/Extensions/SqlServerIndexBuilderExtensions.cs @@ -13,6 +13,8 @@ using Microsoft.EntityFrameworkCore.SqlServer.Metadata.Internal; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + // ReSharper disable once CheckNamespace namespace Microsoft.EntityFrameworkCore { @@ -57,7 +59,7 @@ public static IndexBuilder IsClustered( /// The same builder instance if the configuration was applied, /// otherwise. /// - public static IConventionIndexBuilder IsClustered( + public static IConventionIndexBuilder? IsClustered( [NotNull] this IConventionIndexBuilder indexBuilder, bool? clustered, bool fromDataAnnotation = false) @@ -161,9 +163,9 @@ public static IndexBuilder IncludeProperties( /// The same builder instance if the configuration was applied, /// otherwise. /// - public static IConventionIndexBuilder IncludeProperties( + public static IConventionIndexBuilder? IncludeProperties( [NotNull] this IConventionIndexBuilder indexBuilder, - [NotNull] IReadOnlyList propertyNames, + [CanBeNull] IReadOnlyList? propertyNames, bool fromDataAnnotation = false) { if (indexBuilder.CanSetIncludeProperties(propertyNames, fromDataAnnotation)) @@ -185,14 +187,19 @@ public static IConventionIndexBuilder IncludeProperties( /// if the given include properties can be set. public static bool CanSetIncludeProperties( [NotNull] this IConventionIndexBuilder indexBuilder, - [CanBeNull] IReadOnlyList propertyNames, + [CanBeNull] IReadOnlyList? propertyNames, bool fromDataAnnotation = false) { Check.NotNull(indexBuilder, nameof(indexBuilder)); return (fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention) .Overrides(indexBuilder.Metadata.GetIncludePropertiesConfigurationSource()) - || propertyNames.SequenceEqual(indexBuilder.Metadata.GetIncludeProperties()); + || indexBuilder.Metadata.GetIncludeProperties() is var currentProperties + && (propertyNames is null + && currentProperties is null + || propertyNames is not null + && currentProperties is not null + && propertyNames.SequenceEqual(currentProperties)); } /// @@ -231,7 +238,7 @@ public static IndexBuilder IsCreatedOnline( /// The same builder instance if the configuration was applied, /// otherwise. /// - public static IConventionIndexBuilder IsCreatedOnline( + public static IConventionIndexBuilder? IsCreatedOnline( [NotNull] this IConventionIndexBuilder indexBuilder, bool? createdOnline, bool fromDataAnnotation = false) @@ -303,7 +310,7 @@ public static IndexBuilder HasFillFactor( /// The same builder instance if the configuration was applied, /// otherwise. /// - public static IConventionIndexBuilder HasFillFactor( + public static IConventionIndexBuilder? HasFillFactor( [NotNull] this IConventionIndexBuilder indexBuilder, int? fillFactor, bool fromDataAnnotation = false) diff --git a/src/EFCore.SqlServer/Extensions/SqlServerIndexExtensions.cs b/src/EFCore.SqlServer/Extensions/SqlServerIndexExtensions.cs index edf075e95a4..fbc8271b725 100644 --- a/src/EFCore.SqlServer/Extensions/SqlServerIndexExtensions.cs +++ b/src/EFCore.SqlServer/Extensions/SqlServerIndexExtensions.cs @@ -7,6 +7,8 @@ using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.SqlServer.Metadata.Internal; +#nullable enable + // ReSharper disable once CheckNamespace namespace Microsoft.EntityFrameworkCore { @@ -89,8 +91,8 @@ public static void SetIsClustered([NotNull] this IMutableIndex index, bool? valu /// /// The index. /// The included property names, or if they have not been specified. - public static IReadOnlyList GetIncludeProperties([NotNull] this IIndex index) - => (string[])index[SqlServerAnnotationNames.Include]; + public static IReadOnlyList? GetIncludeProperties([NotNull] this IIndex index) + => (string[]?)index[SqlServerAnnotationNames.Include]; /// /// Sets included property names. @@ -109,9 +111,9 @@ public static void SetIncludeProperties([NotNull] this IMutableIndex index, [Not /// Indicates whether the configuration was specified using a data annotation. /// The value to set. /// The configured property names. - public static IReadOnlyList SetIncludeProperties( + public static IReadOnlyList? SetIncludeProperties( [NotNull] this IConventionIndex index, - [NotNull] IReadOnlyList properties, + [CanBeNull] IReadOnlyList? properties, bool fromDataAnnotation = false) { index.SetOrRemoveAnnotation( diff --git a/src/EFCore.SqlServer/Extensions/SqlServerKeyBuilderExtensions.cs b/src/EFCore.SqlServer/Extensions/SqlServerKeyBuilderExtensions.cs index ce8b9ad9635..517abddaaac 100644 --- a/src/EFCore.SqlServer/Extensions/SqlServerKeyBuilderExtensions.cs +++ b/src/EFCore.SqlServer/Extensions/SqlServerKeyBuilderExtensions.cs @@ -6,6 +6,8 @@ using Microsoft.EntityFrameworkCore.SqlServer.Metadata.Internal; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + // ReSharper disable once CheckNamespace namespace Microsoft.EntityFrameworkCore { @@ -50,7 +52,7 @@ public static KeyBuilder IsClustered( /// The same builder instance if the configuration was applied, /// otherwise. /// - public static IConventionKeyBuilder IsClustered( + public static IConventionKeyBuilder? IsClustered( [NotNull] this IConventionKeyBuilder keyBuilder, bool? clustered, bool fromDataAnnotation = false) diff --git a/src/EFCore.SqlServer/Extensions/SqlServerKeyExtensions.cs b/src/EFCore.SqlServer/Extensions/SqlServerKeyExtensions.cs index c1faac01b87..1e37cdef8dc 100644 --- a/src/EFCore.SqlServer/Extensions/SqlServerKeyExtensions.cs +++ b/src/EFCore.SqlServer/Extensions/SqlServerKeyExtensions.cs @@ -5,6 +5,8 @@ using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.SqlServer.Metadata.Internal; +#nullable enable + // ReSharper disable once CheckNamespace namespace Microsoft.EntityFrameworkCore { diff --git a/src/EFCore.SqlServer/Extensions/SqlServerModelBuilderExtensions.cs b/src/EFCore.SqlServer/Extensions/SqlServerModelBuilderExtensions.cs index b5b2ee60b84..18afffb90b1 100644 --- a/src/EFCore.SqlServer/Extensions/SqlServerModelBuilderExtensions.cs +++ b/src/EFCore.SqlServer/Extensions/SqlServerModelBuilderExtensions.cs @@ -7,6 +7,8 @@ using Microsoft.EntityFrameworkCore.SqlServer.Metadata.Internal; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + // ReSharper disable once CheckNamespace namespace Microsoft.EntityFrameworkCore { @@ -25,8 +27,8 @@ public static class SqlServerModelBuilderExtensions /// The same builder instance so that multiple calls can be chained. public static ModelBuilder UseHiLo( [NotNull] this ModelBuilder modelBuilder, - [CanBeNull] string name = null, - [CanBeNull] string schema = null) + [CanBeNull] string? name = null, + [CanBeNull] string? schema = null) { Check.NotNull(modelBuilder, nameof(modelBuilder)); Check.NullButNotEmpty(name, nameof(name)); @@ -59,10 +61,10 @@ public static ModelBuilder UseHiLo( /// The schema of the sequence. /// Indicates whether the configuration was specified using a data annotation. /// A builder to further configure the sequence. - public static IConventionSequenceBuilder HasHiLoSequence( + public static IConventionSequenceBuilder? HasHiLoSequence( [NotNull] this IConventionModelBuilder modelBuilder, - [CanBeNull] string name, - [CanBeNull] string schema, + [CanBeNull] string? name, + [CanBeNull] string? schema, bool fromDataAnnotation = false) { if (!modelBuilder.CanSetHiLoSequence(name, schema)) @@ -86,8 +88,8 @@ public static IConventionSequenceBuilder HasHiLoSequence( /// if the given name and schema can be set for the hi-lo sequence. public static bool CanSetHiLoSequence( [NotNull] this IConventionModelBuilder modelBuilder, - [CanBeNull] string name, - [CanBeNull] string schema, + [CanBeNull] string? name, + [CanBeNull] string? schema, bool fromDataAnnotation = false) { Check.NotNull(modelBuilder, nameof(modelBuilder)); @@ -135,7 +137,7 @@ public static ModelBuilder UseIdentityColumns( /// The same builder instance if the configuration was applied, /// otherwise. /// - public static IConventionModelBuilder HasIdentityColumnSeed( + public static IConventionModelBuilder? HasIdentityColumnSeed( [NotNull] this IConventionModelBuilder modelBuilder, int? seed, bool fromDataAnnotation = false) @@ -176,7 +178,7 @@ public static bool CanSetIdentityColumnSeed( /// The same builder instance if the configuration was applied, /// otherwise. /// - public static IConventionModelBuilder HasIdentityColumnIncrement( + public static IConventionModelBuilder? HasIdentityColumnIncrement( [NotNull] this IConventionModelBuilder modelBuilder, int? increment, bool fromDataAnnotation = false) @@ -218,7 +220,7 @@ public static bool CanSetIdentityColumnIncrement( /// The same builder instance if the configuration was applied, /// otherwise. /// - public static IConventionModelBuilder HasValueGenerationStrategy( + public static IConventionModelBuilder? HasValueGenerationStrategy( [NotNull] this IConventionModelBuilder modelBuilder, SqlServerValueGenerationStrategy? valueGenerationStrategy, bool fromDataAnnotation = false) @@ -297,9 +299,9 @@ public static ModelBuilder HasDatabaseMaxSize([NotNull] this ModelBuilder modelB /// The same builder instance if the configuration was applied, /// otherwise. /// - public static IConventionModelBuilder HasDatabaseMaxSize( + public static IConventionModelBuilder? HasDatabaseMaxSize( [NotNull] this IConventionModelBuilder modelBuilder, - [CanBeNull] string maxSize, + [CanBeNull] string? maxSize, bool fromDataAnnotation = false) { if (modelBuilder.CanSetDatabaseMaxSize(maxSize, fromDataAnnotation)) @@ -320,7 +322,7 @@ public static IConventionModelBuilder HasDatabaseMaxSize( /// if the given value can be set as the maximum size of the database. public static bool CanSetDatabaseMaxSize( [NotNull] this IConventionModelBuilder modelBuilder, - [CanBeNull] string maxSize, + [CanBeNull] string? maxSize, bool fromDataAnnotation = false) { Check.NotNull(modelBuilder, nameof(modelBuilder)); @@ -385,9 +387,9 @@ public static ModelBuilder HasServiceTierSql([NotNull] this ModelBuilder modelBu /// The same builder instance if the configuration was applied, /// otherwise. /// - public static IConventionModelBuilder HasServiceTierSql( + public static IConventionModelBuilder? HasServiceTierSql( [NotNull] this IConventionModelBuilder modelBuilder, - [CanBeNull] string serviceTier, + [CanBeNull] string? serviceTier, bool fromDataAnnotation = false) { if (modelBuilder.CanSetServiceTierSql(serviceTier, fromDataAnnotation)) @@ -408,7 +410,7 @@ public static IConventionModelBuilder HasServiceTierSql( /// if the given value can be set as the service tier of the database. public static bool CanSetServiceTierSql( [NotNull] this IConventionModelBuilder modelBuilder, - [CanBeNull] string serviceTier, + [CanBeNull] string? serviceTier, bool fromDataAnnotation = false) { Check.NotNull(modelBuilder, nameof(modelBuilder)); @@ -473,9 +475,9 @@ public static ModelBuilder HasPerformanceLevelSql([NotNull] this ModelBuilder mo /// The same builder instance if the configuration was applied, /// otherwise. /// - public static IConventionModelBuilder HasPerformanceLevelSql( + public static IConventionModelBuilder? HasPerformanceLevelSql( [NotNull] this IConventionModelBuilder modelBuilder, - [CanBeNull] string performanceLevel, + [CanBeNull] string? performanceLevel, bool fromDataAnnotation = false) { if (modelBuilder.CanSetPerformanceLevelSql(performanceLevel, fromDataAnnotation)) @@ -496,7 +498,7 @@ public static IConventionModelBuilder HasPerformanceLevelSql( /// if the given value can be set as the performance level of the database. public static bool CanSetPerformanceLevelSql( [NotNull] this IConventionModelBuilder modelBuilder, - [CanBeNull] string performanceLevel, + [CanBeNull] string? performanceLevel, bool fromDataAnnotation = false) { Check.NotNull(modelBuilder, nameof(modelBuilder)); diff --git a/src/EFCore.SqlServer/Extensions/SqlServerModelExtensions.cs b/src/EFCore.SqlServer/Extensions/SqlServerModelExtensions.cs index 17002e7a043..682f49a3897 100644 --- a/src/EFCore.SqlServer/Extensions/SqlServerModelExtensions.cs +++ b/src/EFCore.SqlServer/Extensions/SqlServerModelExtensions.cs @@ -6,6 +6,8 @@ using Microsoft.EntityFrameworkCore.SqlServer.Metadata.Internal; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + // ReSharper disable once CheckNamespace namespace Microsoft.EntityFrameworkCore { @@ -25,7 +27,7 @@ public static class SqlServerModelExtensions /// The model. /// The name to use for the default hi-lo sequence. public static string GetHiLoSequenceName([NotNull] this IModel model) - => (string)model[SqlServerAnnotationNames.HiLoSequenceName] + => (string?)model[SqlServerAnnotationNames.HiLoSequenceName] ?? DefaultHiLoSequenceName; /// @@ -33,7 +35,7 @@ public static string GetHiLoSequenceName([NotNull] this IModel model) /// /// The model. /// The value to set. - public static void SetHiLoSequenceName([NotNull] this IMutableModel model, [CanBeNull] string name) + public static void SetHiLoSequenceName([NotNull] this IMutableModel model, [CanBeNull] string? name) { Check.NullButNotEmpty(name, nameof(name)); @@ -47,9 +49,9 @@ public static void SetHiLoSequenceName([NotNull] this IMutableModel model, [CanB /// The value to set. /// Indicates whether the configuration was specified using a data annotation. /// The configured value. - public static string SetHiLoSequenceName( + public static string? SetHiLoSequenceName( [NotNull] this IConventionModel model, - [CanBeNull] string name, + [CanBeNull] string? name, bool fromDataAnnotation = false) { Check.NullButNotEmpty(name, nameof(name)); @@ -73,15 +75,15 @@ public static string SetHiLoSequenceName( /// /// The model. /// The schema to use for the default hi-lo sequence. - public static string GetHiLoSequenceSchema([NotNull] this IModel model) - => (string)model[SqlServerAnnotationNames.HiLoSequenceSchema]; + public static string? GetHiLoSequenceSchema([NotNull] this IModel model) + => (string?)model[SqlServerAnnotationNames.HiLoSequenceSchema]; /// /// Sets the schema to use for the default hi-lo sequence. /// /// The model. /// The value to set. - public static void SetHiLoSequenceSchema([NotNull] this IMutableModel model, [CanBeNull] string value) + public static void SetHiLoSequenceSchema([NotNull] this IMutableModel model, [CanBeNull] string? value) { Check.NullButNotEmpty(value, nameof(value)); @@ -95,9 +97,9 @@ public static void SetHiLoSequenceSchema([NotNull] this IMutableModel model, [Ca /// The value to set. /// Indicates whether the configuration was specified using a data annotation. /// The configured value. - public static string SetHiLoSequenceSchema( + public static string? SetHiLoSequenceSchema( [NotNull] this IConventionModel model, - [CanBeNull] string value, + [CanBeNull] string? value, bool fromDataAnnotation = false) { Check.NullButNotEmpty(value, nameof(value)); @@ -255,15 +257,15 @@ public static void SetValueGenerationStrategy( /// /// The model. /// The maximum size of the database. - public static string GetDatabaseMaxSize([NotNull] this IModel model) - => (string)model[SqlServerAnnotationNames.MaxDatabaseSize]; + public static string? GetDatabaseMaxSize([NotNull] this IModel model) + => (string?)model[SqlServerAnnotationNames.MaxDatabaseSize]; /// /// Sets the maximum size of the database. /// /// The model. /// The value to set. - public static void SetDatabaseMaxSize([NotNull] this IMutableModel model, [CanBeNull] string value) + public static void SetDatabaseMaxSize([NotNull] this IMutableModel model, [CanBeNull] string? value) => model.SetOrRemoveAnnotation(SqlServerAnnotationNames.MaxDatabaseSize, value); /// @@ -273,9 +275,9 @@ public static void SetDatabaseMaxSize([NotNull] this IMutableModel model, [CanBe /// The value to set. /// Indicates whether the configuration was specified using a data annotation. /// The configured value. - public static string SetDatabaseMaxSize( + public static string? SetDatabaseMaxSize( [NotNull] this IConventionModel model, - [CanBeNull] string value, + [CanBeNull] string? value, bool fromDataAnnotation = false) { model.SetOrRemoveAnnotation(SqlServerAnnotationNames.MaxDatabaseSize, value, fromDataAnnotation); @@ -296,15 +298,15 @@ public static string SetDatabaseMaxSize( /// /// The model. /// The service tier of the database. - public static string GetServiceTierSql([NotNull] this IModel model) - => (string)model[SqlServerAnnotationNames.ServiceTierSql]; + public static string? GetServiceTierSql([NotNull] this IModel model) + => (string?)model[SqlServerAnnotationNames.ServiceTierSql]; /// /// Sets the service tier of the database. /// /// The model. /// The value to set. - public static void SetServiceTierSql([NotNull] this IMutableModel model, [CanBeNull] string value) + public static void SetServiceTierSql([NotNull] this IMutableModel model, [CanBeNull] string? value) => model.SetOrRemoveAnnotation(SqlServerAnnotationNames.ServiceTierSql, value); /// @@ -314,9 +316,9 @@ public static void SetServiceTierSql([NotNull] this IMutableModel model, [CanBeN /// The value to set. /// Indicates whether the configuration was specified using a data annotation. /// The configured value. - public static string SetServiceTierSql( + public static string? SetServiceTierSql( [NotNull] this IConventionModel model, - [CanBeNull] string value, + [CanBeNull] string? value, bool fromDataAnnotation = false) { model.SetOrRemoveAnnotation(SqlServerAnnotationNames.ServiceTierSql, value, fromDataAnnotation); @@ -337,15 +339,15 @@ public static string SetServiceTierSql( /// /// The model. /// The performance level of the database. - public static string GetPerformanceLevelSql([NotNull] this IModel model) - => (string)model[SqlServerAnnotationNames.PerformanceLevelSql]; + public static string? GetPerformanceLevelSql([NotNull] this IModel model) + => (string?)model[SqlServerAnnotationNames.PerformanceLevelSql]; /// /// Sets the performance level of the database. /// /// The model. /// The value to set. - public static void SetPerformanceLevelSql([NotNull] this IMutableModel model, [CanBeNull] string value) + public static void SetPerformanceLevelSql([NotNull] this IMutableModel model, [CanBeNull] string? value) => model.SetOrRemoveAnnotation(SqlServerAnnotationNames.PerformanceLevelSql, value); /// @@ -355,9 +357,9 @@ public static void SetPerformanceLevelSql([NotNull] this IMutableModel model, [C /// The value to set. /// Indicates whether the configuration was specified using a data annotation. /// The configured value. - public static string SetPerformanceLevelSql( + public static string? SetPerformanceLevelSql( [NotNull] this IConventionModel model, - [CanBeNull] string value, + [CanBeNull] string? value, bool fromDataAnnotation = false) { model.SetOrRemoveAnnotation(SqlServerAnnotationNames.PerformanceLevelSql, value, fromDataAnnotation); diff --git a/src/EFCore.SqlServer/Extensions/SqlServerPropertyBuilderExtensions.cs b/src/EFCore.SqlServer/Extensions/SqlServerPropertyBuilderExtensions.cs index 87b10a7cf72..76d2411f10f 100644 --- a/src/EFCore.SqlServer/Extensions/SqlServerPropertyBuilderExtensions.cs +++ b/src/EFCore.SqlServer/Extensions/SqlServerPropertyBuilderExtensions.cs @@ -7,6 +7,8 @@ using Microsoft.EntityFrameworkCore.SqlServer.Metadata.Internal; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + // ReSharper disable once CheckNamespace namespace Microsoft.EntityFrameworkCore { @@ -25,8 +27,8 @@ public static class SqlServerPropertyBuilderExtensions /// The same builder instance so that multiple calls can be chained. public static PropertyBuilder UseHiLo( [NotNull] this PropertyBuilder propertyBuilder, - [CanBeNull] string name = null, - [CanBeNull] string schema = null) + [CanBeNull] string? name = null, + [CanBeNull] string? schema = null) { Check.NotNull(propertyBuilder, nameof(propertyBuilder)); Check.NullButNotEmpty(name, nameof(name)); @@ -63,8 +65,8 @@ public static PropertyBuilder UseHiLo( /// The same builder instance so that multiple calls can be chained. public static PropertyBuilder UseHiLo( [NotNull] this PropertyBuilder propertyBuilder, - [CanBeNull] string name = null, - [CanBeNull] string schema = null) + [CanBeNull] string? name = null, + [CanBeNull] string? schema = null) => (PropertyBuilder)UseHiLo((PropertyBuilder)propertyBuilder, name, schema); /// @@ -76,10 +78,10 @@ public static PropertyBuilder UseHiLo( /// The schema of the sequence. /// Indicates whether the configuration was specified using a data annotation. /// A builder to further configure the sequence. - public static IConventionSequenceBuilder HasHiLoSequence( + public static IConventionSequenceBuilder? HasHiLoSequence( [NotNull] this IConventionPropertyBuilder propertyBuilder, - [CanBeNull] string name, - [CanBeNull] string schema, + [CanBeNull] string? name, + [CanBeNull] string? schema, bool fromDataAnnotation = false) { if (!propertyBuilder.CanSetHiLoSequence(name, schema, fromDataAnnotation)) @@ -105,8 +107,8 @@ public static IConventionSequenceBuilder HasHiLoSequence( /// if the given name and schema can be set for the hi-lo sequence. public static bool CanSetHiLoSequence( [NotNull] this IConventionPropertyBuilder propertyBuilder, - [CanBeNull] string name, - [CanBeNull] string schema, + [CanBeNull] string? name, + [CanBeNull] string? schema, bool fromDataAnnotation = false) { Check.NotNull(propertyBuilder, nameof(propertyBuilder)); @@ -167,7 +169,7 @@ public static PropertyBuilder UseIdentityColumn( /// The same builder instance if the configuration was applied, /// otherwise. /// - public static IConventionPropertyBuilder HasIdentityColumnSeed( + public static IConventionPropertyBuilder? HasIdentityColumnSeed( [NotNull] this IConventionPropertyBuilder propertyBuilder, int? seed, bool fromDataAnnotation = false) @@ -208,7 +210,7 @@ public static bool CanSetIdentityColumnSeed( /// The same builder instance if the configuration was applied, /// otherwise. /// - public static IConventionPropertyBuilder HasIdentityColumnIncrement( + public static IConventionPropertyBuilder? HasIdentityColumnIncrement( [NotNull] this IConventionPropertyBuilder propertyBuilder, int? increment, bool fromDataAnnotation = false) @@ -249,7 +251,7 @@ public static bool CanSetIdentityColumnIncrement( /// The same builder instance if the configuration was applied, /// otherwise. /// - public static IConventionPropertyBuilder HasValueGenerationStrategy( + public static IConventionPropertyBuilder? HasValueGenerationStrategy( [NotNull] this IConventionPropertyBuilder propertyBuilder, SqlServerValueGenerationStrategy? valueGenerationStrategy, bool fromDataAnnotation = false) diff --git a/src/EFCore.SqlServer/Extensions/SqlServerPropertyExtensions.cs b/src/EFCore.SqlServer/Extensions/SqlServerPropertyExtensions.cs index 4de01863479..698c8ca8dca 100644 --- a/src/EFCore.SqlServer/Extensions/SqlServerPropertyExtensions.cs +++ b/src/EFCore.SqlServer/Extensions/SqlServerPropertyExtensions.cs @@ -10,6 +10,8 @@ using Microsoft.EntityFrameworkCore.SqlServer.Metadata.Internal; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + // ReSharper disable once CheckNamespace namespace Microsoft.EntityFrameworkCore { @@ -23,8 +25,8 @@ public static class SqlServerPropertyExtensions /// /// The property. /// The name to use for the hi-lo sequence. - public static string GetHiLoSequenceName([NotNull] this IProperty property) - => (string)property[SqlServerAnnotationNames.HiLoSequenceName]; + public static string? GetHiLoSequenceName([NotNull] this IProperty property) + => (string?)property[SqlServerAnnotationNames.HiLoSequenceName]; /// /// Returns the name to use for the hi-lo sequence. @@ -32,7 +34,7 @@ public static string GetHiLoSequenceName([NotNull] this IProperty property) /// The property. /// The identifier of the store object. /// The name to use for the hi-lo sequence. - public static string GetHiLoSequenceName([NotNull] this IProperty property, in StoreObjectIdentifier storeObject) + public static string? GetHiLoSequenceName([NotNull] this IProperty property, in StoreObjectIdentifier storeObject) { var annotation = property.FindAnnotation(SqlServerAnnotationNames.HiLoSequenceName); if (annotation != null) @@ -51,7 +53,7 @@ public static string GetHiLoSequenceName([NotNull] this IProperty property, in S /// /// The property. /// The sequence name to use. - public static void SetHiLoSequenceName([NotNull] this IMutableProperty property, [CanBeNull] string name) + public static void SetHiLoSequenceName([NotNull] this IMutableProperty property, [CanBeNull] string? name) => property.SetOrRemoveAnnotation( SqlServerAnnotationNames.HiLoSequenceName, Check.NullButNotEmpty(name, nameof(name))); @@ -63,9 +65,9 @@ public static void SetHiLoSequenceName([NotNull] this IMutableProperty property, /// The sequence name to use. /// Indicates whether the configuration was specified using a data annotation. /// The configured value. - public static string SetHiLoSequenceName( + public static string? SetHiLoSequenceName( [NotNull] this IConventionProperty property, - [CanBeNull] string name, + [CanBeNull] string? name, bool fromDataAnnotation = false) { property.SetOrRemoveAnnotation( @@ -89,8 +91,8 @@ public static string SetHiLoSequenceName( /// /// The property. /// The schema to use for the hi-lo sequence. - public static string GetHiLoSequenceSchema([NotNull] this IProperty property) - => (string)property[SqlServerAnnotationNames.HiLoSequenceSchema]; + public static string? GetHiLoSequenceSchema([NotNull] this IProperty property) + => (string?)property[SqlServerAnnotationNames.HiLoSequenceSchema]; /// /// Returns the schema to use for the hi-lo sequence. @@ -98,7 +100,7 @@ public static string GetHiLoSequenceSchema([NotNull] this IProperty property) /// The property. /// The identifier of the store object. /// The schema to use for the hi-lo sequence. - public static string GetHiLoSequenceSchema([NotNull] this IProperty property, in StoreObjectIdentifier storeObject) + public static string? GetHiLoSequenceSchema([NotNull] this IProperty property, in StoreObjectIdentifier storeObject) { var annotation = property.FindAnnotation(SqlServerAnnotationNames.HiLoSequenceSchema); if (annotation != null) @@ -117,7 +119,7 @@ public static string GetHiLoSequenceSchema([NotNull] this IProperty property, in /// /// The property. /// The schema to use. - public static void SetHiLoSequenceSchema([NotNull] this IMutableProperty property, [CanBeNull] string schema) + public static void SetHiLoSequenceSchema([NotNull] this IMutableProperty property, [CanBeNull] string? schema) => property.SetOrRemoveAnnotation( SqlServerAnnotationNames.HiLoSequenceSchema, Check.NullButNotEmpty(schema, nameof(schema))); @@ -129,9 +131,9 @@ public static void SetHiLoSequenceSchema([NotNull] this IMutableProperty propert /// The schema to use. /// Indicates whether the configuration was specified using a data annotation. /// The configured value. - public static string SetHiLoSequenceSchema( + public static string? SetHiLoSequenceSchema( [NotNull] this IConventionProperty property, - [CanBeNull] string schema, + [CanBeNull] string? schema, bool fromDataAnnotation = false) { property.SetOrRemoveAnnotation( @@ -155,7 +157,7 @@ public static string SetHiLoSequenceSchema( /// /// The property. /// The sequence to use, or if no sequence exists in the model. - public static ISequence FindHiLoSequence([NotNull] this IProperty property) + public static ISequence? FindHiLoSequence([NotNull] this IProperty property) { var model = property.DeclaringEntityType.Model; @@ -174,7 +176,7 @@ public static ISequence FindHiLoSequence([NotNull] this IProperty property) /// The property. /// The identifier of the store object. /// The sequence to use, or if no sequence exists in the model. - public static ISequence FindHiLoSequence([NotNull] this IProperty property, in StoreObjectIdentifier storeObject) + public static ISequence? FindHiLoSequence([NotNull] this IProperty property, in StoreObjectIdentifier storeObject) { var model = property.DeclaringEntityType.Model; diff --git a/src/EFCore.SqlServer/Metadata/Conventions/SqlServerConventionSetBuilder.cs b/src/EFCore.SqlServer/Metadata/Conventions/SqlServerConventionSetBuilder.cs index 9534d5ba9b3..1b0de1b5ccb 100644 --- a/src/EFCore.SqlServer/Metadata/Conventions/SqlServerConventionSetBuilder.cs +++ b/src/EFCore.SqlServer/Metadata/Conventions/SqlServerConventionSetBuilder.cs @@ -7,6 +7,8 @@ using Microsoft.EntityFrameworkCore.Storage; using Microsoft.Extensions.DependencyInjection; +#nullable enable + // ReSharper disable once CheckNamespace namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { @@ -119,7 +121,7 @@ public override ConventionSet CreateConventionSet() public static ConventionSet Build() { using var serviceScope = CreateServiceScope(); - using var context = serviceScope.ServiceProvider.GetService(); + using var context = serviceScope.ServiceProvider.GetRequiredService(); return ConventionSet.CreateConventionSet(context); } @@ -136,7 +138,7 @@ public static ConventionSet Build() public static ModelBuilder CreateModelBuilder() { using var serviceScope = CreateServiceScope(); - using var context = serviceScope.ServiceProvider.GetService(); + using var context = serviceScope.ServiceProvider.GetRequiredService(); return new ModelBuilder(ConventionSet.CreateConventionSet(context), context.GetService()); } diff --git a/src/EFCore.SqlServer/Metadata/Conventions/SqlServerDbFunctionConvention.cs b/src/EFCore.SqlServer/Metadata/Conventions/SqlServerDbFunctionConvention.cs index 75b021c82ee..d6fef269e6a 100644 --- a/src/EFCore.SqlServer/Metadata/Conventions/SqlServerDbFunctionConvention.cs +++ b/src/EFCore.SqlServer/Metadata/Conventions/SqlServerDbFunctionConvention.cs @@ -6,6 +6,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + // ReSharper disable once CheckNamespace namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { diff --git a/src/EFCore.SqlServer/Metadata/Conventions/SqlServerIndexConvention.cs b/src/EFCore.SqlServer/Metadata/Conventions/SqlServerIndexConvention.cs index 496b51663d9..71752d77e12 100644 --- a/src/EFCore.SqlServer/Metadata/Conventions/SqlServerIndexConvention.cs +++ b/src/EFCore.SqlServer/Metadata/Conventions/SqlServerIndexConvention.cs @@ -1,9 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System; using System.Collections.Generic; -using System.Linq; using System.Text; using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Metadata.Builders; @@ -11,6 +9,8 @@ using Microsoft.EntityFrameworkCore.SqlServer.Metadata.Internal; using Microsoft.EntityFrameworkCore.Storage; +#nullable enable + // ReSharper disable once CheckNamespace namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { @@ -57,8 +57,8 @@ public SqlServerIndexConvention( /// Additional information associated with convention execution. public virtual void ProcessEntityTypeBaseTypeChanged( IConventionEntityTypeBuilder entityTypeBuilder, - IConventionEntityType newBaseType, - IConventionEntityType oldBaseType, + IConventionEntityType? newBaseType, + IConventionEntityType? oldBaseType, IConventionContext context) { if (oldBaseType == null @@ -117,8 +117,8 @@ public virtual void ProcessPropertyNullabilityChanged( public virtual void ProcessIndexAnnotationChanged( IConventionIndexBuilder indexBuilder, string name, - IConventionAnnotation annotation, - IConventionAnnotation oldAnnotation, + IConventionAnnotation? annotation, + IConventionAnnotation? oldAnnotation, IConventionContext context) { if (name == SqlServerAnnotationNames.Clustered) @@ -138,8 +138,8 @@ public virtual void ProcessIndexAnnotationChanged( public virtual void ProcessPropertyAnnotationChanged( IConventionPropertyBuilder propertyBuilder, string name, - IConventionAnnotation annotation, - IConventionAnnotation oldAnnotation, + IConventionAnnotation? annotation, + IConventionAnnotation? oldAnnotation, IConventionContext context) { if (name == RelationalAnnotationNames.ColumnName) @@ -194,7 +194,7 @@ private string CreateIndexFilter(List nullableColumns) return builder.ToString(); } - private List GetNullableColumns(IIndex index) + private List? GetNullableColumns(IIndex index) { var tableName = index.DeclaringEntityType.GetTableName(); if (tableName == null) diff --git a/src/EFCore.SqlServer/Metadata/Conventions/SqlServerMemoryOptimizedTablesConvention.cs b/src/EFCore.SqlServer/Metadata/Conventions/SqlServerMemoryOptimizedTablesConvention.cs index 2af20680181..0bf35351c5a 100644 --- a/src/EFCore.SqlServer/Metadata/Conventions/SqlServerMemoryOptimizedTablesConvention.cs +++ b/src/EFCore.SqlServer/Metadata/Conventions/SqlServerMemoryOptimizedTablesConvention.cs @@ -7,6 +7,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure; using Microsoft.EntityFrameworkCore.SqlServer.Metadata.Internal; +#nullable enable + // ReSharper disable once CheckNamespace namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { @@ -46,8 +48,8 @@ public SqlServerMemoryOptimizedTablesConvention( public virtual void ProcessEntityTypeAnnotationChanged( IConventionEntityTypeBuilder entityTypeBuilder, string name, - IConventionAnnotation annotation, - IConventionAnnotation oldAnnotation, + IConventionAnnotation? annotation, + IConventionAnnotation? oldAnnotation, IConventionContext context) { if (name == SqlServerAnnotationNames.MemoryOptimized) diff --git a/src/EFCore.SqlServer/Metadata/Conventions/SqlServerOnDeleteConvention.cs b/src/EFCore.SqlServer/Metadata/Conventions/SqlServerOnDeleteConvention.cs index 0e8787489f3..ce57e97fa06 100644 --- a/src/EFCore.SqlServer/Metadata/Conventions/SqlServerOnDeleteConvention.cs +++ b/src/EFCore.SqlServer/Metadata/Conventions/SqlServerOnDeleteConvention.cs @@ -6,6 +6,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure; +#nullable enable + // ReSharper disable once CheckNamespace namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { @@ -30,11 +32,14 @@ public SqlServerOnDeleteConvention( /// public virtual void ProcessSkipNavigationForeignKeyChanged( IConventionSkipNavigationBuilder skipNavigationBuilder, - IConventionForeignKey foreignKey, - IConventionForeignKey oldForeignKey, + IConventionForeignKey? foreignKey, + IConventionForeignKey? oldForeignKey, IConventionContext context) { - foreignKey?.Builder?.OnDelete(GetTargetDeleteBehavior(foreignKey)); + if (foreignKey is not null && foreignKey.IsInModel) + { + foreignKey.Builder.OnDelete(GetTargetDeleteBehavior(foreignKey)); + } } /// @@ -63,7 +68,7 @@ protected override DeleteBehavior GetTargetDeleteBehavior(IConventionForeignKey .First(s => s == selfReferencingSkipNavigation || s == selfReferencingSkipNavigation.Inverse) && selfReferencingSkipNavigation != selfReferencingSkipNavigation.Inverse) { - selfReferencingSkipNavigation.Inverse.ForeignKey?.Builder.OnDelete( + selfReferencingSkipNavigation.Inverse!.ForeignKey?.Builder.OnDelete( GetTargetDeleteBehavior(selfReferencingSkipNavigation.Inverse.ForeignKey)); return DeleteBehavior.ClientCascade; } diff --git a/src/EFCore.SqlServer/Metadata/Conventions/SqlServerSharedTableConvention.cs b/src/EFCore.SqlServer/Metadata/Conventions/SqlServerSharedTableConvention.cs index a30fb790f23..ff4c02aca92 100644 --- a/src/EFCore.SqlServer/Metadata/Conventions/SqlServerSharedTableConvention.cs +++ b/src/EFCore.SqlServer/Metadata/Conventions/SqlServerSharedTableConvention.cs @@ -5,6 +5,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata.Internal; +#nullable enable + // ReSharper disable once CheckNamespace namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { diff --git a/src/EFCore.SqlServer/Metadata/Conventions/SqlServerStoreGenerationConvention.cs b/src/EFCore.SqlServer/Metadata/Conventions/SqlServerStoreGenerationConvention.cs index b4a9b9f1188..7671ceabdb2 100644 --- a/src/EFCore.SqlServer/Metadata/Conventions/SqlServerStoreGenerationConvention.cs +++ b/src/EFCore.SqlServer/Metadata/Conventions/SqlServerStoreGenerationConvention.cs @@ -8,6 +8,8 @@ using Microsoft.EntityFrameworkCore.SqlServer.Internal; using Microsoft.EntityFrameworkCore.SqlServer.Metadata.Internal; +#nullable enable + // ReSharper disable once CheckNamespace namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { @@ -40,8 +42,8 @@ public SqlServerStoreGenerationConvention( public override void ProcessPropertyAnnotationChanged( IConventionPropertyBuilder propertyBuilder, string name, - IConventionAnnotation annotation, - IConventionAnnotation oldAnnotation, + IConventionAnnotation? annotation, + IConventionAnnotation? oldAnnotation, IConventionContext context) { if (annotation == null diff --git a/src/EFCore.SqlServer/Metadata/Conventions/SqlServerValueGenerationConvention.cs b/src/EFCore.SqlServer/Metadata/Conventions/SqlServerValueGenerationConvention.cs index 987a2e205f1..9b42f0568b2 100644 --- a/src/EFCore.SqlServer/Metadata/Conventions/SqlServerValueGenerationConvention.cs +++ b/src/EFCore.SqlServer/Metadata/Conventions/SqlServerValueGenerationConvention.cs @@ -6,6 +6,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure; using Microsoft.EntityFrameworkCore.SqlServer.Metadata.Internal; +#nullable enable + // ReSharper disable once CheckNamespace namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { @@ -40,8 +42,8 @@ public SqlServerValueGenerationConvention( public override void ProcessPropertyAnnotationChanged( IConventionPropertyBuilder propertyBuilder, string name, - IConventionAnnotation annotation, - IConventionAnnotation oldAnnotation, + IConventionAnnotation? annotation, + IConventionAnnotation? oldAnnotation, IConventionContext context) { if (name == SqlServerAnnotationNames.ValueGenerationStrategy) diff --git a/src/EFCore.SqlServer/Metadata/Conventions/SqlServerValueGenerationStrategyConvention.cs b/src/EFCore.SqlServer/Metadata/Conventions/SqlServerValueGenerationStrategyConvention.cs index 74a8350d455..54b844c885e 100644 --- a/src/EFCore.SqlServer/Metadata/Conventions/SqlServerValueGenerationStrategyConvention.cs +++ b/src/EFCore.SqlServer/Metadata/Conventions/SqlServerValueGenerationStrategyConvention.cs @@ -6,6 +6,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure; +#nullable enable + // ReSharper disable once CheckNamespace namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { diff --git a/src/EFCore.SqlServer/Metadata/Internal/SqlServerAnnotationProvider.cs b/src/EFCore.SqlServer/Metadata/Internal/SqlServerAnnotationProvider.cs index 0f39713cd6c..d383314fb47 100644 --- a/src/EFCore.SqlServer/Metadata/Internal/SqlServerAnnotationProvider.cs +++ b/src/EFCore.SqlServer/Metadata/Internal/SqlServerAnnotationProvider.cs @@ -147,12 +147,11 @@ public override IEnumerable For(ITableIndex index) isClustered.Value); } - var includeProperties = modelIndex.GetIncludeProperties(); - if (includeProperties != null) + if (modelIndex.GetIncludeProperties() is IReadOnlyList includeProperties) { - var includeColumns = (IReadOnlyList)includeProperties + var includeColumns = includeProperties .Select( - p => modelIndex.DeclaringEntityType.FindProperty(p) + p => modelIndex.DeclaringEntityType.FindProperty(p)! .GetColumnName(StoreObjectIdentifier.Table(table.Name, table.Schema))) .ToArray(); diff --git a/src/EFCore.SqlServer/Metadata/Internal/SqlServerIndexExtensions.cs b/src/EFCore.SqlServer/Metadata/Internal/SqlServerIndexExtensions.cs index 73e6c5d22a3..1dd76a2f41a 100644 --- a/src/EFCore.SqlServer/Metadata/Internal/SqlServerIndexExtensions.cs +++ b/src/EFCore.SqlServer/Metadata/Internal/SqlServerIndexExtensions.cs @@ -108,12 +108,11 @@ public static bool AreCompatibleForSqlServer( return true; static bool SameColumnNames(IIndex index, IIndex duplicateIndex, StoreObjectIdentifier storeObject) - => index.GetIncludeProperties().Select( - p => index.DeclaringEntityType.FindProperty(p).GetColumnName(storeObject)) + => index.GetIncludeProperties()!.Select( + p => index.DeclaringEntityType.FindProperty(p)!.GetColumnName(storeObject)) .SequenceEqual( - duplicateIndex.GetIncludeProperties().Select( - p => duplicateIndex.DeclaringEntityType.FindProperty(p) - .GetColumnName(storeObject))); + duplicateIndex.GetIncludeProperties()!.Select( + p => duplicateIndex.DeclaringEntityType.FindProperty(p)!.GetColumnName(storeObject))); } private static string FormatInclude(IIndex index, StoreObjectIdentifier storeObject) @@ -122,7 +121,7 @@ private static string FormatInclude(IIndex index, StoreObjectIdentifier storeObj : "{'" + string.Join( "', '", - index.GetIncludeProperties().Select( + index.GetIncludeProperties()!.Select( p => index.DeclaringEntityType.FindProperty(p) ?.GetColumnName(storeObject))) + "'}"; diff --git a/src/EFCore.Sqlite.Core/Extensions/SqlitePropertyBuilderExtensions.cs b/src/EFCore.Sqlite.Core/Extensions/SqlitePropertyBuilderExtensions.cs index e3bc5f405da..e38e582ad42 100644 --- a/src/EFCore.Sqlite.Core/Extensions/SqlitePropertyBuilderExtensions.cs +++ b/src/EFCore.Sqlite.Core/Extensions/SqlitePropertyBuilderExtensions.cs @@ -6,6 +6,8 @@ using Microsoft.EntityFrameworkCore.Sqlite.Metadata.Internal; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + // ReSharper disable once CheckNamespace namespace Microsoft.EntityFrameworkCore { @@ -50,7 +52,7 @@ public static PropertyBuilder HasSrid( /// The same builder instance if the configuration was applied, /// otherwise. /// - public static IConventionPropertyBuilder HasSrid( + public static IConventionPropertyBuilder? HasSrid( [NotNull] this IConventionPropertyBuilder propertyBuilder, int? srid, bool fromDataAnnotation = false) diff --git a/src/EFCore.Sqlite.Core/Extensions/SqlitePropertyExtensions.cs b/src/EFCore.Sqlite.Core/Extensions/SqlitePropertyExtensions.cs index 610e3e29d8f..47c0737aaf2 100644 --- a/src/EFCore.Sqlite.Core/Extensions/SqlitePropertyExtensions.cs +++ b/src/EFCore.Sqlite.Core/Extensions/SqlitePropertyExtensions.cs @@ -5,6 +5,8 @@ using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Sqlite.Metadata.Internal; +#nullable enable + // ReSharper disable once CheckNamespace namespace Microsoft.EntityFrameworkCore { diff --git a/src/EFCore.Sqlite.Core/Metadata/Conventions/SqliteConventionSetBuilder.cs b/src/EFCore.Sqlite.Core/Metadata/Conventions/SqliteConventionSetBuilder.cs index 047aacd5d49..5a4bf508974 100644 --- a/src/EFCore.Sqlite.Core/Metadata/Conventions/SqliteConventionSetBuilder.cs +++ b/src/EFCore.Sqlite.Core/Metadata/Conventions/SqliteConventionSetBuilder.cs @@ -6,6 +6,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure; using Microsoft.Extensions.DependencyInjection; +#nullable enable + // ReSharper disable once CheckNamespace namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { @@ -49,7 +51,7 @@ public SqliteConventionSetBuilder( public static ConventionSet Build() { using var serviceScope = CreateServiceScope(); - using var context = serviceScope.ServiceProvider.GetService(); + using var context = serviceScope.ServiceProvider.GetRequiredService(); return ConventionSet.CreateConventionSet(context); } @@ -66,7 +68,7 @@ public static ConventionSet Build() public static ModelBuilder CreateModelBuilder() { using var serviceScope = CreateServiceScope(); - using var context = serviceScope.ServiceProvider.GetService(); + using var context = serviceScope.ServiceProvider.GetRequiredService(); return new ModelBuilder(ConventionSet.CreateConventionSet(context), context.GetService()); } diff --git a/src/EFCore/Extensions/ConventionAnnotatableExtensions.cs b/src/EFCore/Extensions/ConventionAnnotatableExtensions.cs index 7638e690294..4f8fd686513 100644 --- a/src/EFCore/Extensions/ConventionAnnotatableExtensions.cs +++ b/src/EFCore/Extensions/ConventionAnnotatableExtensions.cs @@ -7,6 +7,8 @@ using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Metadata.Internal; +#nullable enable + // ReSharper disable once CheckNamespace namespace Microsoft.EntityFrameworkCore { @@ -52,10 +54,10 @@ public static void AddAnnotations( /// The value to be stored in the annotation. /// Indicates whether the configuration was specified using a data annotation. /// The new annotation or if it was removed. - public static IConventionAnnotation SetOrRemoveAnnotation( + public static IConventionAnnotation? SetOrRemoveAnnotation( [NotNull] this IConventionAnnotatable annotatable, [NotNull] string name, - [CanBeNull] object value, + [CanBeNull] object? value, bool fromDataAnnotation = false) => ((ConventionAnnotatable)annotatable).SetOrRemoveAnnotation( name, value, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); diff --git a/src/EFCore/Extensions/ConventionForeignKeyExtensions.cs b/src/EFCore/Extensions/ConventionForeignKeyExtensions.cs index d040fb35112..cbcf3c640a1 100644 --- a/src/EFCore/Extensions/ConventionForeignKeyExtensions.cs +++ b/src/EFCore/Extensions/ConventionForeignKeyExtensions.cs @@ -4,6 +4,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Metadata; +#nullable enable + // ReSharper disable once CheckNamespace namespace Microsoft.EntityFrameworkCore { @@ -33,7 +35,7 @@ public static IConventionEntityType GetRelatedEntityType( /// /// A navigation associated with this foreign key or . /// - public static IConventionNavigation GetNavigation([NotNull] this IConventionForeignKey foreignKey, bool pointsToPrincipal) + public static IConventionNavigation? GetNavigation([NotNull] this IConventionForeignKey foreignKey, bool pointsToPrincipal) => pointsToPrincipal ? foreignKey.DependentToPrincipal : foreignKey.PrincipalToDependent; } } diff --git a/src/EFCore/Extensions/ConventionKeyExtensions.cs b/src/EFCore/Extensions/ConventionKeyExtensions.cs index da8bbf2c0e9..d887236d4cf 100644 --- a/src/EFCore/Extensions/ConventionKeyExtensions.cs +++ b/src/EFCore/Extensions/ConventionKeyExtensions.cs @@ -6,6 +6,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Metadata; +#nullable enable + // ReSharper disable once CheckNamespace namespace Microsoft.EntityFrameworkCore { diff --git a/src/EFCore/Extensions/ConventionModelExtensions.cs b/src/EFCore/Extensions/ConventionModelExtensions.cs index b8a2d59a79a..b407774a7de 100644 --- a/src/EFCore/Extensions/ConventionModelExtensions.cs +++ b/src/EFCore/Extensions/ConventionModelExtensions.cs @@ -9,6 +9,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Internal; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + // ReSharper disable once CheckNamespace namespace Microsoft.EntityFrameworkCore { @@ -23,7 +25,7 @@ public static class ConventionModelExtensions /// The model to find the entity type in. /// The type to find the corresponding entity type for. /// The entity type, or if none if found. - public static IConventionEntityType FindEntityType([NotNull] this IConventionModel model, [NotNull] Type type) + public static IConventionEntityType? FindEntityType([NotNull] this IConventionModel model, [NotNull] Type type) => ((Model)model).FindEntityType(type); /// @@ -35,12 +37,12 @@ public static IConventionEntityType FindEntityType([NotNull] this IConventionMod /// The defining navigation of the entity type to find. /// The defining entity type of the entity type to find. /// The entity type, or if none are found. - public static IConventionEntityType FindEntityType( + public static IConventionEntityType? FindEntityType( [NotNull] this IConventionModel model, [NotNull] Type type, [NotNull] string definingNavigationName, [NotNull] IConventionEntityType definingEntityType) - => (IConventionEntityType)((IModel)model).FindEntityType(type, definingNavigationName, definingEntityType); + => (IConventionEntityType?)((IModel)model).FindEntityType(type, definingNavigationName, definingEntityType); /// /// Gets the entity types matching the given type. @@ -71,7 +73,7 @@ public static IReadOnlyCollection GetEntityTypes( /// The model to remove the entity type from. /// The name of the entity type to be removed. /// The entity type that was removed. - public static IConventionEntityType RemoveEntityType( + public static IConventionEntityType? RemoveEntityType( [NotNull] this IConventionModel model, [NotNull] string name) { @@ -90,7 +92,7 @@ public static IConventionEntityType RemoveEntityType( /// The defining navigation. /// The defining entity type. /// The entity type that was removed. - public static IConventionEntityType RemoveEntityType( + public static IConventionEntityType? RemoveEntityType( [NotNull] this IConventionModel model, [NotNull] string name, [NotNull] string definingNavigationName, @@ -110,7 +112,7 @@ public static IConventionEntityType RemoveEntityType( /// The model to remove the entity type from. /// The entity type to be removed. /// The entity type that was removed. - public static IConventionEntityType RemoveEntityType([NotNull] this IConventionModel model, [NotNull] Type type) + public static IConventionEntityType? RemoveEntityType([NotNull] this IConventionModel model, [NotNull] Type type) { Check.NotNull(model, nameof(model)); Check.NotNull(type, nameof(type)); @@ -127,7 +129,7 @@ public static IConventionEntityType RemoveEntityType([NotNull] this IConventionM /// The defining navigation. /// The defining entity type. /// The entity type that was removed. - public static IConventionEntityType RemoveEntityType( + public static IConventionEntityType? RemoveEntityType( [NotNull] this IConventionModel model, [NotNull] Type type, [NotNull] string definingNavigationName, @@ -147,7 +149,7 @@ public static IConventionEntityType RemoveEntityType( public static IReadOnlyList FindLeastDerivedEntityTypes( [NotNull] this IConventionModel model, [NotNull] Type type, - [CanBeNull] Func condition = null) + [CanBeNull] Func? condition = null) => Check.NotNull((Model)model, nameof(model)) .FindLeastDerivedEntityTypes(type, condition); @@ -288,7 +290,7 @@ public static bool IsIgnored([NotNull] this IConventionModel model, [NotNull] Ty /// The model to remove the owned type name from. /// The type of the entity type that should not be owned. /// The name of the removed owned type. - public static string RemoveOwned([NotNull] this IConventionModel model, [NotNull] Type type) + public static string? RemoveOwned([NotNull] this IConventionModel model, [NotNull] Type type) => Check.NotNull((Model)model, nameof(model)).RemoveOwned( Check.NotNull(type, nameof(type))); @@ -299,7 +301,7 @@ public static string RemoveOwned([NotNull] this IConventionModel model, [NotNull /// The entity type to be ignored. /// Indicates whether the configuration was specified using a data annotation. /// The name of the ignored entity type. - public static string AddIgnored([NotNull] this IConventionModel model, [NotNull] Type type, bool fromDataAnnotation = false) + public static string? AddIgnored([NotNull] this IConventionModel model, [NotNull] Type type, bool fromDataAnnotation = false) => Check.NotNull((Model)model, nameof(model)).AddIgnored( Check.NotNull(type, nameof(type)), fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); diff --git a/src/EFCore/Extensions/ConventionPropertyExtensions.cs b/src/EFCore/Extensions/ConventionPropertyExtensions.cs index b605bbea169..1e0d4c47892 100644 --- a/src/EFCore/Extensions/ConventionPropertyExtensions.cs +++ b/src/EFCore/Extensions/ConventionPropertyExtensions.cs @@ -90,7 +90,7 @@ public static IEnumerable GetContainingKeys([NotNull] this IConv /// The property. /// The for this property. /// Indicates whether the configuration was specified using a data annotation. - public static CoreTypeMapping SetTypeMapping( + public static CoreTypeMapping? SetTypeMapping( [NotNull] this IConventionProperty property, [NotNull] CoreTypeMapping typeMapping, bool fromDataAnnotation = false) diff --git a/src/EFCore/Extensions/Internal/TypeExtensions.cs b/src/EFCore/Extensions/Internal/TypeExtensions.cs index 86a25eef257..718298f097e 100644 --- a/src/EFCore/Extensions/Internal/TypeExtensions.cs +++ b/src/EFCore/Extensions/Internal/TypeExtensions.cs @@ -26,7 +26,7 @@ public static class TypeExtensions /// 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. /// - public static bool IsDefaultValue([NotNull] this Type type, [CanBeNull] object value) + public static bool IsDefaultValue([NotNull] this Type type, [CanBeNull] object? value) => (value?.Equals(type.GetDefaultValue()) != false); /// diff --git a/src/EFCore/Extensions/MutablePropertyExtensions.cs b/src/EFCore/Extensions/MutablePropertyExtensions.cs index e66291d158f..2c695885c6d 100644 --- a/src/EFCore/Extensions/MutablePropertyExtensions.cs +++ b/src/EFCore/Extensions/MutablePropertyExtensions.cs @@ -210,7 +210,7 @@ public static void SetProviderClrType([NotNull] this IMutableProperty property, public static CoreTypeMapping SetTypeMapping( [NotNull] this IMutableProperty property, [NotNull] CoreTypeMapping typeMapping) - => ((Property)property).SetTypeMapping(typeMapping, ConfigurationSource.Explicit); + => ((Property)property).SetTypeMapping(typeMapping, ConfigurationSource.Explicit)!; /// /// Sets the custom for this property. diff --git a/src/EFCore/Extensions/PropertyBaseExtensions.cs b/src/EFCore/Extensions/PropertyBaseExtensions.cs index 9bc49d90340..761f3a259c2 100644 --- a/src/EFCore/Extensions/PropertyBaseExtensions.cs +++ b/src/EFCore/Extensions/PropertyBaseExtensions.cs @@ -32,9 +32,11 @@ public static class PropertyBaseExtensions /// /// /// The property. - /// If true, then the member to use for query materialization will be returned. + /// + /// If , then the member to use for query materialization will be returned. + /// /// - /// If true, then the member to use for setting the property value will be returned, otherwise + /// If , then the member to use for setting the property value will be returned, otherwise /// the member to use for getting the property value will be returned. /// /// The to use. @@ -45,7 +47,9 @@ public static MemberInfo GetMemberInfo( { if (propertyBase.TryGetMemberInfo(forMaterialization, forSet, out var memberInfo, out var errorMessage)) { - return memberInfo; + // TODO-NULLABLE: memberInfo is null when the property is a collection navigation - but all of the callers seem to + // assume that it's never null. Should TryGetMemberInfo throw for collection navigations instead of returning null? + return memberInfo!; } throw new InvalidOperationException(errorMessage); diff --git a/src/EFCore/Infrastructure/AnnotatableBuilder.cs b/src/EFCore/Infrastructure/AnnotatableBuilder.cs index 9a30771925e..6c54844296a 100644 --- a/src/EFCore/Infrastructure/AnnotatableBuilder.cs +++ b/src/EFCore/Infrastructure/AnnotatableBuilder.cs @@ -7,6 +7,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Metadata.Internal; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Infrastructure { /// @@ -50,15 +52,15 @@ protected AnnotatableBuilder([NotNull] TMetadata metadata, [NotNull] TModelBuild /// The value to be stored in the annotation. /// The configuration source of the annotation to be set. /// The same builder so that multiple calls can be chained. - public virtual AnnotatableBuilder HasAnnotation( + public virtual AnnotatableBuilder? HasAnnotation( [NotNull] string name, - [CanBeNull] object value, + [CanBeNull] object? value, ConfigurationSource configurationSource) => HasAnnotation(name, value, configurationSource, canOverrideSameSource: true); - private AnnotatableBuilder HasAnnotation( + private AnnotatableBuilder? HasAnnotation( string name, - object value, + object? value, ConfigurationSource configurationSource, bool canOverrideSameSource) { @@ -95,9 +97,9 @@ private AnnotatableBuilder HasAnnotation( /// The value to be stored in the annotation. /// The configuration source of the annotation to be set. /// The same builder so that multiple calls can be chained. - public virtual AnnotatableBuilder HasNonNullAnnotation( + public virtual AnnotatableBuilder? HasNonNullAnnotation( [NotNull] string name, - [CanBeNull] object value, + [CanBeNull] object? value, ConfigurationSource configurationSource) => value == null ? RemoveAnnotation(name, configurationSource) @@ -110,7 +112,7 @@ public virtual AnnotatableBuilder HasNonNullAnnotation /// The value to be stored in the annotation. /// The configuration source of the annotation to be set. /// if the annotation can be set, otherwise. - public virtual bool CanSetAnnotation([NotNull] string name, [CanBeNull] object value, ConfigurationSource configurationSource) + public virtual bool CanSetAnnotation([NotNull] string name, [CanBeNull] object? value, ConfigurationSource configurationSource) { var existingAnnotation = Metadata.FindAnnotation(name); return existingAnnotation == null @@ -119,7 +121,7 @@ public virtual bool CanSetAnnotation([NotNull] string name, [CanBeNull] object v private static bool CanSetAnnotationValue( ConventionAnnotation annotation, - object value, + object? value, ConfigurationSource configurationSource, bool canOverrideSameSource) { @@ -140,7 +142,7 @@ private static bool CanSetAnnotationValue( /// The name of the annotation to remove. /// The configuration source of the annotation to be set. /// The same builder so that multiple calls can be chained. - public virtual AnnotatableBuilder RemoveAnnotation( + public virtual AnnotatableBuilder? RemoveAnnotation( [NotNull] string name, ConfigurationSource configurationSource) { @@ -208,25 +210,25 @@ IConventionAnnotatable IConventionAnnotatableBuilder.Metadata /// [DebuggerStepThrough] - IConventionAnnotatableBuilder IConventionAnnotatableBuilder.HasAnnotation(string name, object value, bool fromDataAnnotation) + IConventionAnnotatableBuilder? IConventionAnnotatableBuilder.HasAnnotation(string name, object? value, bool fromDataAnnotation) => HasAnnotation(name, value, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// [DebuggerStepThrough] - IConventionAnnotatableBuilder IConventionAnnotatableBuilder.HasNonNullAnnotation( + IConventionAnnotatableBuilder? IConventionAnnotatableBuilder.HasNonNullAnnotation( string name, - object value, + object? value, bool fromDataAnnotation) => HasNonNullAnnotation(name, value, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// [DebuggerStepThrough] - bool IConventionAnnotatableBuilder.CanSetAnnotation(string name, object value, bool fromDataAnnotation) + bool IConventionAnnotatableBuilder.CanSetAnnotation(string name, object? value, bool fromDataAnnotation) => CanSetAnnotation(name, value, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// [DebuggerStepThrough] - IConventionAnnotatableBuilder IConventionAnnotatableBuilder.HasNoAnnotation(string name, bool fromDataAnnotation) + IConventionAnnotatableBuilder? IConventionAnnotatableBuilder.HasNoAnnotation(string name, bool fromDataAnnotation) => RemoveAnnotation(name, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// diff --git a/src/EFCore/Infrastructure/ConventionAnnotatable.cs b/src/EFCore/Infrastructure/ConventionAnnotatable.cs index 84f89dcb8fe..36e1078d3ab 100644 --- a/src/EFCore/Infrastructure/ConventionAnnotatable.cs +++ b/src/EFCore/Infrastructure/ConventionAnnotatable.cs @@ -127,6 +127,10 @@ private static ConventionAnnotation CreateAnnotation( IConventionAnnotatableBuilder IConventionAnnotatable.Builder => throw new NotSupportedException(); + /// + bool IConventionAnnotatable.IsInModel + => throw new NotSupportedException(); + /// [DebuggerStepThrough] IEnumerable IConventionAnnotatable.GetAnnotations() diff --git a/src/EFCore/Infrastructure/ExpressionExtensions.cs b/src/EFCore/Infrastructure/ExpressionExtensions.cs index 2c27bd260ec..200f57ac51a 100644 --- a/src/EFCore/Infrastructure/ExpressionExtensions.cs +++ b/src/EFCore/Infrastructure/ExpressionExtensions.cs @@ -152,7 +152,7 @@ public static bool TryGetIndexerArguments( /// /// The expression. /// The . - public static PropertyInfo? GetPropertyAccess([NotNull] this LambdaExpression propertyAccessExpression) + public static PropertyInfo GetPropertyAccess([NotNull] this LambdaExpression propertyAccessExpression) => GetInternalMemberAccess(propertyAccessExpression); /// @@ -165,10 +165,10 @@ public static bool TryGetIndexerArguments( /// /// The expression. /// The . - public static MemberInfo? GetMemberAccess([NotNull] this LambdaExpression memberAccessExpression) + public static MemberInfo GetMemberAccess([NotNull] this LambdaExpression memberAccessExpression) => GetInternalMemberAccess(memberAccessExpression); - private static TMemberInfo? GetInternalMemberAccess([NotNull] this LambdaExpression memberAccessExpression) + private static TMemberInfo GetInternalMemberAccess([NotNull] this LambdaExpression memberAccessExpression) where TMemberInfo : MemberInfo { Check.DebugAssert( @@ -202,7 +202,8 @@ public static bool TryGetIndexerArguments( { if (targetMethod.Equals(runtimeProperty.GetMethod)) { - return runtimeProperty as TMemberInfo; + // TODO-NULLABLE: this used to return null if the type was wrong, but none of the call sites handled that + return (TMemberInfo)(object)runtimeProperty; } } } diff --git a/src/EFCore/Infrastructure/IInfrastructure.cs b/src/EFCore/Infrastructure/IInfrastructure.cs index 9fd8cb0bc0a..5abffeb5358 100644 --- a/src/EFCore/Infrastructure/IInfrastructure.cs +++ b/src/EFCore/Infrastructure/IInfrastructure.cs @@ -1,6 +1,8 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +#nullable enable + namespace Microsoft.EntityFrameworkCore.Infrastructure { /// diff --git a/src/EFCore/Metadata/Builders/CollectionCollectionBuilder.cs b/src/EFCore/Metadata/Builders/CollectionCollectionBuilder.cs index 7cb1c592aec..3da8ddd9b07 100644 --- a/src/EFCore/Metadata/Builders/CollectionCollectionBuilder.cs +++ b/src/EFCore/Metadata/Builders/CollectionCollectionBuilder.cs @@ -9,6 +9,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Internal; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Builders { /// @@ -35,10 +37,10 @@ public CollectionCollectionBuilder( [NotNull] IMutableSkipNavigation leftNavigation, [NotNull] IMutableSkipNavigation rightNavigation) { - Check.DebugAssert(((IConventionEntityType)leftEntityType).Builder != null, "Builder is null"); - Check.DebugAssert(((IConventionEntityType)rightEntityType).Builder != null, "Builder is null"); - Check.DebugAssert(((IConventionSkipNavigation)leftNavigation).Builder != null, "Builder is null"); - Check.DebugAssert(((IConventionSkipNavigation)rightNavigation).Builder != null, "Builder is null"); + Check.DebugAssert(((IConventionEntityType)leftEntityType).IsInModel, "Not in model"); + Check.DebugAssert(((IConventionEntityType)rightEntityType).IsInModel, "Not in model"); + Check.DebugAssert(((IConventionSkipNavigation)leftNavigation).IsInModel, "Not in model"); + Check.DebugAssert(((IConventionSkipNavigation)rightNavigation).IsInModel, "Not in model"); LeftEntityType = leftEntityType; RightEntityType = rightEntityType; @@ -120,10 +122,10 @@ public virtual EntityTypeBuilder UsingEntity( Check.NotNull(configureRight, nameof(configureRight)); Check.NotNull(configureLeft, nameof(configureLeft)); - var existingJoinEntityType = (EntityType) + var existingJoinEntityType = (EntityType?) (LeftNavigation.ForeignKey?.DeclaringEntityType ?? RightNavigation.ForeignKey?.DeclaringEntityType); - EntityType newJoinEntityType = null; + EntityType? newJoinEntityType = null; if (existingJoinEntityType != null) { if (existingJoinEntityType.ClrType == joinEntityType @@ -139,7 +141,7 @@ public virtual EntityTypeBuilder UsingEntity( if (newJoinEntityType == null) { - newJoinEntityType = ModelBuilder.Entity(joinEntityType, ConfigurationSource.Explicit).Metadata; + newJoinEntityType = ModelBuilder.Entity(joinEntityType, ConfigurationSource.Explicit)!.Metadata; } var entityTypeBuilder = new EntityTypeBuilder(newJoinEntityType); @@ -171,10 +173,10 @@ public virtual EntityTypeBuilder UsingEntity( Check.NotNull(configureRight, nameof(configureRight)); Check.NotNull(configureLeft, nameof(configureLeft)); - var existingJoinEntityType = (EntityType) + var existingJoinEntityType = (EntityType?) (LeftNavigation.ForeignKey?.DeclaringEntityType ?? RightNavigation.ForeignKey?.DeclaringEntityType); - EntityType newJoinEntityType = null; + EntityType? newJoinEntityType = null; if (existingJoinEntityType != null) { if (existingJoinEntityType.ClrType == joinEntityType @@ -202,7 +204,7 @@ public virtual EntityTypeBuilder UsingEntity( throw new InvalidOperationException(CoreStrings.TypeNotMarkedAsShared(joinEntityType.DisplayName())); } - newJoinEntityType = ModelBuilder.SharedTypeEntity(joinEntityName, joinEntityType, ConfigurationSource.Explicit) + newJoinEntityType = ModelBuilder.SharedTypeEntity(joinEntityName, joinEntityType, ConfigurationSource.Explicit)! .Metadata; } } @@ -282,10 +284,10 @@ protected virtual void Using([NotNull] IMutableForeignKey rightForeignKey, [NotN var leftBuilder = ((SkipNavigation)LeftNavigation).Builder; var rightBuilder = ((SkipNavigation)RightNavigation).Builder; - leftBuilder = leftBuilder.HasInverse(rightBuilder.Metadata, ConfigurationSource.Explicit); + leftBuilder = leftBuilder.HasInverse(rightBuilder.Metadata, ConfigurationSource.Explicit)!; - leftBuilder = leftBuilder.HasForeignKey((ForeignKey)leftForeignKey, ConfigurationSource.Explicit); - rightBuilder = rightBuilder.HasForeignKey((ForeignKey)rightForeignKey, ConfigurationSource.Explicit); + leftBuilder = leftBuilder.HasForeignKey((ForeignKey)leftForeignKey, ConfigurationSource.Explicit)!; + rightBuilder = rightBuilder.HasForeignKey((ForeignKey)rightForeignKey, ConfigurationSource.Explicit)!; LeftNavigation = leftBuilder.Metadata; RightNavigation = rightBuilder.Metadata; @@ -295,13 +297,13 @@ protected virtual void Using([NotNull] IMutableForeignKey rightForeignKey, [NotN /// [EditorBrowsable(EditorBrowsableState.Never)] - public override string ToString() + public override string? ToString() => base.ToString(); /// [EditorBrowsable(EditorBrowsableState.Never)] // ReSharper disable once BaseObjectEqualsIsObjectEquals - public override bool Equals(object obj) + public override bool Equals(object? obj) => base.Equals(obj); /// diff --git a/src/EFCore/Metadata/Builders/CollectionCollectionBuilder`.cs b/src/EFCore/Metadata/Builders/CollectionCollectionBuilder`.cs index 5f1c1f26abe..1bdf3cb7ad1 100644 --- a/src/EFCore/Metadata/Builders/CollectionCollectionBuilder`.cs +++ b/src/EFCore/Metadata/Builders/CollectionCollectionBuilder`.cs @@ -8,6 +8,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Internal; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Builders { /// @@ -76,10 +78,10 @@ public virtual EntityTypeBuilder UsingEntity( Check.NotNull(configureRight, nameof(configureRight)); Check.NotNull(configureLeft, nameof(configureLeft)); - var existingJoinEntityType = (EntityType) + var existingJoinEntityType = (EntityType?) (LeftNavigation.ForeignKey?.DeclaringEntityType ?? RightNavigation.ForeignKey?.DeclaringEntityType); - EntityType joinEntityType = null; + EntityType? joinEntityType = null; if (existingJoinEntityType != null) { if (existingJoinEntityType.ClrType == typeof(TJoinEntity) @@ -95,7 +97,7 @@ public virtual EntityTypeBuilder UsingEntity( if (joinEntityType == null) { - joinEntityType = ModelBuilder.Entity(typeof(TJoinEntity), ConfigurationSource.Explicit).Metadata; + joinEntityType = ModelBuilder.Entity(typeof(TJoinEntity), ConfigurationSource.Explicit)!.Metadata; } var entityTypeBuilder = new EntityTypeBuilder(joinEntityType); @@ -126,10 +128,10 @@ public virtual EntityTypeBuilder UsingEntity( Check.NotNull(configureRight, nameof(configureRight)); Check.NotNull(configureLeft, nameof(configureLeft)); - var existingJoinEntityType = (EntityType) + var existingJoinEntityType = (EntityType?) (LeftNavigation.ForeignKey?.DeclaringEntityType ?? RightNavigation.ForeignKey?.DeclaringEntityType); - EntityType joinEntityType = null; + EntityType? joinEntityType = null; if (existingJoinEntityType != null) { if (existingJoinEntityType.ClrType == typeof(TJoinEntity) @@ -157,7 +159,7 @@ public virtual EntityTypeBuilder UsingEntity( throw new InvalidOperationException(CoreStrings.TypeNotMarkedAsShared(typeof(TJoinEntity).DisplayName())); } - joinEntityType = ModelBuilder.SharedTypeEntity(joinEntityName, typeof(TJoinEntity), ConfigurationSource.Explicit) + joinEntityType = ModelBuilder.SharedTypeEntity(joinEntityName, typeof(TJoinEntity), ConfigurationSource.Explicit)! .Metadata; } } diff --git a/src/EFCore/Metadata/Builders/CollectionNavigationBuilder.cs b/src/EFCore/Metadata/Builders/CollectionNavigationBuilder.cs index 87972f8c7e7..54032b04b71 100644 --- a/src/EFCore/Metadata/Builders/CollectionNavigationBuilder.cs +++ b/src/EFCore/Metadata/Builders/CollectionNavigationBuilder.cs @@ -10,6 +10,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Internal; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Builders { /// @@ -22,7 +24,7 @@ namespace Microsoft.EntityFrameworkCore.Metadata.Builders /// and it is not designed to be directly constructed in your application code. /// /// - public class CollectionNavigationBuilder : IInfrastructure + public class CollectionNavigationBuilder : IInfrastructure { /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -35,14 +37,14 @@ public CollectionNavigationBuilder( [NotNull] IMutableEntityType declaringEntityType, [NotNull] IMutableEntityType relatedEntityType, MemberIdentity navigation, - [CanBeNull] IMutableForeignKey foreignKey, - [CanBeNull] IMutableSkipNavigation skipNavigation) + [CanBeNull] IMutableForeignKey? foreignKey, + [CanBeNull] IMutableSkipNavigation? skipNavigation) { DeclaringEntityType = declaringEntityType; RelatedEntityType = relatedEntityType; CollectionMember = navigation.MemberInfo; CollectionName = navigation.Name; - Builder = ((ForeignKey)foreignKey)?.Builder; + Builder = ((ForeignKey?)foreignKey)?.Builder; SkipNavigation = skipNavigation; } @@ -53,9 +55,9 @@ public CollectionNavigationBuilder( /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [EntityFrameworkInternal] - protected virtual InternalForeignKeyBuilder Builder { get; private set; } + protected virtual InternalForeignKeyBuilder? Builder { get; private set; } - private IMutableSkipNavigation SkipNavigation { get; set; } + private IMutableSkipNavigation? SkipNavigation { get; set; } /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -64,7 +66,7 @@ public CollectionNavigationBuilder( /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [EntityFrameworkInternal] - protected virtual string CollectionName { get; } + protected virtual string? CollectionName { get; } /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -73,7 +75,7 @@ public CollectionNavigationBuilder( /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [EntityFrameworkInternal] - protected virtual MemberInfo CollectionMember { get; } + protected virtual MemberInfo? CollectionMember { get; } /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -102,7 +104,7 @@ public CollectionNavigationBuilder( /// not directly exposed in the public API surface. /// /// - IConventionForeignKeyBuilder IInfrastructure.Instance + IConventionForeignKeyBuilder? IInfrastructure.Instance => Builder; /// @@ -120,7 +122,7 @@ IConventionForeignKeyBuilder IInfrastructure.Insta /// If null or not specified, then there is no navigation property on the other end of the relationship. /// /// An object to further configure the relationship. - public virtual ReferenceCollectionBuilder WithOne([CanBeNull] string navigationName = null) + public virtual ReferenceCollectionBuilder WithOne([CanBeNull] string? navigationName = null) => new( DeclaringEntityType, RelatedEntityType, @@ -134,7 +136,7 @@ public virtual ReferenceCollectionBuilder WithOne([CanBeNull] string navigationN /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [EntityFrameworkInternal] - protected virtual InternalForeignKeyBuilder WithOneBuilder([CanBeNull] string navigationName) + protected virtual InternalForeignKeyBuilder WithOneBuilder([CanBeNull] string? navigationName) => WithOneBuilder(MemberIdentity.Create(navigationName)); /// @@ -145,7 +147,7 @@ protected virtual InternalForeignKeyBuilder WithOneBuilder([CanBeNull] string na /// [EntityFrameworkInternal] protected virtual InternalForeignKeyBuilder WithOneBuilder( - [CanBeNull] MemberInfo navigationMemberInfo) + [CanBeNull] MemberInfo? navigationMemberInfo) => WithOneBuilder(MemberIdentity.Create(navigationMemberInfo)); private InternalForeignKeyBuilder WithOneBuilder(MemberIdentity reference) @@ -191,7 +193,7 @@ private InternalForeignKeyBuilder WithOneBuilder(MemberIdentity reference) SkipNavigation = null; } - var foreignKey = Builder.Metadata; + var foreignKey = Builder!.Metadata; var referenceName = reference.Name; if (referenceName != null && foreignKey.DependentToPrincipal != null @@ -205,11 +207,11 @@ private InternalForeignKeyBuilder WithOneBuilder(MemberIdentity reference) ? Builder.HasNavigations( reference.Name, CollectionName, (EntityType)DeclaringEntityType, (EntityType)RelatedEntityType, - ConfigurationSource.Explicit) + ConfigurationSource.Explicit)! : Builder.HasNavigations( reference.MemberInfo, CollectionMember, (EntityType)DeclaringEntityType, (EntityType)RelatedEntityType, - ConfigurationSource.Explicit); + ConfigurationSource.Explicit)!; } /// @@ -232,7 +234,7 @@ public virtual CollectionCollectionBuilder WithMany([NotNull] string navigationN Builder.Metadata.DeclaringEntityType.DisplayName())); } - var leftName = Builder?.Metadata.PrincipalToDependent.Name; + var leftName = Builder?.Metadata.PrincipalToDependent!.Name; var collectionCollectionBuilder = new CollectionCollectionBuilder( RelatedEntityType, @@ -294,7 +296,7 @@ protected virtual IMutableSkipNavigation WithLeftManyNavigation([NotNull] string return SkipNavigation; } - var foreignKey = Builder.Metadata; + var foreignKey = Builder!.Metadata; var navigationMember = foreignKey.PrincipalToDependent.CreateMemberIdentity(); if (foreignKey.GetDependentToPrincipalConfigurationSource() == ConfigurationSource.Explicit) { @@ -309,7 +311,7 @@ protected virtual IMutableSkipNavigation WithLeftManyNavigation([NotNull] string return ((EntityType)DeclaringEntityType).Builder.HasSkipNavigation( navigationMember, (EntityType)RelatedEntityType, - ConfigurationSource.Explicit).Metadata; + ConfigurationSource.Explicit)!.Metadata; } } @@ -320,7 +322,7 @@ protected virtual IMutableSkipNavigation WithLeftManyNavigation([NotNull] string /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [EntityFrameworkInternal] - protected virtual IMutableSkipNavigation WithRightManyNavigation([NotNull] string navigationName, [NotNull] string inverseName) + protected virtual IMutableSkipNavigation WithRightManyNavigation([NotNull] string navigationName, [CanBeNull] string? inverseName) => WithRightManyNavigation(MemberIdentity.Create(navigationName), inverseName); /// @@ -332,27 +334,28 @@ protected virtual IMutableSkipNavigation WithRightManyNavigation([NotNull] strin [EntityFrameworkInternal] protected virtual IMutableSkipNavigation WithRightManyNavigation( [NotNull] MemberInfo navigationMemberInfo, - [NotNull] string inverseName) + [CanBeNull] string? inverseName) => WithRightManyNavigation(MemberIdentity.Create(navigationMemberInfo), inverseName); - private IMutableSkipNavigation WithRightManyNavigation(MemberIdentity navigationMember, [NotNull] string inverseName) + private IMutableSkipNavigation WithRightManyNavigation(MemberIdentity navigationMember, [CanBeNull] string? inverseName) { Check.DebugAssert(Builder == null, "Expected no associated foreign key at this point"); + Check.DebugAssert(navigationMember.Name is not null, $"{nameof(navigationMember.Name)} is null"); var navigationName = navigationMember.Name; var conflictingNavigation = RelatedEntityType.FindNavigation(navigationName) as IConventionNavigation; - var foreignKey = (ForeignKey)conflictingNavigation?.ForeignKey; + var foreignKey = (ForeignKey?)conflictingNavigation?.ForeignKey; if (conflictingNavigation?.GetConfigurationSource() == ConfigurationSource.Explicit) { InternalForeignKeyBuilder.ThrowForConflictingNavigation( - foreignKey, DeclaringEntityType, RelatedEntityType, inverseName, navigationName); + foreignKey!, DeclaringEntityType, RelatedEntityType, inverseName, navigationName); } using (((EntityType)RelatedEntityType).Model.DelayConventions()) { if (conflictingNavigation != null) { - foreignKey.DeclaringEntityType.Builder.HasNoRelationship(foreignKey, ConfigurationSource.Explicit); + foreignKey!.DeclaringEntityType.Builder.HasNoRelationship(foreignKey, ConfigurationSource.Explicit); } else { @@ -366,7 +369,7 @@ private IMutableSkipNavigation WithRightManyNavigation(MemberIdentity navigation return ((EntityType)RelatedEntityType).Builder.HasSkipNavigation( navigationMember, (EntityType)DeclaringEntityType, - ConfigurationSource.Explicit).Metadata; + ConfigurationSource.Explicit)!.Metadata; } } @@ -377,7 +380,7 @@ private IMutableSkipNavigation WithRightManyNavigation(MemberIdentity navigation /// /// A string that represents the current object. [EditorBrowsable(EditorBrowsableState.Never)] - public override string ToString() + public override string? ToString() => base.ToString(); /// @@ -387,7 +390,7 @@ public override string ToString() /// if the specified object is equal to the current object; otherwise, . [EditorBrowsable(EditorBrowsableState.Never)] // ReSharper disable once BaseObjectEqualsIsObjectEquals - public override bool Equals(object obj) + public override bool Equals(object? obj) => base.Equals(obj); /// diff --git a/src/EFCore/Metadata/Builders/CollectionNavigationBuilder`.cs b/src/EFCore/Metadata/Builders/CollectionNavigationBuilder`.cs index 53d8a370c3a..c6e318fb2c8 100644 --- a/src/EFCore/Metadata/Builders/CollectionNavigationBuilder`.cs +++ b/src/EFCore/Metadata/Builders/CollectionNavigationBuilder`.cs @@ -9,6 +9,8 @@ using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Builders { /// @@ -38,8 +40,8 @@ public CollectionNavigationBuilder( [NotNull] IMutableEntityType declaringEntityType, [NotNull] IMutableEntityType relatedEntityType, MemberIdentity navigation, - [CanBeNull] IMutableForeignKey foreignKey, - [CanBeNull] IMutableSkipNavigation skipNavigation) + [CanBeNull] IMutableForeignKey? foreignKey, + [CanBeNull] IMutableSkipNavigation? skipNavigation) : base(declaringEntityType, relatedEntityType, navigation, foreignKey, skipNavigation) { } @@ -53,7 +55,7 @@ public CollectionNavigationBuilder( /// /// An object to further configure the relationship. public new virtual ReferenceCollectionBuilder WithOne( - [CanBeNull] string navigationName = null) + [CanBeNull] string? navigationName = null) { return new( DeclaringEntityType, @@ -79,7 +81,7 @@ public CollectionNavigationBuilder( /// /// An object to further configure the relationship. public virtual ReferenceCollectionBuilder WithOne( - [CanBeNull] Expression> navigationExpression) + [CanBeNull] Expression>? navigationExpression) => new( DeclaringEntityType, RelatedEntityType, @@ -94,7 +96,7 @@ public virtual ReferenceCollectionBuilder WithOne( /// An object to further configure the relationship. public new virtual CollectionCollectionBuilder WithMany([NotNull] string navigationName) { - var leftName = Builder?.Metadata.PrincipalToDependent.Name; + var leftName = Builder?.Metadata.PrincipalToDependent!.Name; var collectionCollectionBuilder = new CollectionCollectionBuilder( RelatedEntityType, @@ -130,7 +132,7 @@ public virtual CollectionCollectionBuilder WithMany( Builder.Metadata.DeclaringEntityType.DisplayName())); } - var leftName = Builder?.Metadata.PrincipalToDependent.Name; + var leftName = Builder?.Metadata.PrincipalToDependent!.Name; var collectionCollectionBuilder = new CollectionCollectionBuilder( RelatedEntityType, diff --git a/src/EFCore/Metadata/Builders/DataBuilder.cs b/src/EFCore/Metadata/Builders/DataBuilder.cs index 76fd5b152ba..8bfc1e64cac 100644 --- a/src/EFCore/Metadata/Builders/DataBuilder.cs +++ b/src/EFCore/Metadata/Builders/DataBuilder.cs @@ -4,6 +4,8 @@ using System.ComponentModel; using Microsoft.EntityFrameworkCore.Infrastructure; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Builders { /// @@ -29,7 +31,7 @@ public DataBuilder() /// /// A string that represents the current object. [EditorBrowsable(EditorBrowsableState.Never)] - public override string ToString() + public override string? ToString() => base.ToString(); /// @@ -38,7 +40,7 @@ public override string ToString() /// The object to compare with the current object. /// if the specified object is equal to the current object; otherwise, . [EditorBrowsable(EditorBrowsableState.Never)] - public override bool Equals(object obj) + public override bool Equals(object? obj) => base.Equals(obj); /// diff --git a/src/EFCore/Metadata/Builders/DataBuilder`.cs b/src/EFCore/Metadata/Builders/DataBuilder`.cs index c13ec5deff9..f99ad354aeb 100644 --- a/src/EFCore/Metadata/Builders/DataBuilder`.cs +++ b/src/EFCore/Metadata/Builders/DataBuilder`.cs @@ -3,6 +3,8 @@ using Microsoft.EntityFrameworkCore.Infrastructure; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Builders { /// diff --git a/src/EFCore/Metadata/Builders/DiscriminatorBuilder.cs b/src/EFCore/Metadata/Builders/DiscriminatorBuilder.cs index 784d50b7e5b..432b6d92c6d 100644 --- a/src/EFCore/Metadata/Builders/DiscriminatorBuilder.cs +++ b/src/EFCore/Metadata/Builders/DiscriminatorBuilder.cs @@ -8,6 +8,8 @@ using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata.Internal; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Builders { /// @@ -41,10 +43,10 @@ public DiscriminatorBuilder([NotNull] IMutableEntityType entityType) /// /// The value indicating if this discriminator mapping is complete. /// The same builder so that multiple calls can be chained. - public virtual DiscriminatorBuilder IsComplete(bool complete = true) + public virtual DiscriminatorBuilder? IsComplete(bool complete = true) => IsComplete(complete, ConfigurationSource.Explicit); - private DiscriminatorBuilder IsComplete(bool complete, ConfigurationSource configurationSource) + private DiscriminatorBuilder? IsComplete(bool complete, ConfigurationSource configurationSource) { if (configurationSource == ConfigurationSource.Explicit) { @@ -70,7 +72,7 @@ private DiscriminatorBuilder IsComplete(bool complete, ConfigurationSource confi /// /// The discriminator value. /// The same builder so that multiple calls can be chained. - public virtual DiscriminatorBuilder HasValue([CanBeNull] object value) + public virtual DiscriminatorBuilder? HasValue([CanBeNull] object? value) => HasValue(EntityTypeBuilder, value, ConfigurationSource.Explicit); /// @@ -79,7 +81,7 @@ public virtual DiscriminatorBuilder HasValue([CanBeNull] object value) /// The entity type for which a discriminator value is being set. /// The discriminator value. /// The same builder so that multiple calls can be chained. - public virtual DiscriminatorBuilder HasValue([CanBeNull] object value) + public virtual DiscriminatorBuilder? HasValue([CanBeNull] object? value) => HasValue(typeof(TEntity), value); /// @@ -88,7 +90,7 @@ public virtual DiscriminatorBuilder HasValue([CanBeNull] object value) /// The entity type for which a discriminator value is being set. /// The discriminator value. /// The same builder so that multiple calls can be chained. - public virtual DiscriminatorBuilder HasValue([NotNull] Type entityType, [CanBeNull] object value) + public virtual DiscriminatorBuilder? HasValue([NotNull] Type entityType, [CanBeNull] object? value) { var entityTypeBuilder = EntityTypeBuilder.ModelBuilder.Entity( entityType, ConfigurationSource.Explicit, shouldBeOwned: null); @@ -102,7 +104,7 @@ public virtual DiscriminatorBuilder HasValue([NotNull] Type entityType, [CanBeNu /// The name of the entity type for which a discriminator value is being set. /// The discriminator value. /// The same builder so that multiple calls can be chained. - public virtual DiscriminatorBuilder HasValue([NotNull] string entityTypeName, [CanBeNull] object value) + public virtual DiscriminatorBuilder? HasValue([NotNull] string entityTypeName, [CanBeNull] object? value) { var entityTypeBuilder = EntityTypeBuilder.ModelBuilder.Entity( entityTypeName, ConfigurationSource.Explicit, shouldBeOwned: null); @@ -110,9 +112,9 @@ public virtual DiscriminatorBuilder HasValue([NotNull] string entityTypeName, [C return HasValue(entityTypeBuilder, value, ConfigurationSource.Explicit); } - private DiscriminatorBuilder HasValue( - InternalEntityTypeBuilder entityTypeBuilder, - object value, + private DiscriminatorBuilder? HasValue( + InternalEntityTypeBuilder? entityTypeBuilder, + object? value, ConfigurationSource configurationSource) { if (entityTypeBuilder == null) @@ -151,7 +153,7 @@ private DiscriminatorBuilder HasValue( } /// - IConventionDiscriminatorBuilder IConventionDiscriminatorBuilder.IsComplete(bool complete, bool fromDataAnnotation) + IConventionDiscriminatorBuilder? IConventionDiscriminatorBuilder.IsComplete(bool complete, bool fromDataAnnotation) => IsComplete(complete, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// @@ -160,26 +162,26 @@ bool IConventionDiscriminatorBuilder.CanSetIsComplete(bool complete, bool fromDa CoreAnnotationNames.DiscriminatorMappingComplete, fromDataAnnotation); /// - IConventionDiscriminatorBuilder IConventionDiscriminatorBuilder.HasValue(object value, bool fromDataAnnotation) + IConventionDiscriminatorBuilder? IConventionDiscriminatorBuilder.HasValue(object? value, bool fromDataAnnotation) => HasValue( EntityTypeBuilder, value, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// - IConventionDiscriminatorBuilder IConventionDiscriminatorBuilder.HasValue( + IConventionDiscriminatorBuilder? IConventionDiscriminatorBuilder.HasValue( IConventionEntityType entityType, - object value, + object? value, bool fromDataAnnotation) => HasValue( - (InternalEntityTypeBuilder)entityType.Builder, value, + (InternalEntityTypeBuilder?)entityType.Builder, value, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// - bool IConventionDiscriminatorBuilder.CanSetValue(object value, bool fromDataAnnotation) + bool IConventionDiscriminatorBuilder.CanSetValue(object? value, bool fromDataAnnotation) => ((IConventionDiscriminatorBuilder)this).CanSetValue(EntityTypeBuilder.Metadata, value, fromDataAnnotation); /// - bool IConventionDiscriminatorBuilder.CanSetValue(IConventionEntityType entityType, object value, bool fromDataAnnotation) + bool IConventionDiscriminatorBuilder.CanSetValue(IConventionEntityType entityType, object? value, bool fromDataAnnotation) { var baseEntityTypeBuilder = EntityTypeBuilder; if (!baseEntityTypeBuilder.Metadata.IsAssignableFrom(entityType) @@ -198,7 +200,7 @@ bool IConventionDiscriminatorBuilder.CanSetValue(IConventionEntityType entityTyp /// /// A string that represents the current object. [EditorBrowsable(EditorBrowsableState.Never)] - public override string ToString() + public override string? ToString() => base.ToString(); /// @@ -208,7 +210,7 @@ public override string ToString() /// if the specified object is equal to the current object; otherwise, . [EditorBrowsable(EditorBrowsableState.Never)] // ReSharper disable once BaseObjectEqualsIsObjectEquals - public override bool Equals(object obj) + public override bool Equals(object? obj) => base.Equals(obj); /// diff --git a/src/EFCore/Metadata/Builders/DiscriminatorBuilder`.cs b/src/EFCore/Metadata/Builders/DiscriminatorBuilder`.cs index 1ec429c7036..9c16419400c 100644 --- a/src/EFCore/Metadata/Builders/DiscriminatorBuilder`.cs +++ b/src/EFCore/Metadata/Builders/DiscriminatorBuilder`.cs @@ -6,6 +6,8 @@ using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Builders { /// @@ -35,7 +37,7 @@ public DiscriminatorBuilder([NotNull] DiscriminatorBuilder builder) /// /// The value indicating if this discriminator mapping is complete. /// The same builder so that multiple calls can be chained. - public virtual DiscriminatorBuilder IsComplete(bool complete = true) + public virtual DiscriminatorBuilder? IsComplete(bool complete = true) { var builder = Builder.IsComplete(complete); return builder == null ? null : new DiscriminatorBuilder(builder); @@ -46,7 +48,7 @@ public virtual DiscriminatorBuilder IsComplete(bool complete = t /// /// The discriminator value. /// The same builder so that multiple calls can be chained. - public virtual DiscriminatorBuilder HasValue([CanBeNull] TDiscriminator value) + public virtual DiscriminatorBuilder? HasValue([CanBeNull] TDiscriminator? value) { var builder = Builder.HasValue(value); return builder == null ? null : new DiscriminatorBuilder(builder); @@ -58,7 +60,7 @@ public virtual DiscriminatorBuilder HasValue([CanBeNull] TDiscri /// The entity type for which a discriminator value is being set. /// The discriminator value. /// The same builder so that multiple calls can be chained. - public virtual DiscriminatorBuilder HasValue([CanBeNull] TDiscriminator value) + public virtual DiscriminatorBuilder? HasValue([CanBeNull] TDiscriminator? value) => HasValue(typeof(TEntity), value); /// @@ -67,7 +69,7 @@ public virtual DiscriminatorBuilder HasValue([CanBeNull /// The entity type for which a discriminator value is being set. /// The discriminator value. /// The same builder so that multiple calls can be chained. - public virtual DiscriminatorBuilder HasValue([NotNull] Type entityType, [CanBeNull] TDiscriminator value) + public virtual DiscriminatorBuilder? HasValue([NotNull] Type entityType, [CanBeNull] TDiscriminator? value) { var builder = Builder.HasValue(entityType, value); return builder == null ? null : new DiscriminatorBuilder(builder); @@ -79,7 +81,7 @@ public virtual DiscriminatorBuilder HasValue([NotNull] Type enti /// The name of the entity type for which a discriminator value is being set. /// The discriminator value. /// The same builder so that multiple calls can be chained. - public virtual DiscriminatorBuilder HasValue([NotNull] string entityTypeName, [CanBeNull] TDiscriminator value) + public virtual DiscriminatorBuilder? HasValue([NotNull] string entityTypeName, [CanBeNull] TDiscriminator? value) { var builder = Builder.HasValue(entityTypeName, value); return builder == null ? null : new DiscriminatorBuilder(builder); diff --git a/src/EFCore/Metadata/Builders/EntityTypeBuilder.cs b/src/EFCore/Metadata/Builders/EntityTypeBuilder.cs index cae74e901c8..5a9b79c70e0 100644 --- a/src/EFCore/Metadata/Builders/EntityTypeBuilder.cs +++ b/src/EFCore/Metadata/Builders/EntityTypeBuilder.cs @@ -14,6 +14,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Internal; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Builders { /// @@ -75,16 +77,16 @@ public virtual EntityTypeBuilder HasAnnotation([NotNull] string annotation, [Not /// /// The name of the base type or to indicate no base type. /// The same builder instance so that multiple configuration calls can be chained. - public virtual EntityTypeBuilder HasBaseType([CanBeNull] string name) - => new(Builder.HasBaseType(name, ConfigurationSource.Explicit).Metadata); + public virtual EntityTypeBuilder HasBaseType([CanBeNull] string? name) + => new(Builder.HasBaseType(name, ConfigurationSource.Explicit)!.Metadata); /// /// Sets the base type of this entity type in an inheritance hierarchy. /// /// The base type or to indicate no base type. /// The same builder instance so that multiple configuration calls can be chained. - public virtual EntityTypeBuilder HasBaseType([CanBeNull] Type entityType) - => new(Builder.HasBaseType(entityType, ConfigurationSource.Explicit).Metadata); + public virtual EntityTypeBuilder HasBaseType([CanBeNull] Type? entityType) + => new(Builder.HasBaseType(entityType, ConfigurationSource.Explicit)!.Metadata); /// /// Sets the properties that make up the primary key for this entity type. @@ -92,7 +94,7 @@ public virtual EntityTypeBuilder HasBaseType([CanBeNull] Type entityType) /// The names of the properties that make up the primary key. /// An object that can be used to configure the primary key. public virtual KeyBuilder HasKey([NotNull] params string[] propertyNames) - => new(Builder.PrimaryKey(Check.NotEmpty(propertyNames, nameof(propertyNames)), ConfigurationSource.Explicit).Metadata); + => new(Builder.PrimaryKey(Check.NotEmpty(propertyNames, nameof(propertyNames)), ConfigurationSource.Explicit)!.Metadata); /// /// Creates an alternate key in the model for this entity type if one does not already exist over the specified @@ -102,7 +104,7 @@ public virtual KeyBuilder HasKey([NotNull] params string[] propertyNames) /// The names of the properties that make up the key. /// An object that can be used to configure the key. public virtual KeyBuilder HasAlternateKey([NotNull] params string[] propertyNames) - => new(Builder.HasKey(Check.NotEmpty(propertyNames, nameof(propertyNames)), ConfigurationSource.Explicit).Metadata); + => new(Builder.HasKey(Check.NotEmpty(propertyNames, nameof(propertyNames)), ConfigurationSource.Explicit)!.Metadata); /// /// Configures the entity type to have no keys. It will only be usable for queries. @@ -131,7 +133,7 @@ public virtual PropertyBuilder Property([NotNull] string propertyName) => new( Builder.Property( Check.NotEmpty(propertyName, nameof(propertyName)), - ConfigurationSource.Explicit).Metadata); + ConfigurationSource.Explicit)!.Metadata); /// /// @@ -153,7 +155,7 @@ public virtual PropertyBuilder Property([NotNull] string p => new( Builder.Property( typeof(TProperty), - Check.NotEmpty(propertyName, nameof(propertyName)), ConfigurationSource.Explicit).Metadata); + Check.NotEmpty(propertyName, nameof(propertyName)), ConfigurationSource.Explicit)!.Metadata); /// /// @@ -175,7 +177,7 @@ public virtual PropertyBuilder Property([NotNull] Type propertyType, [NotNull] s => new( Builder.Property( Check.NotNull(propertyType, nameof(propertyType)), - Check.NotEmpty(propertyName, nameof(propertyName)), ConfigurationSource.Explicit).Metadata); + Check.NotEmpty(propertyName, nameof(propertyName)), ConfigurationSource.Explicit)!.Metadata); /// /// @@ -195,7 +197,7 @@ public virtual PropertyBuilder IndexerProperty([NotNull] s => new( Builder.IndexerProperty( typeof(TProperty), - Check.NotEmpty(propertyName, nameof(propertyName)), ConfigurationSource.Explicit).Metadata); + Check.NotEmpty(propertyName, nameof(propertyName)), ConfigurationSource.Explicit)!.Metadata); /// /// @@ -215,7 +217,7 @@ public virtual PropertyBuilder IndexerProperty([NotNull] Type propertyType, [Not => new( Builder.IndexerProperty( Check.NotNull(propertyType, nameof(propertyType)), - Check.NotEmpty(propertyName, nameof(propertyName)), ConfigurationSource.Explicit).Metadata); + Check.NotEmpty(propertyName, nameof(propertyName)), ConfigurationSource.Explicit)!.Metadata); /// /// @@ -248,7 +250,7 @@ public virtual EntityTypeBuilder Ignore([NotNull] string propertyName) /// /// The LINQ predicate expression. /// The same builder instance so that multiple configuration calls can be chained. - public virtual EntityTypeBuilder HasQueryFilter([CanBeNull] LambdaExpression filter) + public virtual EntityTypeBuilder HasQueryFilter([CanBeNull] LambdaExpression? filter) { Builder.HasQueryFilter(filter, ConfigurationSource.Explicit); @@ -264,7 +266,7 @@ public virtual EntityTypeBuilder HasQueryFilter([CanBeNull] LambdaExpression fil /// The names of the properties that make up the index. /// An object that can be used to configure the index. public virtual IndexBuilder HasIndex([NotNull] params string[] propertyNames) - => new(Builder.HasIndex(Check.NotEmpty(propertyNames, nameof(propertyNames)), ConfigurationSource.Explicit).Metadata); + => new(Builder.HasIndex(Check.NotEmpty(propertyNames, nameof(propertyNames)), ConfigurationSource.Explicit)!.Metadata); /// /// Configures an index on the specified properties and with the given name. @@ -281,7 +283,7 @@ public virtual IndexBuilder HasIndex( Builder.HasIndex( Check.NotEmpty(propertyNames, nameof(propertyNames)), Check.NotEmpty(name, nameof(name)), - ConfigurationSource.Explicit).Metadata); + ConfigurationSource.Explicit)!.Metadata); /// /// @@ -489,9 +491,9 @@ private OwnedNavigationBuilder OwnsOneBuilder(in TypeIdentity ownedType, string using (var batch = Builder.Metadata.Model.DelayConventions()) { var navigationMember = new MemberIdentity(navigationName); - var relationship = Builder.HasOwnership(ownedType, navigationMember, ConfigurationSource.Explicit); + var relationship = Builder.HasOwnership(ownedType, navigationMember, ConfigurationSource.Explicit)!; relationship.IsUnique(true, ConfigurationSource.Explicit); - foreignKey = (IMutableForeignKey)batch.Run(relationship.Metadata); + foreignKey = (IMutableForeignKey)batch.Run(relationship.Metadata)!; } return new OwnedNavigationBuilder(foreignKey); @@ -703,9 +705,9 @@ private OwnedNavigationBuilder OwnsManyBuilder(in TypeIdentity ownedType, string using (var batch = Builder.Metadata.Model.DelayConventions()) { var navigationMember = new MemberIdentity(navigationName); - var relationship = Builder.HasOwnership(ownedType, navigationMember, ConfigurationSource.Explicit); + var relationship = Builder.HasOwnership(ownedType, navigationMember, ConfigurationSource.Explicit)!; relationship.IsUnique(false, ConfigurationSource.Explicit); - foreignKey = (IMutableForeignKey)batch.Run(relationship.Metadata); + foreignKey = (IMutableForeignKey)batch.Run(relationship.Metadata)!; } return new OwnedNavigationBuilder(foreignKey); @@ -738,7 +740,7 @@ private OwnedNavigationBuilder OwnsManyBuilder(in TypeIdentity ownedType, string /// An object that can be used to configure the relationship. public virtual ReferenceNavigationBuilder HasOne( [NotNull] string relatedTypeName, - [CanBeNull] string navigationName) + [CanBeNull] string? navigationName) { Check.NotEmpty(relatedTypeName, nameof(relatedTypeName)); Check.NullButNotEmpty(navigationName, nameof(navigationName)); @@ -781,7 +783,7 @@ public virtual ReferenceNavigationBuilder HasOne( /// An object that can be used to configure the relationship. public virtual ReferenceNavigationBuilder HasOne( [NotNull] Type relatedType, - [CanBeNull] string navigationName = null) + [CanBeNull] string? navigationName = null) { Check.NotNull(relatedType, nameof(relatedType)); Check.NullButNotEmpty(navigationName, nameof(navigationName)); @@ -840,13 +842,13 @@ protected virtual ForeignKey HasOneBuilder( { foreignKey = Builder.HasRelationship( relatedEntityType, navigationId.MemberInfo, ConfigurationSource.Explicit, - targetIsPrincipal: Builder.Metadata == relatedEntityType ? true : (bool?)null).Metadata; + targetIsPrincipal: Builder.Metadata == relatedEntityType ? true : (bool?)null)!.Metadata; } else { foreignKey = Builder.HasRelationship( relatedEntityType, navigationId.Name, ConfigurationSource.Explicit, - targetIsPrincipal: Builder.Metadata == relatedEntityType ? true : (bool?)null).Metadata; + targetIsPrincipal: Builder.Metadata == relatedEntityType ? true : (bool?)null)!.Metadata; } return foreignKey; @@ -873,7 +875,7 @@ protected virtual ForeignKey HasOneBuilder( /// An object that can be used to configure the relationship. public virtual CollectionNavigationBuilder HasMany( [NotNull] string relatedTypeName, - [CanBeNull] string navigationName) + [CanBeNull] string? navigationName) { Check.NotEmpty(relatedTypeName, nameof(relatedTypeName)); Check.NullButNotEmpty(navigationName, nameof(navigationName)); @@ -906,7 +908,7 @@ public virtual CollectionNavigationBuilder HasMany([NotNull] string navigationNa if (Metadata.ClrType == null) { - return HasMany(navigationName, (string)null); + return HasMany(navigationName, (string?)null); } var memberType = Metadata.GetNavigationMemberInfo(navigationName).GetMemberType(); @@ -951,7 +953,7 @@ public virtual CollectionNavigationBuilder HasMany([NotNull] string navigationNa /// An object that can be used to configure the relationship. public virtual CollectionNavigationBuilder HasMany( [NotNull] Type relatedType, - [CanBeNull] string navigationName = null) + [CanBeNull] string? navigationName = null) { Check.NotNull(relatedType, nameof(relatedType)); Check.NullButNotEmpty(navigationName, nameof(navigationName)); @@ -962,7 +964,7 @@ public virtual CollectionNavigationBuilder HasMany( } private CollectionNavigationBuilder HasMany( - string navigationName, + string? navigationName, EntityType relatedEntityType) { // Note: delay setting ConfigurationSource of skip navigation (if it exists). @@ -971,18 +973,18 @@ private CollectionNavigationBuilder HasMany( // we want to be able to override it later. var skipNavigation = navigationName != null ? Builder.Metadata.FindSkipNavigation(navigationName) : null; - InternalForeignKeyBuilder relationship = null; + InternalForeignKeyBuilder? relationship = null; if (skipNavigation == null) { relationship = Builder - .HasRelationship(relatedEntityType, navigationName, ConfigurationSource.Explicit, targetIsPrincipal: false) + .HasRelationship(relatedEntityType, navigationName, ConfigurationSource.Explicit, targetIsPrincipal: false)! .IsUnique(false, ConfigurationSource.Explicit); } return new CollectionNavigationBuilder( Builder.Metadata, relatedEntityType, - new MemberIdentity(navigationName), + new MemberIdentity(navigationName!), relationship?.Metadata, skipNavigation); } @@ -994,11 +996,11 @@ private CollectionNavigationBuilder HasMany( /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [EntityFrameworkInternal] - protected virtual EntityType FindRelatedEntityType([NotNull] string relatedTypeName, [CanBeNull] string navigationName) + protected virtual EntityType FindRelatedEntityType([NotNull] string relatedTypeName, [CanBeNull] string? navigationName) => (navigationName == null ? null : Builder.ModelBuilder.Metadata.FindEntityType(relatedTypeName, navigationName, Builder.Metadata)) - ?? Builder.ModelBuilder.Entity(relatedTypeName, ConfigurationSource.Explicit).Metadata; + ?? Builder.ModelBuilder.Entity(relatedTypeName, ConfigurationSource.Explicit)!.Metadata; /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -1007,11 +1009,11 @@ protected virtual EntityType FindRelatedEntityType([NotNull] string relatedTypeN /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [EntityFrameworkInternal] - protected virtual EntityType FindRelatedEntityType([NotNull] Type relatedType, [CanBeNull] string navigationName) + protected virtual EntityType FindRelatedEntityType([NotNull] Type relatedType, [CanBeNull] string? navigationName) => (navigationName == null || !Builder.ModelBuilder.Metadata.IsShared(relatedType) ? null : Builder.ModelBuilder.Metadata.FindEntityType(relatedType, navigationName, Builder.Metadata)) - ?? Builder.ModelBuilder.Entity(relatedType, ConfigurationSource.Explicit).Metadata; + ?? Builder.ModelBuilder.Entity(relatedType, ConfigurationSource.Explicit)!.Metadata; /// /// Configures the to be used for this entity type. @@ -1081,7 +1083,7 @@ public virtual DataBuilder HasData([NotNull] IEnumerable data) /// /// A builder that allows the discriminator property to be configured. public virtual DiscriminatorBuilder HasDiscriminator() - => Builder.HasDiscriminator(ConfigurationSource.Explicit); + => Builder.HasDiscriminator(ConfigurationSource.Explicit)!; /// /// Configures the discriminator property used to identify the entity type in the store. @@ -1096,7 +1098,7 @@ public virtual DiscriminatorBuilder HasDiscriminator( Check.NotEmpty(name, nameof(name)); Check.NotNull(type, nameof(type)); - return Builder.HasDiscriminator(name, type, ConfigurationSource.Explicit); + return Builder.HasDiscriminator(name, type, ConfigurationSource.Explicit)!; } /// @@ -1110,7 +1112,7 @@ public virtual DiscriminatorBuilder HasDiscriminator( - Builder.HasDiscriminator(name, typeof(TDiscriminator), ConfigurationSource.Explicit)); + Builder.HasDiscriminator(name, typeof(TDiscriminator), ConfigurationSource.Explicit)!); } /// @@ -1130,7 +1132,7 @@ public virtual EntityTypeBuilder HasNoDiscriminator() /// /// A string that represents the current object. [EditorBrowsable(EditorBrowsableState.Never)] - public override string ToString() + public override string? ToString() => base.ToString(); /// @@ -1140,7 +1142,7 @@ public override string ToString() /// if the specified object is equal to the current object; otherwise, . [EditorBrowsable(EditorBrowsableState.Never)] // ReSharper disable once BaseObjectEqualsIsObjectEquals - public override bool Equals(object obj) + public override bool Equals(object? obj) => base.Equals(obj); /// diff --git a/src/EFCore/Metadata/Builders/EntityTypeBuilder`.cs b/src/EFCore/Metadata/Builders/EntityTypeBuilder`.cs index 3dad17f5ada..75f6cd97a73 100644 --- a/src/EFCore/Metadata/Builders/EntityTypeBuilder`.cs +++ b/src/EFCore/Metadata/Builders/EntityTypeBuilder`.cs @@ -11,6 +11,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Internal; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Builders { /// @@ -53,16 +55,16 @@ public EntityTypeBuilder([NotNull] IMutableEntityType entityType) /// /// The name of the base type or to indicate no base type. /// The same builder instance so that multiple configuration calls can be chained. - public new virtual EntityTypeBuilder HasBaseType([CanBeNull] string name) - => new(Builder.HasBaseType(name, ConfigurationSource.Explicit).Metadata); + public new virtual EntityTypeBuilder HasBaseType([CanBeNull] string? name) + => new(Builder.HasBaseType(name, ConfigurationSource.Explicit)!.Metadata); /// /// Sets the base type of this entity type in an inheritance hierarchy. /// /// The base type or to indicate no base type. /// The same builder instance so that multiple configuration calls can be chained. - public new virtual EntityTypeBuilder HasBaseType([CanBeNull] Type entityType) - => new(Builder.HasBaseType(entityType, ConfigurationSource.Explicit).Metadata); + public new virtual EntityTypeBuilder HasBaseType([CanBeNull] Type? entityType) + => new(Builder.HasBaseType(entityType, ConfigurationSource.Explicit)!.Metadata); /// /// Sets the base type of this entity type in an inheritance hierarchy. @@ -89,7 +91,7 @@ public virtual KeyBuilder HasKey([NotNull] Expression> key => new KeyBuilder( Builder.PrimaryKey( Check.NotNull(keyExpression, nameof(keyExpression)).GetMemberAccessList(), - ConfigurationSource.Explicit).Metadata); + ConfigurationSource.Explicit)!.Metadata); /// /// Sets the properties that make up the primary key for this entity type. @@ -99,7 +101,7 @@ public virtual KeyBuilder HasKey([NotNull] Expression> key public new virtual KeyBuilder HasKey([NotNull] params string[] propertyNames) => new( Builder.PrimaryKey( - Check.NotEmpty(propertyNames, nameof(propertyNames)), ConfigurationSource.Explicit).Metadata); + Check.NotEmpty(propertyNames, nameof(propertyNames)), ConfigurationSource.Explicit)!.Metadata); /// /// Creates an alternate key in the model for this entity type if one does not already exist over the specified @@ -121,7 +123,7 @@ public virtual KeyBuilder HasAlternateKey([NotNull] Expression new( Builder.HasKey( Check.NotNull(keyExpression, nameof(keyExpression)).GetMemberAccessList(), - ConfigurationSource.Explicit).Metadata); + ConfigurationSource.Explicit)!.Metadata); /// /// Creates an alternate key in the model for this entity type if one does not already exist over the specified @@ -134,7 +136,7 @@ public virtual KeyBuilder HasAlternateKey([NotNull] Expression HasAlternateKey([NotNull] params string[] propertyNames) => new( Builder.HasKey( - Check.NotEmpty(propertyNames, nameof(propertyNames)), ConfigurationSource.Explicit).Metadata); + Check.NotEmpty(propertyNames, nameof(propertyNames)), ConfigurationSource.Explicit)!.Metadata); /// /// Configures the entity type to have no keys. It will only be usable for queries. @@ -155,7 +157,7 @@ public virtual KeyBuilder HasAlternateKey([NotNull] Expression Property([NotNull] Expression> propertyExpression) => new( Builder.Property( - Check.NotNull(propertyExpression, nameof(propertyExpression)).GetMemberAccess(), ConfigurationSource.Explicit) + Check.NotNull(propertyExpression, nameof(propertyExpression)).GetMemberAccess(), ConfigurationSource.Explicit)! .Metadata); /// @@ -218,7 +220,7 @@ public virtual EntityTypeBuilder Ignore([NotNull] Expression /// The LINQ predicate expression. /// The same builder instance so that multiple configuration calls can be chained. - public new virtual EntityTypeBuilder HasQueryFilter([CanBeNull] LambdaExpression filter) + public new virtual EntityTypeBuilder HasQueryFilter([CanBeNull] LambdaExpression? filter) => (EntityTypeBuilder)base.HasQueryFilter(filter); /// @@ -227,7 +229,7 @@ public virtual EntityTypeBuilder Ignore([NotNull] Expression /// The LINQ predicate expression. /// The same builder instance so that multiple configuration calls can be chained. - public virtual EntityTypeBuilder HasQueryFilter([CanBeNull] Expression> filter) + public virtual EntityTypeBuilder HasQueryFilter([CanBeNull] Expression>? filter) => (EntityTypeBuilder)base.HasQueryFilter(filter); /// @@ -265,7 +267,7 @@ public virtual IndexBuilder HasIndex([NotNull] Expression new( Builder.HasIndex( Check.NotNull(indexExpression, nameof(indexExpression)).GetMemberAccessList(), - ConfigurationSource.Explicit).Metadata); + ConfigurationSource.Explicit)!.Metadata); /// /// Configures an index on the specified properties with the given name. @@ -291,7 +293,7 @@ public virtual IndexBuilder HasIndex( Builder.HasIndex( Check.NotNull(indexExpression, nameof(indexExpression)).GetMemberAccessList(), name, - ConfigurationSource.Explicit).Metadata); + ConfigurationSource.Explicit)!.Metadata); /// /// Configures an unnamed index on the specified properties. @@ -304,7 +306,7 @@ public virtual IndexBuilder HasIndex( => new( Builder.HasIndex( Check.NotEmpty(propertyNames, nameof(propertyNames)), - ConfigurationSource.Explicit).Metadata); + ConfigurationSource.Explicit)!.Metadata); /// /// Configures an index on the specified properties with the given name. @@ -321,7 +323,7 @@ public virtual IndexBuilder HasIndex( Builder.HasIndex( Check.NotEmpty(propertyNames, nameof(propertyNames)), name, - ConfigurationSource.Explicit).Metadata); + ConfigurationSource.Explicit)!.Metadata); /// /// @@ -699,9 +701,9 @@ private OwnedNavigationBuilder OwnsOneBuilder(relationship.Metadata); @@ -1083,10 +1085,10 @@ private OwnedNavigationBuilder OwnsManyBuilder(relationship.Metadata); @@ -1119,7 +1121,7 @@ private OwnedNavigationBuilder OwnsManyBuilder /// An object that can be used to configure the relationship. public virtual ReferenceNavigationBuilder HasOne( - [CanBeNull] string navigationName) + [CanBeNull] string? navigationName) where TRelatedEntity : class { var relatedEntityType = FindRelatedEntityType(typeof(TRelatedEntity), navigationName); @@ -1162,7 +1164,7 @@ public virtual ReferenceNavigationBuilder HasOne /// An object that can be used to configure the relationship. public virtual ReferenceNavigationBuilder HasOne( - [CanBeNull] Expression> navigationExpression = null) + [CanBeNull] Expression>? navigationExpression = null) where TRelatedEntity : class { var navigationMember = navigationExpression?.GetMemberAccess(); @@ -1203,7 +1205,7 @@ public virtual ReferenceNavigationBuilder HasOne /// An object that can be used to configure the relationship. public virtual CollectionNavigationBuilder HasMany( - [CanBeNull] string navigationName) + [CanBeNull] string? navigationName) where TRelatedEntity : class { Check.NullButNotEmpty(navigationName, nameof(navigationName)); @@ -1216,18 +1218,18 @@ public virtual CollectionNavigationBuilder HasMany( Builder.Metadata, relatedEntityType, - new MemberIdentity(navigationName), + navigationName is null ? MemberIdentity.None : new MemberIdentity(navigationName), relationship?.Metadata, skipNavigation); } @@ -1258,7 +1260,7 @@ public virtual CollectionNavigationBuilder HasMany /// An object that can be used to configure the relationship. public virtual CollectionNavigationBuilder HasMany( - [CanBeNull] Expression>> navigationExpression = null) + [CanBeNull] Expression>>? navigationExpression = null) where TRelatedEntity : class { var navigationMember = navigationExpression?.GetMemberAccess(); @@ -1270,18 +1272,18 @@ public virtual CollectionNavigationBuilder HasMany( Builder.Metadata, relatedEntityType, - new MemberIdentity(navigationMember), + navigationMember is null ? MemberIdentity.None : new MemberIdentity(navigationMember), relationship?.Metadata, skipNavigation); } @@ -1374,7 +1376,7 @@ public virtual DiscriminatorBuilder HasDiscriminator( - Builder.HasDiscriminator(propertyExpression.GetMemberAccess(), ConfigurationSource.Explicit)); + Builder.HasDiscriminator(propertyExpression.GetMemberAccess(), ConfigurationSource.Explicit)!); } /// diff --git a/src/EFCore/Metadata/Builders/IConventionAnnotatableBuilder.cs b/src/EFCore/Metadata/Builders/IConventionAnnotatableBuilder.cs index c54a55dbbea..3daa0137743 100644 --- a/src/EFCore/Metadata/Builders/IConventionAnnotatableBuilder.cs +++ b/src/EFCore/Metadata/Builders/IConventionAnnotatableBuilder.cs @@ -4,6 +4,8 @@ using System; using JetBrains.Annotations; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Builders { /// @@ -37,7 +39,7 @@ public interface IConventionAnnotatableBuilder /// /// An to continue configuration if the annotation was set, otherwise. /// - IConventionAnnotatableBuilder HasAnnotation([NotNull] string name, [CanBeNull] object value, bool fromDataAnnotation = false); + IConventionAnnotatableBuilder? HasAnnotation([NotNull] string name, [CanBeNull] object? value, bool fromDataAnnotation = false); /// /// Sets the annotation stored under the given name. Overwrites the existing annotation if an @@ -51,9 +53,9 @@ public interface IConventionAnnotatableBuilder /// An to continue configuration if the annotation was set or removed, /// otherwise. /// - IConventionAnnotatableBuilder HasNonNullAnnotation( + IConventionAnnotatableBuilder? HasNonNullAnnotation( [NotNull] string name, - [CanBeNull] object value, + [CanBeNull] object? value, bool fromDataAnnotation = false); /// @@ -67,9 +69,9 @@ IConventionAnnotatableBuilder HasNonNullAnnotation( /// otherwise. /// [Obsolete("Use HasNonNullAnnotation")] - IConventionAnnotatableBuilder SetOrRemoveAnnotation( + IConventionAnnotatableBuilder? SetOrRemoveAnnotation( [NotNull] string name, - [CanBeNull] object value, + [CanBeNull] object? value, bool fromDataAnnotation = false) => HasNonNullAnnotation(name, value, fromDataAnnotation); @@ -80,7 +82,7 @@ IConventionAnnotatableBuilder SetOrRemoveAnnotation( /// The value to be stored in the annotation. /// Indicates whether the configuration was specified using a data annotation. /// if the annotation can be set, otherwise. - bool CanSetAnnotation([NotNull] string name, [CanBeNull] object value, bool fromDataAnnotation = false); + bool CanSetAnnotation([NotNull] string name, [CanBeNull] object? value, bool fromDataAnnotation = false); /// /// Removes the annotation with the given name from this object. @@ -90,7 +92,7 @@ IConventionAnnotatableBuilder SetOrRemoveAnnotation( /// /// An to continue configuration if the annotation was set, otherwise. /// - IConventionAnnotatableBuilder HasNoAnnotation([NotNull] string name, bool fromDataAnnotation = false); + IConventionAnnotatableBuilder? HasNoAnnotation([NotNull] string name, bool fromDataAnnotation = false); /// /// Removes the annotation with the given name from this object. @@ -101,7 +103,7 @@ IConventionAnnotatableBuilder SetOrRemoveAnnotation( /// An to continue configuration if the annotation was set, otherwise. /// [Obsolete("Use HasNoAnnotation")] - IConventionAnnotatableBuilder RemoveAnnotation([NotNull] string name, bool fromDataAnnotation = false) + IConventionAnnotatableBuilder? RemoveAnnotation([NotNull] string name, bool fromDataAnnotation = false) => HasNoAnnotation(name, fromDataAnnotation); /// diff --git a/src/EFCore/Metadata/Builders/IConventionDiscriminatorBuilder.cs b/src/EFCore/Metadata/Builders/IConventionDiscriminatorBuilder.cs index 562979ef77d..f8be77eab59 100644 --- a/src/EFCore/Metadata/Builders/IConventionDiscriminatorBuilder.cs +++ b/src/EFCore/Metadata/Builders/IConventionDiscriminatorBuilder.cs @@ -3,6 +3,8 @@ using JetBrains.Annotations; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Builders { /// @@ -16,7 +18,7 @@ public interface IConventionDiscriminatorBuilder /// The value indicating if this discriminator mapping is complete. /// Indicates whether the configuration was specified using a data annotation. /// The same builder so that multiple calls can be chained. - IConventionDiscriminatorBuilder IsComplete(bool complete, bool fromDataAnnotation = false); + IConventionDiscriminatorBuilder? IsComplete(bool complete, bool fromDataAnnotation = false); /// /// Returns a value indicating whether the discriminator mapping is complete can be set from this configuration source. @@ -32,7 +34,7 @@ public interface IConventionDiscriminatorBuilder /// The discriminator value. /// Indicates whether the configuration was specified using a data annotation. /// The same builder so that multiple calls can be chained. - IConventionDiscriminatorBuilder HasValue([CanBeNull] object value, bool fromDataAnnotation = false); + IConventionDiscriminatorBuilder? HasValue([CanBeNull] object? value, bool fromDataAnnotation = false); /// /// Configures the discriminator value to use for entities of the given type. @@ -41,9 +43,9 @@ public interface IConventionDiscriminatorBuilder /// The discriminator value. /// Indicates whether the configuration was specified using a data annotation. /// The same builder so that multiple calls can be chained. - IConventionDiscriminatorBuilder HasValue( + IConventionDiscriminatorBuilder? HasValue( [NotNull] IConventionEntityType entityType, - [CanBeNull] object value, + [CanBeNull] object? value, bool fromDataAnnotation = false); /// @@ -52,7 +54,7 @@ IConventionDiscriminatorBuilder HasValue( /// The discriminator value. /// Indicates whether the configuration was specified using a data annotation. /// if the discriminator value can be set from this configuration source. - bool CanSetValue([CanBeNull] object value, bool fromDataAnnotation = false); + bool CanSetValue([CanBeNull] object? value, bool fromDataAnnotation = false); /// /// Returns a value indicating whether the discriminator value can be set from this configuration source. @@ -61,6 +63,6 @@ IConventionDiscriminatorBuilder HasValue( /// The discriminator value. /// Indicates whether the configuration was specified using a data annotation. /// if the discriminator value can be set from this configuration source. - bool CanSetValue([NotNull] IConventionEntityType entityType, [CanBeNull] object value, bool fromDataAnnotation = false); + bool CanSetValue([NotNull] IConventionEntityType entityType, [CanBeNull] object? value, bool fromDataAnnotation = false); } } diff --git a/src/EFCore/Metadata/Builders/IConventionEntityTypeBuilder.cs b/src/EFCore/Metadata/Builders/IConventionEntityTypeBuilder.cs index 65c792651c8..cfeb1929b97 100644 --- a/src/EFCore/Metadata/Builders/IConventionEntityTypeBuilder.cs +++ b/src/EFCore/Metadata/Builders/IConventionEntityTypeBuilder.cs @@ -7,6 +7,8 @@ using System.Reflection; using JetBrains.Annotations; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Builders { /// @@ -34,8 +36,8 @@ public interface IConventionEntityTypeBuilder : IConventionAnnotatableBuilder /// The same builder instance if the base type was configured, /// otherwise. /// - IConventionEntityTypeBuilder HasBaseType( - [CanBeNull] IConventionEntityType baseEntityType, + IConventionEntityTypeBuilder? HasBaseType( + [CanBeNull] IConventionEntityType? baseEntityType, bool fromDataAnnotation = false); /// @@ -44,7 +46,7 @@ IConventionEntityTypeBuilder HasBaseType( /// The base entity type or to indicate no base type. /// Indicates whether the configuration was specified using a data annotation. /// if the given type can be set as the base type of this entity type. - bool CanSetBaseType([CanBeNull] IConventionEntityType baseEntityType, bool fromDataAnnotation = false); + bool CanSetBaseType([CanBeNull] IConventionEntityType? baseEntityType, bool fromDataAnnotation = false); /// /// Returns an object that can be used to configure the property with the given name. @@ -58,7 +60,7 @@ IConventionEntityTypeBuilder HasBaseType( /// An object that can be used to configure the property if it exists on the entity type, /// otherwise. /// - IConventionPropertyBuilder Property( + IConventionPropertyBuilder? Property( [NotNull] Type propertyType, [NotNull] string propertyName, bool setTypeConfigurationSource = true, @@ -74,7 +76,7 @@ IConventionPropertyBuilder Property( /// An object that can be used to configure the property if it exists on the entity type, /// otherwise. /// - IConventionPropertyBuilder Property([NotNull] MemberInfo memberInfo, bool fromDataAnnotation = false); + IConventionPropertyBuilder? Property([NotNull] MemberInfo memberInfo, bool fromDataAnnotation = false); /// /// Creates a property with a name that's different from any existing properties. @@ -86,7 +88,7 @@ IConventionPropertyBuilder Property( /// An object that can be used to configure the property if it exists on the entity type, /// otherwise. /// - IConventionPropertyBuilder CreateUniqueProperty([NotNull] Type propertyType, [NotNull] string basePropertyName, bool required); + IConventionPropertyBuilder? CreateUniqueProperty([NotNull] Type propertyType, [NotNull] string basePropertyName, bool required); /// /// Returns the existing properties with the given names or creates them if matching CLR members are found. @@ -94,8 +96,8 @@ IConventionPropertyBuilder Property( /// The names of the properties. /// Indicates whether the configuration was specified using a data annotation. /// A list of properties if they exist on the entity type, otherwise. - IReadOnlyList GetOrCreateProperties( - [CanBeNull] IReadOnlyList propertyNames, + IReadOnlyList? GetOrCreateProperties( + [CanBeNull] IReadOnlyList? propertyNames, bool fromDataAnnotation = false); /// @@ -104,8 +106,8 @@ IReadOnlyList GetOrCreateProperties( /// The type members. /// Indicates whether the configuration was specified using a data annotation. /// A list of properties if they exist on the entity type, otherwise. - IReadOnlyList GetOrCreateProperties( - [CanBeNull] IEnumerable memberInfos, + IReadOnlyList? GetOrCreateProperties( + [CanBeNull] IEnumerable? memberInfos, bool fromDataAnnotation = false); /// @@ -135,7 +137,7 @@ IConventionEntityTypeBuilder RemoveUnusedShadowProperties( /// An object that can be used to configure the property if it exists on the entity type, /// otherwise. /// - IConventionServicePropertyBuilder ServiceProperty( + IConventionServicePropertyBuilder? ServiceProperty( [NotNull] MemberInfo memberInfo, bool fromDataAnnotation = false); @@ -161,7 +163,7 @@ IConventionServicePropertyBuilder ServiceProperty( /// The same instance so that additional configuration calls can be chained /// if the given member was ignored, otherwise. /// - IConventionEntityTypeBuilder Ignore([NotNull] string memberName, bool fromDataAnnotation = false); + IConventionEntityTypeBuilder? Ignore([NotNull] string memberName, bool fromDataAnnotation = false); /// /// Returns a value indicating whether the given member name can be ignored from the given configuration source. @@ -186,7 +188,7 @@ IConventionServicePropertyBuilder ServiceProperty( /// An object that can be used to configure the primary key if it was set on the entity type, /// otherwise. /// - IConventionKeyBuilder PrimaryKey([CanBeNull] IReadOnlyList properties, bool fromDataAnnotation = false); + IConventionKeyBuilder? PrimaryKey([CanBeNull] IReadOnlyList? properties, bool fromDataAnnotation = false); /// /// Returns a value indicating whether the given properties can be set as the primary key for this entity type. @@ -194,7 +196,7 @@ IConventionServicePropertyBuilder ServiceProperty( /// The properties that make up the primary key. /// Indicates whether the configuration was specified using a data annotation. /// if the given properties can be set as the primary key. - bool CanSetPrimaryKey([CanBeNull] IReadOnlyList properties, bool fromDataAnnotation = false); + bool CanSetPrimaryKey([CanBeNull] IReadOnlyList? properties, bool fromDataAnnotation = false); /// /// Creates an alternate key in the model for this entity type if one does not already exist over the specified @@ -206,7 +208,7 @@ IConventionServicePropertyBuilder ServiceProperty( /// An object that can be used to configure the key if it exists on the entity type, /// otherwise. /// - IConventionKeyBuilder HasKey([NotNull] IReadOnlyList properties, bool fromDataAnnotation = false); + IConventionKeyBuilder? HasKey([NotNull] IReadOnlyList properties, bool fromDataAnnotation = false); /// /// Removes a primary or alternate key from this entity type. @@ -214,7 +216,7 @@ IConventionServicePropertyBuilder ServiceProperty( /// The properties that make up the key. /// Indicates whether the configuration was specified using a data annotation. /// The key that was removed. - IConventionEntityTypeBuilder HasNoKey([NotNull] IReadOnlyList properties, bool fromDataAnnotation = false); + IConventionEntityTypeBuilder? HasNoKey([NotNull] IReadOnlyList properties, bool fromDataAnnotation = false); /// /// Removes a primary or alternate key from this entity type. @@ -225,7 +227,7 @@ IConventionServicePropertyBuilder ServiceProperty( /// The same builder instance if the key was removed, /// otherwise. /// - IConventionEntityTypeBuilder HasNoKey([NotNull] IConventionKey key, bool fromDataAnnotation = false); + IConventionEntityTypeBuilder? HasNoKey([NotNull] IConventionKey key, bool fromDataAnnotation = false); /// /// Returns a value indicating whether the key can be removed from this entity type. @@ -243,7 +245,7 @@ IConventionServicePropertyBuilder ServiceProperty( /// The same builder instance if the entity type was configured as keyless, /// otherwise. /// - IConventionEntityTypeBuilder HasNoKey(bool fromDataAnnotation = false); + IConventionEntityTypeBuilder? HasNoKey(bool fromDataAnnotation = false); /// /// Returns a value indicating whether the entity type can be marked as keyless. @@ -263,7 +265,7 @@ IConventionServicePropertyBuilder ServiceProperty( /// An object that can be used to configure the index if it exists on the entity type, /// otherwise. /// - IConventionIndexBuilder HasIndex( + IConventionIndexBuilder? HasIndex( [NotNull] IReadOnlyList propertyNames, bool fromDataAnnotation = false); @@ -279,7 +281,7 @@ IConventionIndexBuilder HasIndex( /// An object that can be used to configure the index if it exists on the entity type, /// otherwise. /// - IConventionIndexBuilder HasIndex( + IConventionIndexBuilder? HasIndex( [NotNull] IReadOnlyList propertyNames, [NotNull] string name, bool fromDataAnnotation = false); @@ -295,7 +297,7 @@ IConventionIndexBuilder HasIndex( /// An object that can be used to configure the index if it exists on the entity type, /// otherwise. /// - IConventionIndexBuilder HasIndex( + IConventionIndexBuilder? HasIndex( [NotNull] IReadOnlyList properties, bool fromDataAnnotation = false); @@ -311,7 +313,7 @@ IConventionIndexBuilder HasIndex( /// An object that can be used to configure the index if it exists on the entity type, /// otherwise. /// - IConventionIndexBuilder HasIndex( + IConventionIndexBuilder? HasIndex( [NotNull] IReadOnlyList properties, [NotNull] string name, bool fromDataAnnotation = false); @@ -325,7 +327,7 @@ IConventionIndexBuilder HasIndex( /// The same builder instance if the index was removed or didn't exist, /// otherwise. /// - IConventionEntityTypeBuilder HasNoIndex([NotNull] IReadOnlyList properties, bool fromDataAnnotation = false); + IConventionEntityTypeBuilder? HasNoIndex([NotNull] IReadOnlyList properties, bool fromDataAnnotation = false); /// /// Removes an index from this entity type. @@ -336,7 +338,7 @@ IConventionIndexBuilder HasIndex( /// The same builder instance if the index was removed, /// otherwise. /// - IConventionEntityTypeBuilder HasNoIndex([NotNull] IConventionIndex index, bool fromDataAnnotation = false); + IConventionEntityTypeBuilder? HasNoIndex([NotNull] IConventionIndex index, bool fromDataAnnotation = false); /// /// Returns a value indicating whether the index can be removed from this entity type. @@ -352,7 +354,7 @@ IConventionIndexBuilder HasIndex( /// The entity type that this relationship targets. /// Indicates whether the configuration was specified using a data annotation. /// An object that can be used to configure the relationship. - IConventionForeignKeyBuilder HasRelationship( + IConventionForeignKeyBuilder? HasRelationship( [NotNull] IConventionEntityType targetEntityType, bool fromDataAnnotation = false); @@ -366,7 +368,7 @@ IConventionForeignKeyBuilder HasRelationship( /// An object that can be used to configure the relationship if it exists on the entity type, /// otherwise. /// - IConventionForeignKeyBuilder HasRelationship( + IConventionForeignKeyBuilder? HasRelationship( [NotNull] IConventionEntityType principalEntityType, [NotNull] IReadOnlyList dependentProperties, bool fromDataAnnotation = false); @@ -381,7 +383,7 @@ IConventionForeignKeyBuilder HasRelationship( /// An object that can be used to configure the relationship if it exists on the entity type, /// otherwise. /// - IConventionForeignKeyBuilder HasRelationship( + IConventionForeignKeyBuilder? HasRelationship( [NotNull] IConventionEntityType principalEntityType, [NotNull] IConventionKey principalKey, bool fromDataAnnotation = false); @@ -397,7 +399,7 @@ IConventionForeignKeyBuilder HasRelationship( /// An object that can be used to configure the relationship if it exists on the entity type, /// otherwise. /// - IConventionForeignKeyBuilder HasRelationship( + IConventionForeignKeyBuilder? HasRelationship( [NotNull] IConventionEntityType principalEntityType, [NotNull] IReadOnlyList dependentProperties, [NotNull] IConventionKey principalKey, @@ -416,7 +418,7 @@ IConventionForeignKeyBuilder HasRelationship( /// An object that can be used to configure the relationship if it exists on the entity type, /// otherwise. /// - IConventionForeignKeyBuilder HasRelationship( + IConventionForeignKeyBuilder? HasRelationship( [NotNull] IConventionEntityType targetEntityType, [NotNull] string navigationName, bool setTargetAsPrincipal = false, @@ -433,7 +435,7 @@ IConventionForeignKeyBuilder HasRelationship( /// An object that can be used to configure the relationship if it exists on the entity type, /// otherwise. /// - IConventionForeignKeyBuilder HasRelationship( + IConventionForeignKeyBuilder? HasRelationship( [NotNull] IConventionEntityType targetEntityType, [NotNull] MemberInfo navigation, bool setTargetAsPrincipal = false, @@ -454,10 +456,10 @@ IConventionForeignKeyBuilder HasRelationship( /// An object that can be used to configure the relationship if it exists on the entity type, /// otherwise. /// - IConventionForeignKeyBuilder HasRelationship( + IConventionForeignKeyBuilder? HasRelationship( [NotNull] IConventionEntityType targetEntityType, [NotNull] string navigationName, - [CanBeNull] string inverseNavigationName, + [CanBeNull] string? inverseNavigationName, bool setTargetAsPrincipal = false, bool fromDataAnnotation = false); @@ -476,10 +478,10 @@ IConventionForeignKeyBuilder HasRelationship( /// An object that can be used to configure the relationship if it exists on the entity type, /// otherwise. /// - IConventionForeignKeyBuilder HasRelationship( + IConventionForeignKeyBuilder? HasRelationship( [NotNull] IConventionEntityType targetEntityType, [NotNull] MemberInfo navigation, - [CanBeNull] MemberInfo inverseNavigation, + [CanBeNull] MemberInfo? inverseNavigation, bool setTargetAsPrincipal = false, bool fromDataAnnotation = false); @@ -490,7 +492,7 @@ IConventionForeignKeyBuilder HasRelationship( /// The name of the navigation property on this entity type that is part of the relationship. /// Indicates whether the configuration was specified using a data annotation. /// An object that can be used to configure the relationship. - IConventionForeignKeyBuilder HasOwnership( + IConventionForeignKeyBuilder? HasOwnership( [NotNull] Type targetEntityType, [NotNull] string navigationName, bool fromDataAnnotation = false); @@ -505,7 +507,7 @@ IConventionForeignKeyBuilder HasOwnership( /// An object that can be used to configure the relationship if it exists on the entity type, /// otherwise. /// - IConventionForeignKeyBuilder HasOwnership( + IConventionForeignKeyBuilder? HasOwnership( [NotNull] Type targetEntityType, [NotNull] MemberInfo navigation, bool fromDataAnnotation = false); @@ -524,10 +526,10 @@ IConventionForeignKeyBuilder HasOwnership( /// An object that can be used to configure the relationship if it exists on the entity type, /// otherwise. /// - IConventionForeignKeyBuilder HasOwnership( + IConventionForeignKeyBuilder? HasOwnership( [NotNull] Type targetEntityType, [NotNull] string navigationName, - [CanBeNull] string inverseNavigationName, + [CanBeNull] string? inverseNavigationName, bool fromDataAnnotation = false); /// @@ -544,10 +546,10 @@ IConventionForeignKeyBuilder HasOwnership( /// An object that can be used to configure the relationship if it exists on the entity type, /// otherwise. /// - IConventionForeignKeyBuilder HasOwnership( + IConventionForeignKeyBuilder? HasOwnership( [NotNull] Type targetEntityType, [NotNull] MemberInfo navigation, - [CanBeNull] MemberInfo inverseNavigation, + [CanBeNull] MemberInfo? inverseNavigation, bool fromDataAnnotation = false); /// @@ -565,7 +567,7 @@ IConventionForeignKeyBuilder HasOwnership( /// The same builder instance if the relationship was removed or didn't exist, /// otherwise. /// - IConventionEntityTypeBuilder HasNoRelationship( + IConventionEntityTypeBuilder? HasNoRelationship( [NotNull] IReadOnlyList properties, [NotNull] IConventionKey principalKey, [NotNull] IConventionEntityType principalEntityType, @@ -580,7 +582,7 @@ IConventionEntityTypeBuilder HasNoRelationship( /// The same builder instance if the foreign key was removed, /// otherwise. /// - IConventionEntityTypeBuilder HasNoRelationship([NotNull] IConventionForeignKey foreignKey, bool fromDataAnnotation = false); + IConventionEntityTypeBuilder? HasNoRelationship([NotNull] IConventionForeignKey foreignKey, bool fromDataAnnotation = false); /// /// Returns a value indicating whether the foreign key can be removed from this entity type. @@ -599,7 +601,7 @@ IConventionEntityTypeBuilder HasNoRelationship( /// The same builder instance if the skip navigation was removed, /// otherwise. /// - IConventionEntityTypeBuilder HasNoSkipNavigation([NotNull] ISkipNavigation skipNavigation, bool fromDataAnnotation = false); + IConventionEntityTypeBuilder? HasNoSkipNavigation([NotNull] ISkipNavigation skipNavigation, bool fromDataAnnotation = false); /// /// Returns a value indicating whether the skip navigation can be removed from this entity type. @@ -653,7 +655,7 @@ bool CanAddNavigation([NotNull] string navigationName, bool fromDataAnnotation = /// An object that can be used to configure the relationship if it exists on the entity type, /// otherwise. /// - IConventionSkipNavigationBuilder HasSkipNavigation( + IConventionSkipNavigationBuilder? HasSkipNavigation( [NotNull] MemberInfo navigation, [NotNull] IConventionEntityType targetEntityType, [NotNull] MemberInfo inverseNavigation, @@ -675,7 +677,7 @@ IConventionSkipNavigationBuilder HasSkipNavigation( /// An object that can be used to configure the relationship if it exists on the entity type, /// otherwise. /// - IConventionSkipNavigationBuilder HasSkipNavigation( + IConventionSkipNavigationBuilder? HasSkipNavigation( [NotNull] MemberInfo navigation, [NotNull] IConventionEntityType targetEntityType, bool? collection = null, @@ -696,7 +698,7 @@ IConventionSkipNavigationBuilder HasSkipNavigation( /// An object that can be used to configure the relationship if it exists on the entity type, /// otherwise. /// - IConventionSkipNavigationBuilder HasSkipNavigation( + IConventionSkipNavigationBuilder? HasSkipNavigation( [NotNull] string navigationName, [NotNull] IConventionEntityType targetEntityType, bool? collection = null, @@ -713,7 +715,7 @@ IConventionSkipNavigationBuilder HasSkipNavigation( /// The same builder instance if the query filter was set, /// otherwise. /// - IConventionEntityTypeBuilder HasQueryFilter([CanBeNull] LambdaExpression filter, bool fromDataAnnotation = false); + IConventionEntityTypeBuilder? HasQueryFilter([CanBeNull] LambdaExpression? filter, bool fromDataAnnotation = false); /// /// Returns a value indicating whether the given query filter can be set from the current configuration source. @@ -721,7 +723,7 @@ IConventionSkipNavigationBuilder HasSkipNavigation( /// The LINQ predicate expression. /// Indicates whether the configuration was specified using a data annotation. /// if the given query filter can be set. - bool CanSetQueryFilter([CanBeNull] LambdaExpression filter, bool fromDataAnnotation = false); + bool CanSetQueryFilter([CanBeNull] LambdaExpression? filter, bool fromDataAnnotation = false); /// /// Configures a query used to provide data for a keyless entity type. @@ -732,7 +734,7 @@ IConventionSkipNavigationBuilder HasSkipNavigation( /// The same builder instance if the query was set, otherwise. /// [Obsolete("Use InMemoryEntityTypeBuilderExtensions.ToInMemoryQuery")] - IConventionEntityTypeBuilder HasDefiningQuery([CanBeNull] LambdaExpression query, bool fromDataAnnotation = false); + IConventionEntityTypeBuilder? HasDefiningQuery([CanBeNull] LambdaExpression? query, bool fromDataAnnotation = false); /// /// Returns a value indicating whether the given defining query can be set from the current configuration source. @@ -741,7 +743,7 @@ IConventionSkipNavigationBuilder HasSkipNavigation( /// Indicates whether the configuration was specified using a data annotation. /// if the given defining query can be set. [Obsolete("Use InMemoryEntityTypeBuilderExtensions.CanSetInMemoryQuery")] - bool CanSetDefiningQuery([CanBeNull] LambdaExpression query, bool fromDataAnnotation = false); + bool CanSetDefiningQuery([CanBeNull] LambdaExpression? query, bool fromDataAnnotation = false); /// /// Configures the to be used for this entity type. @@ -756,7 +758,7 @@ IConventionSkipNavigationBuilder HasSkipNavigation( /// The same builder instance if the was set, /// otherwise. /// - IConventionEntityTypeBuilder HasChangeTrackingStrategy( + IConventionEntityTypeBuilder? HasChangeTrackingStrategy( ChangeTrackingStrategy? changeTrackingStrategy, bool fromDataAnnotation = false); @@ -784,7 +786,7 @@ IConventionEntityTypeBuilder HasChangeTrackingStrategy( /// The same builder instance if the was set, /// otherwise. /// - IConventionEntityTypeBuilder UsePropertyAccessMode( + IConventionEntityTypeBuilder? UsePropertyAccessMode( PropertyAccessMode? propertyAccessMode, bool fromDataAnnotation = false); @@ -805,7 +807,7 @@ IConventionEntityTypeBuilder UsePropertyAccessMode( /// /// Indicates whether the configuration was specified using a data annotation. /// A builder that allows the discriminator property to be configured. - IConventionDiscriminatorBuilder HasDiscriminator(bool fromDataAnnotation = false); + IConventionDiscriminatorBuilder? HasDiscriminator(bool fromDataAnnotation = false); /// /// Configures the discriminator property used to identify which entity type each row in a table represents @@ -814,7 +816,7 @@ IConventionEntityTypeBuilder UsePropertyAccessMode( /// The type of values stored in the discriminator property. /// Indicates whether the configuration was specified using a data annotation. /// A builder that allows the discriminator property to be configured. - IConventionDiscriminatorBuilder HasDiscriminator([NotNull] Type type, bool fromDataAnnotation = false); + IConventionDiscriminatorBuilder? HasDiscriminator([NotNull] Type type, bool fromDataAnnotation = false); /// /// Configures the discriminator property used to identify which entity type each row in a table represents @@ -823,7 +825,7 @@ IConventionEntityTypeBuilder UsePropertyAccessMode( /// The name of the discriminator property. /// Indicates whether the configuration was specified using a data annotation. /// A builder that allows the discriminator property to be configured. - IConventionDiscriminatorBuilder HasDiscriminator([NotNull] string name, bool fromDataAnnotation = false); + IConventionDiscriminatorBuilder? HasDiscriminator([NotNull] string name, bool fromDataAnnotation = false); /// /// Configures the discriminator property used to identify which entity type each row in a table represents @@ -833,7 +835,7 @@ IConventionEntityTypeBuilder UsePropertyAccessMode( /// The type of values stored in the discriminator property. /// Indicates whether the configuration was specified using a data annotation. /// A builder that allows the discriminator property to be configured. - IConventionDiscriminatorBuilder HasDiscriminator([NotNull] string name, [NotNull] Type type, bool fromDataAnnotation = false); + IConventionDiscriminatorBuilder? HasDiscriminator([NotNull] string name, [NotNull] Type type, bool fromDataAnnotation = false); /// /// Configures the discriminator property used to identify which entity type each row in a table represents @@ -842,7 +844,7 @@ IConventionEntityTypeBuilder UsePropertyAccessMode( /// The property mapped to the discriminator property. /// Indicates whether the configuration was specified using a data annotation. /// A builder that allows the discriminator property to be configured. - IConventionDiscriminatorBuilder HasDiscriminator([NotNull] MemberInfo memberInfo, bool fromDataAnnotation = false); + IConventionDiscriminatorBuilder? HasDiscriminator([NotNull] MemberInfo memberInfo, bool fromDataAnnotation = false); /// /// Removes the discriminator property from this entity type. @@ -854,7 +856,7 @@ IConventionEntityTypeBuilder UsePropertyAccessMode( /// The same builder instance if the discriminator was configured, /// otherwise. /// - IConventionEntityTypeBuilder HasNoDiscriminator(bool fromDataAnnotation = false); + IConventionEntityTypeBuilder? HasNoDiscriminator(bool fromDataAnnotation = false); /// /// Removes the discriminator property from this entity type. @@ -867,7 +869,7 @@ IConventionEntityTypeBuilder UsePropertyAccessMode( /// otherwise. /// [Obsolete("Use HasNoDiscriminator")] - IConventionEntityTypeBuilder HasNoDeclaredDiscriminator(bool fromDataAnnotation = false) + IConventionEntityTypeBuilder? HasNoDeclaredDiscriminator(bool fromDataAnnotation = false) => HasNoDiscriminator(fromDataAnnotation); /// diff --git a/src/EFCore/Metadata/Builders/IConventionForeignKeyBuilder.cs b/src/EFCore/Metadata/Builders/IConventionForeignKeyBuilder.cs index 7699aabc49c..3f1be9c9afa 100644 --- a/src/EFCore/Metadata/Builders/IConventionForeignKeyBuilder.cs +++ b/src/EFCore/Metadata/Builders/IConventionForeignKeyBuilder.cs @@ -5,6 +5,8 @@ using System.Reflection; using JetBrains.Annotations; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Builders { /// @@ -35,7 +37,7 @@ public interface IConventionForeignKeyBuilder : IConventionAnnotatableBuilder /// A builder instance if the entity types were configured as related, /// otherwise. /// - IConventionForeignKeyBuilder HasEntityTypes( + IConventionForeignKeyBuilder? HasEntityTypes( [NotNull] IConventionEntityType principalEntityType, [NotNull] IConventionEntityType dependentEntityType, bool fromDataAnnotation = false); @@ -66,7 +68,7 @@ bool CanSetEntityTypes( /// Indicates whether the configuration was specified using a data annotation. /// if the principal and dependent entity types can be switched. bool CanInvert( - [CanBeNull] IReadOnlyList newForeignKeyProperties, + [CanBeNull] IReadOnlyList? newForeignKeyProperties, bool fromDataAnnotation = false); /// @@ -78,8 +80,8 @@ bool CanInvert( /// The same builder instance if the properties were configured as the foreign key, /// otherwise. /// - IConventionForeignKeyBuilder HasForeignKey( - [CanBeNull] IReadOnlyList propertyNames, + IConventionForeignKeyBuilder? HasForeignKey( + [CanBeNull] IReadOnlyList? propertyNames, bool fromDataAnnotation = false); /// @@ -91,8 +93,8 @@ IConventionForeignKeyBuilder HasForeignKey( /// The same builder instance if the properties were configured as the foreign key, /// otherwise. /// - IConventionForeignKeyBuilder HasForeignKey( - [CanBeNull] IReadOnlyList properties, + IConventionForeignKeyBuilder? HasForeignKey( + [CanBeNull] IReadOnlyList? properties, bool fromDataAnnotation = false); /// @@ -102,7 +104,7 @@ IConventionForeignKeyBuilder HasForeignKey( /// The properties to use as the foreign key for this relationship. /// Indicates whether the configuration was specified using a data annotation. /// if the given properties can be set as the foreign key. - bool CanSetForeignKey([CanBeNull] IReadOnlyList propertyNames, bool fromDataAnnotation = false); + bool CanSetForeignKey([CanBeNull] IReadOnlyList? propertyNames, bool fromDataAnnotation = false); /// /// Returns a value indicating whether the given properties can be set as the foreign key for this relationship @@ -111,7 +113,7 @@ IConventionForeignKeyBuilder HasForeignKey( /// The properties to use as the foreign key for this relationship. /// Indicates whether the configuration was specified using a data annotation. /// if the given properties can be set as the foreign key. - bool CanSetForeignKey([CanBeNull] IReadOnlyList properties, bool fromDataAnnotation = false); + bool CanSetForeignKey([CanBeNull] IReadOnlyList? properties, bool fromDataAnnotation = false); /// /// Configures the properties that this relationship targets. @@ -122,8 +124,8 @@ IConventionForeignKeyBuilder HasForeignKey( /// The same builder instance if the properties were configured as the target for this relationship, /// otherwise. /// - IConventionForeignKeyBuilder HasPrincipalKey( - [CanBeNull] IReadOnlyList propertyNames, + IConventionForeignKeyBuilder? HasPrincipalKey( + [CanBeNull] IReadOnlyList? propertyNames, bool fromDataAnnotation = false); /// @@ -135,8 +137,8 @@ IConventionForeignKeyBuilder HasPrincipalKey( /// The same builder instance if the properties were configured as the target for this relationship, /// otherwise. /// - IConventionForeignKeyBuilder HasPrincipalKey( - [CanBeNull] IReadOnlyList properties, + IConventionForeignKeyBuilder? HasPrincipalKey( + [CanBeNull] IReadOnlyList? properties, bool fromDataAnnotation = false); /// @@ -146,7 +148,7 @@ IConventionForeignKeyBuilder HasPrincipalKey( /// The properties for this relationship to target. /// Indicates whether the configuration was specified using a data annotation. /// if the given properties can be set as the target. - bool CanSetPrincipalKey([CanBeNull] IReadOnlyList propertyNames, bool fromDataAnnotation = false); + bool CanSetPrincipalKey([CanBeNull] IReadOnlyList? propertyNames, bool fromDataAnnotation = false); /// /// Returns a value indicating whether the given properties can be set as the target for this relationship @@ -155,7 +157,7 @@ IConventionForeignKeyBuilder HasPrincipalKey( /// The properties for this relationship to target. /// Indicates whether the configuration was specified using a data annotation. /// if the given properties can be set as the target. - bool CanSetPrincipalKey([CanBeNull] IReadOnlyList properties, bool fromDataAnnotation = false); + bool CanSetPrincipalKey([CanBeNull] IReadOnlyList? properties, bool fromDataAnnotation = false); /// /// Configures the property with the given name as a navigation property used by this relationship. @@ -169,8 +171,8 @@ IConventionForeignKeyBuilder HasPrincipalKey( /// The same builder instance if the navigation property was configured, /// otherwise. /// - IConventionForeignKeyBuilder HasNavigation( - [CanBeNull] string name, + IConventionForeignKeyBuilder? HasNavigation( + [CanBeNull] string? name, bool pointsToPrincipal, bool fromDataAnnotation = false); @@ -186,8 +188,8 @@ IConventionForeignKeyBuilder HasNavigation( /// The same builder instance if the navigation property was configured, /// otherwise. /// - IConventionForeignKeyBuilder HasNavigation( - [CanBeNull] MemberInfo property, + IConventionForeignKeyBuilder? HasNavigation( + [CanBeNull] MemberInfo? property, bool pointsToPrincipal, bool fromDataAnnotation = false); @@ -207,9 +209,9 @@ IConventionForeignKeyBuilder HasNavigation( /// The same builder instance if the navigation properties were configured, /// otherwise. /// - IConventionForeignKeyBuilder HasNavigations( - [CanBeNull] string navigationToPrincipalName, - [CanBeNull] string navigationToDependentName, + IConventionForeignKeyBuilder? HasNavigations( + [CanBeNull] string? navigationToPrincipalName, + [CanBeNull] string? navigationToDependentName, bool fromDataAnnotation = false); /// @@ -228,9 +230,9 @@ IConventionForeignKeyBuilder HasNavigations( /// The same builder instance if the navigation properties were configured, /// otherwise. /// - IConventionForeignKeyBuilder HasNavigations( - [CanBeNull] MemberInfo navigationToPrincipal, - [CanBeNull] MemberInfo navigationToDependent, + IConventionForeignKeyBuilder? HasNavigations( + [CanBeNull] MemberInfo? navigationToPrincipal, + [CanBeNull] MemberInfo? navigationToDependent, bool fromDataAnnotation = false); /// @@ -244,7 +246,7 @@ IConventionForeignKeyBuilder HasNavigations( /// Indicates whether the configuration was specified using a data annotation. /// if the given property can be used as a navigation. bool CanSetNavigation( - [CanBeNull] string name, + [CanBeNull] string? name, bool pointsToPrincipal, bool fromDataAnnotation = false); @@ -259,7 +261,7 @@ bool CanSetNavigation( /// Indicates whether the configuration was specified using a data annotation. /// if the given property can be used as a navigation. bool CanSetNavigation( - [CanBeNull] MemberInfo property, + [CanBeNull] MemberInfo? property, bool pointsToPrincipal, bool fromDataAnnotation = false); @@ -278,8 +280,8 @@ bool CanSetNavigation( /// Indicates whether the configuration was specified using a data annotation. /// if the given properties can be used as navigations. bool CanSetNavigations( - [CanBeNull] string navigationToPrincipalName, - [CanBeNull] string navigationToDependentName, + [CanBeNull] string? navigationToPrincipalName, + [CanBeNull] string? navigationToDependentName, bool fromDataAnnotation = false); /// @@ -297,8 +299,8 @@ bool CanSetNavigations( /// Indicates whether the configuration was specified using a data annotation. /// if the given properties can be used as navigations. bool CanSetNavigations( - [CanBeNull] MemberInfo navigationToPrincipal, - [CanBeNull] MemberInfo navigationToDependent, + [CanBeNull] MemberInfo? navigationToPrincipal, + [CanBeNull] MemberInfo? navigationToDependent, bool fromDataAnnotation = false); /// @@ -314,7 +316,7 @@ bool CanSetNavigations( /// The same builder instance if the requiredness was configured, /// otherwise. /// - IConventionForeignKeyBuilder IsRequired(bool? required, bool fromDataAnnotation = false); + IConventionForeignKeyBuilder? IsRequired(bool? required, bool fromDataAnnotation = false); /// /// Returns a value indicating whether the relationship requiredness can be configured @@ -341,7 +343,7 @@ bool CanSetNavigations( /// The same builder instance if the dependent end requiredness was configured, /// otherwise. /// - IConventionForeignKeyBuilder IsRequiredDependent(bool? required, bool fromDataAnnotation = false); + IConventionForeignKeyBuilder? IsRequiredDependent(bool? required, bool fromDataAnnotation = false); /// /// Returns a value indicating whether the dependent end requiredness can be configured @@ -368,7 +370,7 @@ bool CanSetNavigations( /// The same builder instance if the ownership was configured, /// otherwise. /// - IConventionForeignKeyBuilder IsOwnership(bool? ownership, bool fromDataAnnotation = false); + IConventionForeignKeyBuilder? IsOwnership(bool? ownership, bool fromDataAnnotation = false); /// /// Returns a value indicating whether this relationship can be configured as defining an ownership or not @@ -395,7 +397,7 @@ bool CanSetNavigations( /// The same builder instance if the uniqueness was configured, /// otherwise. /// - IConventionForeignKeyBuilder IsUnique(bool? unique, bool fromDataAnnotation = false); + IConventionForeignKeyBuilder? IsUnique(bool? unique, bool fromDataAnnotation = false); /// /// Returns a value indicating whether this relationship uniqueness can be configured @@ -422,7 +424,7 @@ bool CanSetNavigations( /// The same builder instance if the delete operation was configured, /// otherwise. /// - IConventionForeignKeyBuilder OnDelete(DeleteBehavior? deleteBehavior, bool fromDataAnnotation = false); + IConventionForeignKeyBuilder? OnDelete(DeleteBehavior? deleteBehavior, bool fromDataAnnotation = false); /// /// Returns a value indicating whether the operation on principal deletion can be configured diff --git a/src/EFCore/Metadata/Builders/IConventionIndexBuilder.cs b/src/EFCore/Metadata/Builders/IConventionIndexBuilder.cs index c5864342662..a7f3fab94f5 100644 --- a/src/EFCore/Metadata/Builders/IConventionIndexBuilder.cs +++ b/src/EFCore/Metadata/Builders/IConventionIndexBuilder.cs @@ -1,6 +1,8 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Builders { /// @@ -28,7 +30,7 @@ public interface IConventionIndexBuilder : IConventionAnnotatableBuilder /// The same builder instance if the uniqueness was configured, /// otherwise. /// - IConventionIndexBuilder IsUnique(bool? unique, bool fromDataAnnotation = false); + IConventionIndexBuilder? IsUnique(bool? unique, bool fromDataAnnotation = false); /// /// Returns a value indicating whether this index uniqueness can be configured diff --git a/src/EFCore/Metadata/Builders/IConventionKeyBuilder.cs b/src/EFCore/Metadata/Builders/IConventionKeyBuilder.cs index dafbea076c9..5fb02c29857 100644 --- a/src/EFCore/Metadata/Builders/IConventionKeyBuilder.cs +++ b/src/EFCore/Metadata/Builders/IConventionKeyBuilder.cs @@ -1,6 +1,8 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Builders { /// diff --git a/src/EFCore/Metadata/Builders/IConventionModelBuilder.cs b/src/EFCore/Metadata/Builders/IConventionModelBuilder.cs index aff274c68b5..9469cc1624a 100644 --- a/src/EFCore/Metadata/Builders/IConventionModelBuilder.cs +++ b/src/EFCore/Metadata/Builders/IConventionModelBuilder.cs @@ -4,6 +4,8 @@ using System; using JetBrains.Annotations; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Builders { /// @@ -37,7 +39,7 @@ public interface IConventionModelBuilder : IConventionAnnotatableBuilder /// An object that can be used to configure the entity type if the entity type was added or already part of the model, /// otherwise. /// - IConventionEntityTypeBuilder Entity([NotNull] string name, bool? shouldBeOwned = false, bool fromDataAnnotation = false); + IConventionEntityTypeBuilder? Entity([NotNull] string name, bool? shouldBeOwned = false, bool fromDataAnnotation = false); /// /// @@ -63,7 +65,7 @@ public interface IConventionModelBuilder : IConventionAnnotatableBuilder /// An object that can be used to configure the entity type if the entity type was added or already part of the model, /// otherwise. /// - IConventionEntityTypeBuilder SharedTypeEntity( + IConventionEntityTypeBuilder? SharedTypeEntity( [NotNull] string name, [NotNull] Type type, bool? shouldBeOwned = false, @@ -84,7 +86,7 @@ IConventionEntityTypeBuilder SharedTypeEntity( /// An object that can be used to configure the entity type if the entity type was added or already part of the model, /// otherwise. /// - IConventionEntityTypeBuilder Entity([NotNull] Type type, bool? shouldBeOwned = false, bool fromDataAnnotation = false); + IConventionEntityTypeBuilder? Entity([NotNull] Type type, bool? shouldBeOwned = false, bool fromDataAnnotation = false); /// /// Returns an object that can be used to configure a given entity type with defining navigation. @@ -99,7 +101,7 @@ IConventionEntityTypeBuilder SharedTypeEntity( /// An object that can be used to configure the entity type if the entity type was added or already part of the model, /// otherwise. /// - IConventionEntityTypeBuilder Entity( + IConventionEntityTypeBuilder? Entity( [NotNull] string name, [NotNull] string definingNavigationName, [NotNull] IConventionEntityType definingEntityType, @@ -118,7 +120,7 @@ IConventionEntityTypeBuilder Entity( /// An object that can be used to configure the entity type if the entity type was added or already part of the model, /// otherwise. /// - IConventionEntityTypeBuilder Entity( + IConventionEntityTypeBuilder? Entity( [NotNull] Type type, [NotNull] string definingNavigationName, [NotNull] IConventionEntityType definingEntityType, @@ -133,7 +135,7 @@ IConventionEntityTypeBuilder Entity( /// /// An object that can be used to provide default configuration for the owned entity types. /// - IConventionOwnedEntityTypeBuilder Owned([NotNull] Type type, bool fromDataAnnotation = false); + IConventionOwnedEntityTypeBuilder? Owned([NotNull] Type type, bool fromDataAnnotation = false); /// /// Indicates whether the given entity type name is ignored for the current configuration source. @@ -160,7 +162,7 @@ IConventionEntityTypeBuilder Entity( /// The same builder instance so that additional configuration calls can be chained /// if the given entity type was ignored, otherwise. /// - IConventionModelBuilder Ignore([NotNull] Type type, bool fromDataAnnotation = false); + IConventionModelBuilder? Ignore([NotNull] Type type, bool fromDataAnnotation = false); /// /// Excludes the given entity type name from the model and prevents it from being added by convention. @@ -171,7 +173,7 @@ IConventionEntityTypeBuilder Entity( /// /// The same builder instance if the given entity type name was ignored, otherwise. /// - IConventionModelBuilder Ignore([NotNull] string typeName, bool fromDataAnnotation = false); + IConventionModelBuilder? Ignore([NotNull] string typeName, bool fromDataAnnotation = false); /// /// Removes the given entity type from the model. @@ -181,7 +183,7 @@ IConventionEntityTypeBuilder Entity( /// /// The same builder instance if the given entity type was removed, otherwise. /// - IConventionModelBuilder HasNoEntityType([NotNull] IConventionEntityType entityType, bool fromDataAnnotation = false); + IConventionModelBuilder? HasNoEntityType([NotNull] IConventionEntityType entityType, bool fromDataAnnotation = false); /// /// Returns a value indicating whether the given entity type can be ignored from the current configuration source @@ -208,7 +210,7 @@ IConventionEntityTypeBuilder Entity( /// /// The same builder instance if the configuration was successful, otherwise. /// - IConventionModelBuilder HasChangeTrackingStrategy(ChangeTrackingStrategy? changeTrackingStrategy, bool fromDataAnnotation = false); + IConventionModelBuilder? HasChangeTrackingStrategy(ChangeTrackingStrategy? changeTrackingStrategy, bool fromDataAnnotation = false); /// /// Returns a value indicating whether the given change tracking strategy can be set from the current configuration source @@ -234,7 +236,7 @@ IConventionEntityTypeBuilder Entity( /// /// The same builder instance if the configuration was successful, otherwise. /// - IConventionModelBuilder UsePropertyAccessMode(PropertyAccessMode? propertyAccessMode, bool fromDataAnnotation = false); + IConventionModelBuilder? UsePropertyAccessMode(PropertyAccessMode? propertyAccessMode, bool fromDataAnnotation = false); /// /// Returns a value indicating whether the given property access mode can be set from the current configuration source diff --git a/src/EFCore/Metadata/Builders/IConventionNavigationBuilder.cs b/src/EFCore/Metadata/Builders/IConventionNavigationBuilder.cs index e3b8ece83c3..00d03efa3fe 100644 --- a/src/EFCore/Metadata/Builders/IConventionNavigationBuilder.cs +++ b/src/EFCore/Metadata/Builders/IConventionNavigationBuilder.cs @@ -4,6 +4,8 @@ using System.Reflection; using JetBrains.Annotations; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Builders { /// @@ -31,7 +33,7 @@ public interface IConventionNavigationBuilder : IConventionPropertyBaseBuilder /// The same builder instance if the configuration was applied, /// otherwise. /// - new IConventionNavigationBuilder HasField([CanBeNull] string fieldName, bool fromDataAnnotation = false); + new IConventionNavigationBuilder? HasField([CanBeNull] string? fieldName, bool fromDataAnnotation = false); /// /// Sets the backing field to use for this navigation. @@ -42,7 +44,7 @@ public interface IConventionNavigationBuilder : IConventionPropertyBaseBuilder /// The same builder instance if the configuration was applied, /// otherwise. /// - new IConventionNavigationBuilder HasField([CanBeNull] FieldInfo fieldInfo, bool fromDataAnnotation = false); + new IConventionNavigationBuilder? HasField([CanBeNull] FieldInfo? fieldInfo, bool fromDataAnnotation = false); /// /// Sets the to use for this navigation. @@ -53,7 +55,7 @@ public interface IConventionNavigationBuilder : IConventionPropertyBaseBuilder /// The same builder instance if the configuration was applied, /// otherwise. /// - new IConventionNavigationBuilder UsePropertyAccessMode(PropertyAccessMode? propertyAccessMode, bool fromDataAnnotation = false); + new IConventionNavigationBuilder? UsePropertyAccessMode(PropertyAccessMode? propertyAccessMode, bool fromDataAnnotation = false); /// /// Returns a value indicating whether this navigation can be configured to be automatically included in a query @@ -73,7 +75,7 @@ public interface IConventionNavigationBuilder : IConventionPropertyBaseBuilder /// The same builder instance if the configuration was applied, /// otherwise. /// - IConventionNavigationBuilder AutoInclude(bool? autoInclude, bool fromDataAnnotation = false); + IConventionNavigationBuilder? AutoInclude(bool? autoInclude, bool fromDataAnnotation = false); /// /// Returns a value indicating whether this navigation requiredness can be configured @@ -95,6 +97,6 @@ public interface IConventionNavigationBuilder : IConventionPropertyBaseBuilder /// /// The same builder instance if the requiredness was configured, otherwise. /// - IConventionNavigationBuilder IsRequired(bool? required, bool fromDataAnnotation = false); + IConventionNavigationBuilder? IsRequired(bool? required, bool fromDataAnnotation = false); } } diff --git a/src/EFCore/Metadata/Builders/IConventionOwnedEntityTypeBuilder.cs b/src/EFCore/Metadata/Builders/IConventionOwnedEntityTypeBuilder.cs index c90f9ba22ba..2a332e309ad 100644 --- a/src/EFCore/Metadata/Builders/IConventionOwnedEntityTypeBuilder.cs +++ b/src/EFCore/Metadata/Builders/IConventionOwnedEntityTypeBuilder.cs @@ -1,6 +1,8 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Builders { /// diff --git a/src/EFCore/Metadata/Builders/IConventionPropertyBaseBuilder.cs b/src/EFCore/Metadata/Builders/IConventionPropertyBaseBuilder.cs index c614176b8ee..b0855a24ba8 100644 --- a/src/EFCore/Metadata/Builders/IConventionPropertyBaseBuilder.cs +++ b/src/EFCore/Metadata/Builders/IConventionPropertyBaseBuilder.cs @@ -4,6 +4,8 @@ using System.Reflection; using JetBrains.Annotations; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Builders { /// @@ -31,7 +33,7 @@ public interface IConventionPropertyBaseBuilder : IConventionAnnotatableBuilder /// The same builder instance if the configuration was applied, /// otherwise. /// - IConventionPropertyBaseBuilder HasField([CanBeNull] string fieldName, bool fromDataAnnotation = false); + IConventionPropertyBaseBuilder? HasField([CanBeNull] string? fieldName, bool fromDataAnnotation = false); /// /// Sets the backing field to use for this property-like object. @@ -42,7 +44,7 @@ public interface IConventionPropertyBaseBuilder : IConventionAnnotatableBuilder /// The same builder instance if the configuration was applied, /// otherwise. /// - IConventionPropertyBaseBuilder HasField([CanBeNull] FieldInfo fieldInfo, bool fromDataAnnotation = false); + IConventionPropertyBaseBuilder? HasField([CanBeNull] FieldInfo? fieldInfo, bool fromDataAnnotation = false); /// /// Returns a value indicating whether the backing field can be set for this property-like object @@ -51,7 +53,7 @@ public interface IConventionPropertyBaseBuilder : IConventionAnnotatableBuilder /// The field name. /// Indicates whether the configuration was specified using a data annotation. /// if the backing field can be set for this property-like object. - bool CanSetField([CanBeNull] string fieldName, bool fromDataAnnotation = false); + bool CanSetField([CanBeNull] string? fieldName, bool fromDataAnnotation = false); /// /// Returns a value indicating whether the backing field can be set for this property-like object @@ -60,7 +62,7 @@ public interface IConventionPropertyBaseBuilder : IConventionAnnotatableBuilder /// The field. /// Indicates whether the configuration was specified using a data annotation. /// if the backing field can be set for this property-like object. - bool CanSetField([CanBeNull] FieldInfo fieldInfo, bool fromDataAnnotation = false); + bool CanSetField([CanBeNull] FieldInfo? fieldInfo, bool fromDataAnnotation = false); /// /// Sets the to use for this property-like object. @@ -71,7 +73,7 @@ public interface IConventionPropertyBaseBuilder : IConventionAnnotatableBuilder /// The same builder instance if the configuration was applied, /// otherwise. /// - IConventionPropertyBaseBuilder UsePropertyAccessMode(PropertyAccessMode? propertyAccessMode, bool fromDataAnnotation = false); + IConventionPropertyBaseBuilder? UsePropertyAccessMode(PropertyAccessMode? propertyAccessMode, bool fromDataAnnotation = false); /// /// Returns a value indicating whether the can be set for this property-like object diff --git a/src/EFCore/Metadata/Builders/IConventionPropertyBuilder.cs b/src/EFCore/Metadata/Builders/IConventionPropertyBuilder.cs index f207465ff08..c72d2f6a305 100644 --- a/src/EFCore/Metadata/Builders/IConventionPropertyBuilder.cs +++ b/src/EFCore/Metadata/Builders/IConventionPropertyBuilder.cs @@ -9,6 +9,8 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; using Microsoft.EntityFrameworkCore.ValueGeneration; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Builders { /// @@ -41,7 +43,7 @@ public interface IConventionPropertyBuilder : IConventionPropertyBaseBuilder /// The same builder instance if the requiredness was configured, /// otherwise. /// - IConventionPropertyBuilder IsRequired(bool? required, bool fromDataAnnotation = false); + IConventionPropertyBuilder? IsRequired(bool? required, bool fromDataAnnotation = false); /// /// Returns a value indicating whether this property requiredness can be configured @@ -71,7 +73,7 @@ public interface IConventionPropertyBuilder : IConventionPropertyBaseBuilder /// The same builder instance if the requiredness was configured, /// otherwise. /// - IConventionPropertyBuilder ValueGenerated(ValueGenerated? valueGenerated, bool fromDataAnnotation = false); + IConventionPropertyBuilder? ValueGenerated(ValueGenerated? valueGenerated, bool fromDataAnnotation = false); /// /// Returns a value indicating whether the property value generation can be configured @@ -98,7 +100,7 @@ public interface IConventionPropertyBuilder : IConventionPropertyBaseBuilder /// The same builder instance if the configuration was applied, /// otherwise. /// - IConventionPropertyBuilder IsConcurrencyToken(bool? concurrencyToken, bool fromDataAnnotation = false); + IConventionPropertyBuilder? IsConcurrencyToken(bool? concurrencyToken, bool fromDataAnnotation = false); /// /// Returns a value indicating whether the property can be configured as a concurrency token @@ -118,7 +120,7 @@ public interface IConventionPropertyBuilder : IConventionPropertyBaseBuilder /// The same builder instance if the configuration was applied, /// otherwise. /// - new IConventionPropertyBuilder HasField([CanBeNull] string fieldName, bool fromDataAnnotation = false); + new IConventionPropertyBuilder? HasField([CanBeNull] string? fieldName, bool fromDataAnnotation = false); /// /// Sets the backing field to use for this property. @@ -129,7 +131,7 @@ public interface IConventionPropertyBuilder : IConventionPropertyBaseBuilder /// The same builder instance if the configuration was applied, /// otherwise. /// - new IConventionPropertyBuilder HasField([CanBeNull] FieldInfo fieldInfo, bool fromDataAnnotation = false); + new IConventionPropertyBuilder? HasField([CanBeNull] FieldInfo? fieldInfo, bool fromDataAnnotation = false); /// /// Sets the to use for this property. @@ -140,7 +142,7 @@ public interface IConventionPropertyBuilder : IConventionPropertyBaseBuilder /// The same builder instance if the configuration was applied, /// otherwise. /// - new IConventionPropertyBuilder UsePropertyAccessMode(PropertyAccessMode? propertyAccessMode, bool fromDataAnnotation = false); + new IConventionPropertyBuilder? UsePropertyAccessMode(PropertyAccessMode? propertyAccessMode, bool fromDataAnnotation = false); /// /// Configures the maximum length of data that can be stored in this property. @@ -151,7 +153,7 @@ public interface IConventionPropertyBuilder : IConventionPropertyBaseBuilder /// The same builder instance if the configuration was applied, /// otherwise. /// - IConventionPropertyBuilder HasMaxLength(int? maxLength, bool fromDataAnnotation = false); + IConventionPropertyBuilder? HasMaxLength(int? maxLength, bool fromDataAnnotation = false); /// /// Returns a value indicating whether the maximum length of data allowed can be set for this property @@ -171,7 +173,7 @@ public interface IConventionPropertyBuilder : IConventionPropertyBaseBuilder /// The same builder instance if the configuration was applied, /// otherwise. /// - IConventionPropertyBuilder IsUnicode(bool? unicode, bool fromDataAnnotation = false); + IConventionPropertyBuilder? IsUnicode(bool? unicode, bool fromDataAnnotation = false); /// /// Returns a value indicating whether the property can be configured as capable of persisting unicode characters @@ -191,7 +193,7 @@ public interface IConventionPropertyBuilder : IConventionPropertyBaseBuilder /// The same builder instance if the configuration was applied, /// otherwise. /// - IConventionPropertyBuilder HasPrecision(int? precision, bool fromDataAnnotation = false); + IConventionPropertyBuilder? HasPrecision(int? precision, bool fromDataAnnotation = false); /// /// Returns a value indicating whether the precision of data allowed can be set for this property @@ -211,7 +213,7 @@ public interface IConventionPropertyBuilder : IConventionPropertyBaseBuilder /// The same builder instance if the configuration was applied, /// otherwise. /// - IConventionPropertyBuilder HasScale(int? scale, bool fromDataAnnotation = false); + IConventionPropertyBuilder? HasScale(int? scale, bool fromDataAnnotation = false); /// /// Returns a value indicating whether the scale of data allowed can be set for this property @@ -234,7 +236,7 @@ public interface IConventionPropertyBuilder : IConventionPropertyBaseBuilder /// The same builder instance if the configuration was applied, /// otherwise. /// - IConventionPropertyBuilder BeforeSave(PropertySaveBehavior? behavior, bool fromDataAnnotation = false); + IConventionPropertyBuilder? BeforeSave(PropertySaveBehavior? behavior, bool fromDataAnnotation = false); /// /// Returns a value indicating whether the ability to be modified before the entity is saved to the database @@ -262,7 +264,7 @@ public interface IConventionPropertyBuilder : IConventionPropertyBaseBuilder /// The same builder instance if the configuration was applied, /// otherwise. /// - IConventionPropertyBuilder AfterSave(PropertySaveBehavior? behavior, bool fromDataAnnotation = false); + IConventionPropertyBuilder? AfterSave(PropertySaveBehavior? behavior, bool fromDataAnnotation = false); /// /// Returns a value indicating whether the ability to be modified after the entity is saved to the database @@ -287,7 +289,7 @@ public interface IConventionPropertyBuilder : IConventionPropertyBaseBuilder /// The same builder instance if the configuration was applied, /// otherwise. /// - IConventionPropertyBuilder HasValueGenerator([CanBeNull] Type valueGeneratorType, bool fromDataAnnotation = false); + IConventionPropertyBuilder? HasValueGenerator([CanBeNull] Type? valueGeneratorType, bool fromDataAnnotation = false); /// /// Configures the that will generate values for this property. @@ -298,8 +300,8 @@ public interface IConventionPropertyBuilder : IConventionPropertyBaseBuilder /// The same builder instance if the configuration was applied, /// otherwise. /// - IConventionPropertyBuilder HasValueGenerator( - [CanBeNull] Func factory, + IConventionPropertyBuilder? HasValueGenerator( + [CanBeNull] Func? factory, bool fromDataAnnotation = false); /// @@ -316,7 +318,7 @@ IConventionPropertyBuilder HasValueGenerator( /// if the can be configured for this property. /// bool CanSetValueGenerator( - [CanBeNull] Func factory, + [CanBeNull] Func? factory, bool fromDataAnnotation = false); /// @@ -329,7 +331,7 @@ bool CanSetValueGenerator( /// The same builder instance if the configuration was applied, /// otherwise. /// - IConventionPropertyBuilder HasConversion([CanBeNull] ValueConverter converter, bool fromDataAnnotation = false); + IConventionPropertyBuilder? HasConversion([CanBeNull] ValueConverter? converter, bool fromDataAnnotation = false); /// /// Returns a value indicating whether the can be configured for this property @@ -340,7 +342,7 @@ bool CanSetValueGenerator( /// /// if the can be configured for this property. /// - bool CanSetConversion([CanBeNull] ValueConverter converter, bool fromDataAnnotation = false); + bool CanSetConversion([CanBeNull] ValueConverter? converter, bool fromDataAnnotation = false); /// /// Configures the property so that the property value is converted to the given type before @@ -352,7 +354,7 @@ bool CanSetValueGenerator( /// The same builder instance if the configuration was applied, /// otherwise. /// - IConventionPropertyBuilder HasConversion([CanBeNull] Type providerClrType, bool fromDataAnnotation = false); + IConventionPropertyBuilder? HasConversion([CanBeNull] Type? providerClrType, bool fromDataAnnotation = false); /// /// Returns a value indicating whether the given type to convert values to and from @@ -363,7 +365,7 @@ bool CanSetValueGenerator( /// /// if the given type to convert values to and from can be configured for this property. /// - bool CanSetConversion([CanBeNull] Type providerClrType, bool fromDataAnnotation = false); + bool CanSetConversion([CanBeNull] Type? providerClrType, bool fromDataAnnotation = false); /// /// Configures the for this property. @@ -374,7 +376,7 @@ bool CanSetValueGenerator( /// The same builder instance if the configuration was applied, /// otherwise. /// - IConventionPropertyBuilder HasTypeMapping([NotNull] CoreTypeMapping typeMapping, bool fromDataAnnotation = false); + IConventionPropertyBuilder? HasTypeMapping([CanBeNull] CoreTypeMapping? typeMapping, bool fromDataAnnotation = false); /// /// Returns a value indicating whether the given @@ -396,7 +398,7 @@ bool CanSetValueGenerator( /// The same builder instance if the configuration was applied, /// otherwise. /// - IConventionPropertyBuilder HasValueComparer([CanBeNull] ValueComparer comparer, bool fromDataAnnotation = false); + IConventionPropertyBuilder? HasValueComparer([CanBeNull] ValueComparer? comparer, bool fromDataAnnotation = false); /// /// Returns a value indicating whether the given @@ -407,7 +409,7 @@ bool CanSetValueGenerator( /// /// if the given can be configured for this property. /// - bool CanSetValueComparer([CanBeNull] ValueComparer comparer, bool fromDataAnnotation = false); + bool CanSetValueComparer([CanBeNull] ValueComparer? comparer, bool fromDataAnnotation = false); /// /// Configures the to be used for key comparisons for this property. @@ -419,7 +421,7 @@ bool CanSetValueGenerator( /// otherwise. /// [Obsolete("Use HasValueComparer. Only a single value comparer is allowed for a given property.")] - IConventionPropertyBuilder HasKeyValueComparer([CanBeNull] ValueComparer comparer, bool fromDataAnnotation = false); + IConventionPropertyBuilder? HasKeyValueComparer([CanBeNull] ValueComparer? comparer, bool fromDataAnnotation = false); /// /// Returns a value indicating whether the given @@ -431,7 +433,7 @@ bool CanSetValueGenerator( /// if the given can be configured for this property. /// [Obsolete("Use CanSetValueComparer. Only a single value comparer is allowed for a given property.")] - bool CanSetKeyValueComparer([CanBeNull] ValueComparer comparer, bool fromDataAnnotation = false); + bool CanSetKeyValueComparer([CanBeNull] ValueComparer? comparer, bool fromDataAnnotation = false); /// /// Configures the to be used for structural comparisons for this property. @@ -443,7 +445,7 @@ bool CanSetValueGenerator( /// otherwise. /// [Obsolete("Use HasValueComparer. Only a single value comparer is allowed for a given property.")] - IConventionPropertyBuilder HasStructuralValueComparer([CanBeNull] ValueComparer comparer, bool fromDataAnnotation = false); + IConventionPropertyBuilder? HasStructuralValueComparer([CanBeNull] ValueComparer? comparer, bool fromDataAnnotation = false); /// /// Returns a value indicating whether the given @@ -455,6 +457,6 @@ bool CanSetValueGenerator( /// if the given can be configured for this property. /// [Obsolete("Use CanSetValueComparer. Only a single value comparer is allowed for a given property.")] - bool CanSetStructuralValueComparer([CanBeNull] ValueComparer comparer, bool fromDataAnnotation = false); + bool CanSetStructuralValueComparer([CanBeNull] ValueComparer? comparer, bool fromDataAnnotation = false); } } diff --git a/src/EFCore/Metadata/Builders/IConventionServicePropertyBuilder.cs b/src/EFCore/Metadata/Builders/IConventionServicePropertyBuilder.cs index 7ccc88b686d..63ebec62834 100644 --- a/src/EFCore/Metadata/Builders/IConventionServicePropertyBuilder.cs +++ b/src/EFCore/Metadata/Builders/IConventionServicePropertyBuilder.cs @@ -4,6 +4,8 @@ using System.Reflection; using JetBrains.Annotations; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Builders { /// @@ -31,7 +33,7 @@ public interface IConventionServicePropertyBuilder : IConventionPropertyBaseBuil /// The same builder instance if the configuration was applied, /// otherwise. /// - new IConventionServicePropertyBuilder HasField([CanBeNull] string fieldName, bool fromDataAnnotation = false); + new IConventionServicePropertyBuilder? HasField([CanBeNull] string? fieldName, bool fromDataAnnotation = false); /// /// Sets the backing field to use for this property. @@ -42,7 +44,7 @@ public interface IConventionServicePropertyBuilder : IConventionPropertyBaseBuil /// The same builder instance if the configuration was applied, /// otherwise. /// - new IConventionServicePropertyBuilder HasField([CanBeNull] FieldInfo fieldInfo, bool fromDataAnnotation = false); + new IConventionServicePropertyBuilder? HasField([CanBeNull] FieldInfo? fieldInfo, bool fromDataAnnotation = false); /// /// Sets the to use for this property. @@ -53,7 +55,7 @@ public interface IConventionServicePropertyBuilder : IConventionPropertyBaseBuil /// The same builder instance if the configuration was applied, /// otherwise. /// - new IConventionServicePropertyBuilder UsePropertyAccessMode( + new IConventionServicePropertyBuilder? UsePropertyAccessMode( PropertyAccessMode? propertyAccessMode, bool fromDataAnnotation = false); @@ -66,8 +68,8 @@ public interface IConventionServicePropertyBuilder : IConventionPropertyBaseBuil /// The same builder instance if the configuration was applied, /// otherwise. /// - IConventionServicePropertyBuilder HasParameterBinding( - [CanBeNull] ServiceParameterBinding parameterBinding, + IConventionServicePropertyBuilder? HasParameterBinding( + [CanBeNull] ServiceParameterBinding? parameterBinding, bool fromDataAnnotation = false); /// @@ -77,6 +79,6 @@ IConventionServicePropertyBuilder HasParameterBinding( /// The parameter binding. /// Indicates whether the configuration was specified using a data annotation. /// if the can be set for this property. - bool CanSetParameterBinding([CanBeNull] ServiceParameterBinding parameterBinding, bool fromDataAnnotation = false); + bool CanSetParameterBinding([CanBeNull] ServiceParameterBinding? parameterBinding, bool fromDataAnnotation = false); } } diff --git a/src/EFCore/Metadata/Builders/IConventionSkipNavigationBuilder.cs b/src/EFCore/Metadata/Builders/IConventionSkipNavigationBuilder.cs index 43654470e6b..1c0f31e4cf2 100644 --- a/src/EFCore/Metadata/Builders/IConventionSkipNavigationBuilder.cs +++ b/src/EFCore/Metadata/Builders/IConventionSkipNavigationBuilder.cs @@ -4,6 +4,8 @@ using System.Reflection; using JetBrains.Annotations; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Builders { /// @@ -31,7 +33,7 @@ public interface IConventionSkipNavigationBuilder : IConventionPropertyBaseBuild /// The same builder instance if the configuration was applied, /// otherwise. /// - new IConventionSkipNavigationBuilder HasField([CanBeNull] string fieldName, bool fromDataAnnotation = false); + new IConventionSkipNavigationBuilder? HasField([CanBeNull] string? fieldName, bool fromDataAnnotation = false); /// /// Sets the backing field to use for this navigation. @@ -42,7 +44,7 @@ public interface IConventionSkipNavigationBuilder : IConventionPropertyBaseBuild /// The same builder instance if the configuration was applied, /// otherwise. /// - new IConventionSkipNavigationBuilder HasField([CanBeNull] FieldInfo fieldInfo, bool fromDataAnnotation = false); + new IConventionSkipNavigationBuilder? HasField([CanBeNull] FieldInfo? fieldInfo, bool fromDataAnnotation = false); /// /// Sets the to use for this navigation. @@ -53,7 +55,7 @@ public interface IConventionSkipNavigationBuilder : IConventionPropertyBaseBuild /// The same builder instance if the configuration was applied, /// otherwise. /// - new IConventionSkipNavigationBuilder UsePropertyAccessMode(PropertyAccessMode? propertyAccessMode, bool fromDataAnnotation = false); + new IConventionSkipNavigationBuilder? UsePropertyAccessMode(PropertyAccessMode? propertyAccessMode, bool fromDataAnnotation = false); /// /// Sets the foreign key. @@ -66,7 +68,7 @@ public interface IConventionSkipNavigationBuilder : IConventionPropertyBaseBuild /// The same builder instance if the configuration was applied, /// otherwise. /// - IConventionSkipNavigationBuilder HasForeignKey([CanBeNull] IConventionForeignKey foreignKey, bool fromDataAnnotation = false); + IConventionSkipNavigationBuilder? HasForeignKey([CanBeNull] IConventionForeignKey? foreignKey, bool fromDataAnnotation = false); /// /// Returns a value indicating whether the can be set for this navigation @@ -77,7 +79,7 @@ public interface IConventionSkipNavigationBuilder : IConventionPropertyBaseBuild /// /// Indicates whether the configuration was specified using a data annotation. /// if the can be set for this property. - bool CanSetForeignKey([CanBeNull] IConventionForeignKey foreignKey, bool fromDataAnnotation = false); + bool CanSetForeignKey([CanBeNull] IConventionForeignKey? foreignKey, bool fromDataAnnotation = false); /// /// Sets the inverse skip navigation. @@ -90,7 +92,7 @@ public interface IConventionSkipNavigationBuilder : IConventionPropertyBaseBuild /// The same builder instance if the configuration was applied, /// otherwise. /// - IConventionSkipNavigationBuilder HasInverse([CanBeNull] IConventionSkipNavigation inverse, bool fromDataAnnotation = false); + IConventionSkipNavigationBuilder? HasInverse([CanBeNull] IConventionSkipNavigation? inverse, bool fromDataAnnotation = false); /// /// Returns a value indicating whether the can be set for this navigation @@ -101,7 +103,7 @@ public interface IConventionSkipNavigationBuilder : IConventionPropertyBaseBuild /// /// Indicates whether the configuration was specified using a data annotation. /// if the can be set for this property. - bool CanSetInverse([CanBeNull] IConventionSkipNavigation inverse, bool fromDataAnnotation = false); + bool CanSetInverse([CanBeNull] IConventionSkipNavigation? inverse, bool fromDataAnnotation = false); /// /// Returns a value indicating whether this navigation can be configured to be automatically included in a query @@ -121,6 +123,6 @@ public interface IConventionSkipNavigationBuilder : IConventionPropertyBaseBuild /// The same builder instance if the configuration was applied, /// otherwise. /// - IConventionSkipNavigationBuilder AutoInclude(bool? autoInclude, bool fromDataAnnotation = false); + IConventionSkipNavigationBuilder? AutoInclude(bool? autoInclude, bool fromDataAnnotation = false); } } diff --git a/src/EFCore/Metadata/Builders/IndexBuilder.cs b/src/EFCore/Metadata/Builders/IndexBuilder.cs index 4785b569748..b2140939eab 100644 --- a/src/EFCore/Metadata/Builders/IndexBuilder.cs +++ b/src/EFCore/Metadata/Builders/IndexBuilder.cs @@ -7,6 +7,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Internal; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Builders { /// @@ -83,7 +85,7 @@ public virtual IndexBuilder IsUnique(bool unique = true) /// /// A string that represents the current object. [EditorBrowsable(EditorBrowsableState.Never)] - public override string ToString() + public override string? ToString() => base.ToString(); /// @@ -93,7 +95,7 @@ public override string ToString() /// if the specified object is equal to the current object; otherwise, . [EditorBrowsable(EditorBrowsableState.Never)] // ReSharper disable once BaseObjectEqualsIsObjectEquals - public override bool Equals(object obj) + public override bool Equals(object? obj) => base.Equals(obj); /// diff --git a/src/EFCore/Metadata/Builders/IndexBuilder`.cs b/src/EFCore/Metadata/Builders/IndexBuilder`.cs index d964c742a0c..ea539882a55 100644 --- a/src/EFCore/Metadata/Builders/IndexBuilder`.cs +++ b/src/EFCore/Metadata/Builders/IndexBuilder`.cs @@ -4,6 +4,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Infrastructure; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Builders { /// diff --git a/src/EFCore/Metadata/Builders/InvertibleRelationshipBuilderBase.cs b/src/EFCore/Metadata/Builders/InvertibleRelationshipBuilderBase.cs index 55a8fac55c5..fb83b34240b 100644 --- a/src/EFCore/Metadata/Builders/InvertibleRelationshipBuilderBase.cs +++ b/src/EFCore/Metadata/Builders/InvertibleRelationshipBuilderBase.cs @@ -10,6 +10,8 @@ using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata.Internal; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Builders { /// @@ -17,10 +19,12 @@ namespace Microsoft.EntityFrameworkCore.Metadata.Builders /// public abstract class InvertibleRelationshipBuilderBase : IInfrastructure { - private readonly IReadOnlyList _foreignKeyProperties; - private readonly IReadOnlyList _principalKeyProperties; + private readonly IReadOnlyList? _foreignKeyProperties; + private readonly IReadOnlyList? _principalKeyProperties; private readonly bool? _required; + // TODO-NULLABLE: Refactored the construction here, please confirm it makes sense + /// /// 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 @@ -32,8 +36,9 @@ protected InvertibleRelationshipBuilderBase( [NotNull] IMutableEntityType declaringEntityType, [NotNull] IMutableEntityType relatedEntityType, [NotNull] IMutableForeignKey foreignKey) - : this(((ForeignKey)foreignKey).Builder, null) { + Builder = ((ForeignKey)foreignKey).Builder; + DeclaringEntityType = declaringEntityType; RelatedEntityType = relatedEntityType; } @@ -47,7 +52,7 @@ protected InvertibleRelationshipBuilderBase( [EntityFrameworkInternal] protected InvertibleRelationshipBuilderBase( [NotNull] InternalForeignKeyBuilder builder, - [CanBeNull] InvertibleRelationshipBuilderBase oldBuilder, + [NotNull] InvertibleRelationshipBuilderBase oldBuilder, bool inverted = false, bool foreignKeySet = false, bool principalKeySet = false, @@ -55,41 +60,38 @@ protected InvertibleRelationshipBuilderBase( { Builder = builder; - if (oldBuilder != null) + if (inverted) { - if (inverted) + if (oldBuilder._foreignKeyProperties != null + || oldBuilder._principalKeyProperties != null) { - if (oldBuilder._foreignKeyProperties != null - || oldBuilder._principalKeyProperties != null) - { - throw new InvalidOperationException(CoreStrings.RelationshipCannotBeInverted); - } + throw new InvalidOperationException(CoreStrings.RelationshipCannotBeInverted); } - - DeclaringEntityType = oldBuilder.DeclaringEntityType; - RelatedEntityType = oldBuilder.RelatedEntityType; - - _foreignKeyProperties = foreignKeySet - ? builder.Metadata.Properties - : oldBuilder._foreignKeyProperties; - _principalKeyProperties = principalKeySet - ? builder.Metadata.PrincipalKey.Properties - : oldBuilder._principalKeyProperties; - _required = requiredSet - ? builder.Metadata.IsRequired - : oldBuilder._required; - - var foreignKey = builder.Metadata; - ForeignKey.AreCompatible( - foreignKey.PrincipalEntityType, - foreignKey.DeclaringEntityType, - foreignKey.DependentToPrincipal?.GetIdentifyingMemberInfo(), - foreignKey.PrincipalToDependent?.GetIdentifyingMemberInfo(), - _foreignKeyProperties, - _principalKeyProperties, - foreignKey.IsUnique, - shouldThrow: true); } + + DeclaringEntityType = oldBuilder.DeclaringEntityType; + RelatedEntityType = oldBuilder.RelatedEntityType; + + _foreignKeyProperties = foreignKeySet + ? builder.Metadata.Properties + : oldBuilder._foreignKeyProperties; + _principalKeyProperties = principalKeySet + ? builder.Metadata.PrincipalKey.Properties + : oldBuilder._principalKeyProperties; + _required = requiredSet + ? builder.Metadata.IsRequired + : oldBuilder._required; + + var foreignKey = builder.Metadata; + ForeignKey.AreCompatible( + foreignKey.PrincipalEntityType, + foreignKey.DeclaringEntityType, + foreignKey.DependentToPrincipal?.GetIdentifyingMemberInfo(), + foreignKey.PrincipalToDependent?.GetIdentifyingMemberInfo(), + _foreignKeyProperties, + _principalKeyProperties, + foreignKey.IsUnique, + shouldThrow: true); } /// @@ -131,7 +133,7 @@ public virtual IMutableForeignKey Metadata /// /// A string that represents the current object. [EditorBrowsable(EditorBrowsableState.Never)] - public override string ToString() + public override string? ToString() => base.ToString(); /// @@ -140,7 +142,7 @@ public override string ToString() /// The object to compare with the current object. /// if the specified object is equal to the current object; otherwise, . [EditorBrowsable(EditorBrowsableState.Never)] - public override bool Equals(object obj) + public override bool Equals(object? obj) => base.Equals(obj); /// diff --git a/src/EFCore/Metadata/Builders/KeyBuilder.cs b/src/EFCore/Metadata/Builders/KeyBuilder.cs index 2736c4d6046..70cd08aacad 100644 --- a/src/EFCore/Metadata/Builders/KeyBuilder.cs +++ b/src/EFCore/Metadata/Builders/KeyBuilder.cs @@ -7,6 +7,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Internal; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Builders { /// @@ -73,7 +75,7 @@ public virtual KeyBuilder HasAnnotation([NotNull] string annotation, [NotNull] o /// /// A string that represents the current object. [EditorBrowsable(EditorBrowsableState.Never)] - public override string ToString() + public override string? ToString() => base.ToString(); /// @@ -83,7 +85,7 @@ public override string ToString() /// if the specified object is equal to the current object; otherwise, . [EditorBrowsable(EditorBrowsableState.Never)] // ReSharper disable once BaseObjectEqualsIsObjectEquals - public override bool Equals(object obj) + public override bool Equals(object? obj) => base.Equals(obj); /// diff --git a/src/EFCore/Metadata/Builders/KeyBuilder`.cs b/src/EFCore/Metadata/Builders/KeyBuilder`.cs index 2f548a6cf0d..66409e780d8 100644 --- a/src/EFCore/Metadata/Builders/KeyBuilder`.cs +++ b/src/EFCore/Metadata/Builders/KeyBuilder`.cs @@ -4,6 +4,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Infrastructure; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Builders { /// diff --git a/src/EFCore/Metadata/Builders/NavigationBuilder.cs b/src/EFCore/Metadata/Builders/NavigationBuilder.cs index 1d10d03f3e8..4e052bf1cc0 100644 --- a/src/EFCore/Metadata/Builders/NavigationBuilder.cs +++ b/src/EFCore/Metadata/Builders/NavigationBuilder.cs @@ -9,6 +9,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Internal; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Builders { /// @@ -20,7 +22,7 @@ namespace Microsoft.EntityFrameworkCore.Metadata.Builders /// and it is not designed to be directly constructed in your application code. /// /// - public class NavigationBuilder : IInfrastructure, IInfrastructure + public class NavigationBuilder : IInfrastructure, IInfrastructure { /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -42,9 +44,9 @@ public NavigationBuilder([NotNull] IMutableNavigationBase navigationOrSkipNaviga "Expected either a Navigation or SkipNavigation"); } - private InternalNavigationBuilder InternalNavigationBuilder { get; set; } + private InternalNavigationBuilder? InternalNavigationBuilder { get; set; } - private InternalSkipNavigationBuilder InternalSkipNavigationBuilder { get; } + private InternalSkipNavigationBuilder? InternalSkipNavigationBuilder { get; } /// /// The navigation being configured. @@ -70,7 +72,7 @@ public virtual NavigationBuilder HasAnnotation([NotNull] string annotation, [Not } else { - InternalSkipNavigationBuilder.HasAnnotation(annotation, value, ConfigurationSource.Explicit); + InternalSkipNavigationBuilder!.HasAnnotation(annotation, value, ConfigurationSource.Explicit); } return this; @@ -101,7 +103,7 @@ public virtual NavigationBuilder UsePropertyAccessMode(PropertyAccessMode proper } else { - InternalSkipNavigationBuilder.UsePropertyAccessMode(propertyAccessMode, ConfigurationSource.Explicit); + InternalSkipNavigationBuilder!.UsePropertyAccessMode(propertyAccessMode, ConfigurationSource.Explicit); } return this; @@ -112,7 +114,7 @@ public virtual NavigationBuilder UsePropertyAccessMode(PropertyAccessMode proper /// /// The name of the field to use for this navigation property. /// The same builder instance so that multiple configuration calls can be chained. - public virtual NavigationBuilder HasField([CanBeNull] string fieldName) + public virtual NavigationBuilder HasField([CanBeNull] string? fieldName) { if (InternalNavigationBuilder != null) { @@ -120,7 +122,7 @@ public virtual NavigationBuilder HasField([CanBeNull] string fieldName) } else { - InternalSkipNavigationBuilder.HasField(fieldName, ConfigurationSource.Explicit); + InternalSkipNavigationBuilder!.HasField(fieldName, ConfigurationSource.Explicit); } return this; @@ -139,7 +141,7 @@ public virtual NavigationBuilder AutoInclude(bool autoInclude = true) } else { - InternalSkipNavigationBuilder.AutoInclude(autoInclude, ConfigurationSource.Explicit); + InternalSkipNavigationBuilder!.AutoInclude(autoInclude, ConfigurationSource.Explicit); } return this; @@ -160,7 +162,7 @@ public virtual NavigationBuilder IsRequired(bool required = true) { throw new InvalidOperationException( CoreStrings.RequiredSkipNavigation( - InternalSkipNavigationBuilder.Metadata.DeclaringEntityType.DisplayName(), + InternalSkipNavigationBuilder!.Metadata.DeclaringEntityType.DisplayName(), InternalSkipNavigationBuilder.Metadata.Name)); } @@ -170,13 +172,13 @@ public virtual NavigationBuilder IsRequired(bool required = true) /// /// The internal builder being used to configure the skip navigation. /// - IConventionSkipNavigationBuilder IInfrastructure.Instance + IConventionSkipNavigationBuilder? IInfrastructure.Instance => InternalSkipNavigationBuilder; /// /// The internal builder being used to configure the navigation. /// - IConventionNavigationBuilder IInfrastructure.Instance + IConventionNavigationBuilder? IInfrastructure.Instance => InternalNavigationBuilder; #region Hidden System.Object members @@ -186,7 +188,7 @@ IConventionNavigationBuilder IInfrastructure.Insta /// /// A string that represents the current object. [EditorBrowsable(EditorBrowsableState.Never)] - public override string ToString() + public override string? ToString() => base.ToString(); /// @@ -196,7 +198,7 @@ public override string ToString() /// if the specified object is equal to the current object; otherwise, . [EditorBrowsable(EditorBrowsableState.Never)] // ReSharper disable once BaseObjectEqualsIsObjectEquals - public override bool Equals(object obj) + public override bool Equals(object? obj) => base.Equals(obj); /// diff --git a/src/EFCore/Metadata/Builders/NavigationBuilder`.cs b/src/EFCore/Metadata/Builders/NavigationBuilder`.cs index f37bc01fc78..51f6d7d44f4 100644 --- a/src/EFCore/Metadata/Builders/NavigationBuilder`.cs +++ b/src/EFCore/Metadata/Builders/NavigationBuilder`.cs @@ -5,6 +5,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Infrastructure; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Builders { /// @@ -68,7 +70,7 @@ public NavigationBuilder([NotNull] IMutableNavigationBase navigationOrSkipNaviga /// /// The name of the field to use for this navigation property. /// The same builder instance so that multiple configuration calls can be chained. - public new virtual NavigationBuilder HasField([CanBeNull] string fieldName) + public new virtual NavigationBuilder HasField([CanBeNull] string? fieldName) => (NavigationBuilder)base.HasField(fieldName); /// @@ -94,7 +96,7 @@ public NavigationBuilder([NotNull] IMutableNavigationBase navigationOrSkipNaviga /// /// A string that represents the current object. [EditorBrowsable(EditorBrowsableState.Never)] - public override string ToString() + public override string? ToString() => base.ToString(); /// @@ -104,7 +106,7 @@ public override string ToString() /// if the specified object is equal to the current object; otherwise, . [EditorBrowsable(EditorBrowsableState.Never)] // ReSharper disable once BaseObjectEqualsIsObjectEquals - public override bool Equals(object obj) + public override bool Equals(object? obj) => base.Equals(obj); /// diff --git a/src/EFCore/Metadata/Builders/OwnedEntityTypeBuilder.cs b/src/EFCore/Metadata/Builders/OwnedEntityTypeBuilder.cs index 6e1a3a0f6d3..6d429207006 100644 --- a/src/EFCore/Metadata/Builders/OwnedEntityTypeBuilder.cs +++ b/src/EFCore/Metadata/Builders/OwnedEntityTypeBuilder.cs @@ -4,6 +4,8 @@ using System.ComponentModel; using Microsoft.EntityFrameworkCore.Infrastructure; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Builders { /// @@ -32,7 +34,7 @@ public OwnedEntityTypeBuilder() /// /// A string that represents the current object. [EditorBrowsable(EditorBrowsableState.Never)] - public override string ToString() + public override string? ToString() => base.ToString(); /// @@ -41,7 +43,7 @@ public override string ToString() /// The object to compare with the current object. /// if the specified object is equal to the current object; otherwise, . [EditorBrowsable(EditorBrowsableState.Never)] - public override bool Equals(object obj) + public override bool Equals(object? obj) => base.Equals(obj); /// diff --git a/src/EFCore/Metadata/Builders/OwnedEntityTypeBuilder`.cs b/src/EFCore/Metadata/Builders/OwnedEntityTypeBuilder`.cs index 3e6a9f4f24c..2b33c747948 100644 --- a/src/EFCore/Metadata/Builders/OwnedEntityTypeBuilder`.cs +++ b/src/EFCore/Metadata/Builders/OwnedEntityTypeBuilder`.cs @@ -3,6 +3,8 @@ using Microsoft.EntityFrameworkCore.Infrastructure; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Builders { /// diff --git a/src/EFCore/Metadata/Builders/OwnedNavigationBuilder.cs b/src/EFCore/Metadata/Builders/OwnedNavigationBuilder.cs index 6a8d360fff1..ee741be4fab 100644 --- a/src/EFCore/Metadata/Builders/OwnedNavigationBuilder.cs +++ b/src/EFCore/Metadata/Builders/OwnedNavigationBuilder.cs @@ -10,6 +10,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Internal; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Builders { /// @@ -56,9 +58,9 @@ protected virtual InternalForeignKeyBuilder Builder { get { - if (_builder.Metadata.Builder == null) + if (!_builder.Metadata.IsInModel) { - _builder = PrincipalEntityType.FindNavigation(_builder.Metadata.PrincipalToDependent.Name)?.ForeignKey.Builder; + _builder = PrincipalEntityType.FindNavigation(_builder.Metadata.PrincipalToDependent!.Name)?.ForeignKey.Builder!; } return _builder; @@ -76,7 +78,7 @@ protected virtual InternalForeignKeyBuilder Builder [EntityFrameworkInternal] protected virtual T UpdateBuilder([NotNull] Func configure) { - IConventionForeignKey foreignKey = _builder.Metadata; + IConventionForeignKey? foreignKey = _builder.Metadata; var result = DependentEntityType.Model.Track(configure, ref foreignKey); if (foreignKey != null) { @@ -129,7 +131,7 @@ public virtual OwnedNavigationBuilder HasAnnotation([NotNull] string annotation, public virtual KeyBuilder HasKey([NotNull] params string[] propertyNames) => new( DependentEntityType.Builder.PrimaryKey( - Check.NotEmpty(propertyNames, nameof(propertyNames)), ConfigurationSource.Explicit).Metadata); + Check.NotEmpty(propertyNames, nameof(propertyNames)), ConfigurationSource.Explicit)!.Metadata); /// /// @@ -149,7 +151,7 @@ public virtual PropertyBuilder Property([NotNull] string propertyName) () => new PropertyBuilder( DependentEntityType.Builder.Property( Check.NotEmpty(propertyName, nameof(propertyName)), - ConfigurationSource.Explicit).Metadata)); + ConfigurationSource.Explicit)!.Metadata)); /// /// @@ -172,7 +174,7 @@ public virtual PropertyBuilder Property([NotNull] string p () => new PropertyBuilder( DependentEntityType.Builder.Property( typeof(TProperty), - Check.NotEmpty(propertyName, nameof(propertyName)), ConfigurationSource.Explicit).Metadata)); + Check.NotEmpty(propertyName, nameof(propertyName)), ConfigurationSource.Explicit)!.Metadata)); /// /// @@ -194,7 +196,7 @@ public virtual PropertyBuilder Property([NotNull] Type propertyType, [NotNull] s => new( DependentEntityType.Builder.Property( Check.NotNull(propertyType, nameof(propertyType)), - Check.NotEmpty(propertyName, nameof(propertyName)), ConfigurationSource.Explicit).Metadata); + Check.NotEmpty(propertyName, nameof(propertyName)), ConfigurationSource.Explicit)!.Metadata); /// /// @@ -214,7 +216,7 @@ public virtual PropertyBuilder IndexerProperty([NotNull] s => new( DependentEntityType.Builder.IndexerProperty( typeof(TProperty), - Check.NotEmpty(propertyName, nameof(propertyName)), ConfigurationSource.Explicit).Metadata); + Check.NotEmpty(propertyName, nameof(propertyName)), ConfigurationSource.Explicit)!.Metadata); /// /// @@ -234,7 +236,7 @@ public virtual PropertyBuilder IndexerProperty([NotNull] Type propertyType, [Not => new( DependentEntityType.Builder.IndexerProperty( Check.NotNull(propertyType, nameof(propertyType)), - Check.NotEmpty(propertyName, nameof(propertyName)), ConfigurationSource.Explicit).Metadata); + Check.NotEmpty(propertyName, nameof(propertyName)), ConfigurationSource.Explicit)!.Metadata); /// /// @@ -273,7 +275,7 @@ public virtual OwnedNavigationBuilder Ignore([NotNull] string propertyName) public virtual IndexBuilder HasIndex([NotNull] params string[] propertyNames) => new( DependentEntityType.Builder.HasIndex( - Check.NotEmpty(propertyNames, nameof(propertyNames)), ConfigurationSource.Explicit).Metadata); + Check.NotEmpty(propertyNames, nameof(propertyNames)), ConfigurationSource.Explicit)!.Metadata); /// /// @@ -291,7 +293,7 @@ public virtual IndexBuilder HasIndex([NotNull] params string[] propertyNames) /// /// An object that can be used to configure the relationship. public virtual OwnershipBuilder WithOwner( - [CanBeNull] string ownerReference = null) + [CanBeNull] string? ownerReference = null) { Check.NullButNotEmpty(ownerReference, nameof(ownerReference)); @@ -301,7 +303,7 @@ public virtual OwnershipBuilder WithOwner( Builder.HasNavigation( ownerReference, pointsToPrincipal: true, - ConfigurationSource.Explicit).Metadata); + ConfigurationSource.Explicit)!.Metadata); } /// @@ -525,9 +527,9 @@ private OwnedNavigationBuilder OwnsOneBuilder(in TypeIdentity ownedType, string using (var batch = DependentEntityType.Model.DelayConventions()) { var navigationMember = MemberIdentity.Create(navigationName); - var relationship = DependentEntityType.Builder.HasOwnership(ownedType, navigationMember, ConfigurationSource.Explicit); + var relationship = DependentEntityType.Builder.HasOwnership(ownedType, navigationMember, ConfigurationSource.Explicit)!; relationship.IsUnique(true, ConfigurationSource.Explicit); - foreignKey = (IMutableForeignKey)batch.Run(relationship.Metadata); + foreignKey = (IMutableForeignKey)batch.Run(relationship.Metadata)!; } return new OwnedNavigationBuilder(foreignKey); @@ -748,9 +750,9 @@ private OwnedNavigationBuilder OwnsManyBuilder(in TypeIdentity ownedType, string using (var batch = DependentEntityType.Model.DelayConventions()) { var navigationMember = MemberIdentity.Create(navigationName); - var relationship = DependentEntityType.Builder.HasOwnership(ownedType, navigationMember, ConfigurationSource.Explicit); + var relationship = DependentEntityType.Builder.HasOwnership(ownedType, navigationMember, ConfigurationSource.Explicit)!; relationship.IsUnique(false, ConfigurationSource.Explicit); - foreignKey = (IMutableForeignKey)batch.Run(relationship.Metadata); + foreignKey = (IMutableForeignKey)batch.Run(relationship.Metadata)!; } return new OwnedNavigationBuilder(foreignKey); @@ -783,7 +785,7 @@ private OwnedNavigationBuilder OwnsManyBuilder(in TypeIdentity ownedType, string /// An object that can be used to configure the relationship. public virtual ReferenceNavigationBuilder HasOne( [NotNull] string relatedTypeName, - [CanBeNull] string navigationName) + [CanBeNull] string? navigationName) { Check.NotEmpty(relatedTypeName, nameof(relatedTypeName)); Check.NullButNotEmpty(navigationName, nameof(navigationName)); @@ -796,7 +798,7 @@ public virtual ReferenceNavigationBuilder HasOne( navigationName, DependentEntityType.Builder.HasRelationship( relatedEntityType, navigationName, ConfigurationSource.Explicit, - targetIsPrincipal: DependentEntityType == relatedEntityType ? true : (bool?)null).Metadata); + targetIsPrincipal: DependentEntityType == relatedEntityType ? true : (bool?)null)!.Metadata); } /// @@ -857,7 +859,7 @@ public virtual ReferenceNavigationBuilder HasOne([NotNull] string navigationName /// An object that can be used to configure the relationship. public virtual ReferenceNavigationBuilder HasOne( [NotNull] Type relatedType, - [CanBeNull] string navigationName = null) + [CanBeNull] string? navigationName = null) { Check.NotNull(relatedType, nameof(relatedType)); Check.NullButNotEmpty(navigationName, nameof(navigationName)); @@ -870,7 +872,7 @@ public virtual ReferenceNavigationBuilder HasOne( navigationName, DependentEntityType.Builder.HasRelationship( relatedEntityType, navigationName, ConfigurationSource.Explicit, - targetIsPrincipal: DependentEntityType == relatedEntityType ? true : (bool?)null).Metadata); + targetIsPrincipal: DependentEntityType == relatedEntityType ? true : (bool?)null)!.Metadata); } /// @@ -880,9 +882,9 @@ public virtual ReferenceNavigationBuilder HasOne( /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [EntityFrameworkInternal] - protected virtual EntityType FindRelatedEntityType([NotNull] string relatedTypeName, [CanBeNull] string navigationName) + protected virtual EntityType FindRelatedEntityType([NotNull] string relatedTypeName, [CanBeNull] string? navigationName) { - EntityType relatedEntityType = null; + EntityType? relatedEntityType = null; var model = DependentEntityType.Model; if (navigationName != null) { @@ -892,7 +894,7 @@ protected virtual EntityType FindRelatedEntityType([NotNull] string relatedTypeN if (relatedEntityType == null && model.GetProductVersion()?.StartsWith("2.", StringComparison.Ordinal) == true) { - var owner = DependentEntityType.FindOwnership().PrincipalEntityType; + var owner = DependentEntityType.FindOwnership()!.PrincipalEntityType; if (owner.Name == relatedTypeName || owner.ShortName() == relatedTypeName) { @@ -900,7 +902,7 @@ protected virtual EntityType FindRelatedEntityType([NotNull] string relatedTypeN } } - return relatedEntityType ?? Builder.ModelBuilder.Entity(relatedTypeName, ConfigurationSource.Explicit).Metadata; + return relatedEntityType ?? Builder.ModelBuilder.Entity(relatedTypeName, ConfigurationSource.Explicit)!.Metadata; } /// @@ -910,9 +912,9 @@ protected virtual EntityType FindRelatedEntityType([NotNull] string relatedTypeN /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [EntityFrameworkInternal] - protected virtual EntityType FindRelatedEntityType([NotNull] Type relatedType, [CanBeNull] string navigationName) + protected virtual EntityType FindRelatedEntityType([NotNull] Type relatedType, [CanBeNull] string? navigationName) { - var relatedEntityType = (EntityType)DependentEntityType.FindInOwnershipPath(relatedType); + var relatedEntityType = (EntityType?)DependentEntityType.FindInOwnershipPath(relatedType); if (relatedEntityType != null) { return relatedEntityType; @@ -932,7 +934,7 @@ protected virtual EntityType FindRelatedEntityType([NotNull] Type relatedType, [ } } - return relatedEntityType ?? DependentEntityType.Builder.ModelBuilder.Entity(relatedType, ConfigurationSource.Explicit).Metadata; + return relatedEntityType ?? DependentEntityType.Builder.ModelBuilder.Entity(relatedType, ConfigurationSource.Explicit)!.Metadata; } /// diff --git a/src/EFCore/Metadata/Builders/OwnedNavigationBuilder`.cs b/src/EFCore/Metadata/Builders/OwnedNavigationBuilder`.cs index 27d101d1a9e..5a9e55bec74 100644 --- a/src/EFCore/Metadata/Builders/OwnedNavigationBuilder`.cs +++ b/src/EFCore/Metadata/Builders/OwnedNavigationBuilder`.cs @@ -11,6 +11,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Internal; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Builders { /// @@ -60,7 +62,7 @@ public OwnedNavigationBuilder([NotNull] IMutableForeignKey ownership) public virtual KeyBuilder HasKey([NotNull] Expression> keyExpression) => new( DependentEntityType.Builder.PrimaryKey( - Check.NotNull(keyExpression, nameof(keyExpression)).GetMemberAccessList(), ConfigurationSource.Explicit).Metadata); + Check.NotNull(keyExpression, nameof(keyExpression)).GetMemberAccessList(), ConfigurationSource.Explicit)!.Metadata); /// /// Sets the properties that make up the primary key for this owned entity type. @@ -70,7 +72,7 @@ public virtual KeyBuilder HasKey([NotNull] Expression HasKey([NotNull] params string[] propertyNames) => new( DependentEntityType.Builder.PrimaryKey( - Check.NotEmpty(propertyNames, nameof(propertyNames)), ConfigurationSource.Explicit).Metadata); + Check.NotEmpty(propertyNames, nameof(propertyNames)), ConfigurationSource.Explicit)!.Metadata); /// /// @@ -97,7 +99,7 @@ public virtual PropertyBuilder Property( () => new PropertyBuilder( DependentEntityType.Builder.Property( Check.NotNull(propertyExpression, nameof(propertyExpression)).GetMemberAccess(), - ConfigurationSource.Explicit).Metadata)); + ConfigurationSource.Explicit)!.Metadata)); /// /// @@ -180,7 +182,7 @@ public virtual OwnedNavigationBuilder Ignore( public virtual IndexBuilder HasIndex([NotNull] Expression> indexExpression) => new( DependentEntityType.Builder.HasIndex( - Check.NotNull(indexExpression, nameof(indexExpression)).GetMemberAccessList(), ConfigurationSource.Explicit) + Check.NotNull(indexExpression, nameof(indexExpression)).GetMemberAccessList(), ConfigurationSource.Explicit)! .Metadata); /// @@ -192,7 +194,7 @@ public virtual IndexBuilder HasIndex([NotNull] Expression HasIndex([NotNull] params string[] propertyNames) => new( DependentEntityType.Builder.HasIndex( - Check.NotEmpty(propertyNames, nameof(propertyNames)), ConfigurationSource.Explicit).Metadata); + Check.NotEmpty(propertyNames, nameof(propertyNames)), ConfigurationSource.Explicit)!.Metadata); /// /// @@ -210,7 +212,7 @@ public virtual IndexBuilder HasIndex([NotNull] Expression /// An object that can be used to configure the relationship. public new virtual OwnershipBuilder WithOwner( - [CanBeNull] string ownerReference = null) + [CanBeNull] string? ownerReference = null) { Check.NullButNotEmpty(ownerReference, nameof(ownerReference)); @@ -220,7 +222,7 @@ public virtual IndexBuilder HasIndex([NotNull] Expression @@ -240,14 +242,14 @@ public virtual IndexBuilder HasIndex([NotNull] Expression /// An object that can be used to configure the relationship. public virtual OwnershipBuilder WithOwner( - [CanBeNull] Expression> referenceExpression) + [CanBeNull] Expression>? referenceExpression) => new( PrincipalEntityType, DependentEntityType, Builder.HasNavigation( referenceExpression?.GetMemberAccess(), pointsToPrincipal: true, - ConfigurationSource.Explicit).Metadata); + ConfigurationSource.Explicit)!.Metadata); /// /// @@ -638,9 +640,9 @@ private OwnedNavigationBuilder OwnsOneBui InternalForeignKeyBuilder relationship; using (var batch = DependentEntityType.Model.DelayConventions()) { - relationship = DependentEntityType.Builder.HasOwnership(ownedType, navigation, ConfigurationSource.Explicit); + relationship = DependentEntityType.Builder.HasOwnership(ownedType, navigation, ConfigurationSource.Explicit)!; relationship.IsUnique(true, ConfigurationSource.Explicit); - relationship = (InternalForeignKeyBuilder)batch.Run(relationship.Metadata).Builder; + relationship = (InternalForeignKeyBuilder)batch.Run(relationship.Metadata)!.Builder; } return new OwnedNavigationBuilder(relationship.Metadata); @@ -1036,9 +1038,9 @@ private OwnedNavigationBuilder OwnsManyBuil InternalForeignKeyBuilder relationship; using (var batch = DependentEntityType.Model.DelayConventions()) { - relationship = DependentEntityType.Builder.HasOwnership(ownedType, navigation, ConfigurationSource.Explicit); + relationship = DependentEntityType.Builder.HasOwnership(ownedType, navigation, ConfigurationSource.Explicit)!; relationship.IsUnique(false, ConfigurationSource.Explicit); - relationship = (InternalForeignKeyBuilder)batch.Run(relationship.Metadata).Builder; + relationship = (InternalForeignKeyBuilder)batch.Run(relationship.Metadata)!.Builder; } return new OwnedNavigationBuilder(relationship.Metadata); @@ -1071,7 +1073,7 @@ private OwnedNavigationBuilder OwnsManyBuil /// /// An object that can be used to configure the relationship. public virtual ReferenceNavigationBuilder HasOne( - [CanBeNull] string navigationName) + [CanBeNull] string? navigationName) where TNewRelatedEntity : class { var relatedEntityType = FindRelatedEntityType(typeof(TNewRelatedEntity), navigationName); @@ -1082,7 +1084,7 @@ public virtual ReferenceNavigationBuilder H navigationName, DependentEntityType.Builder.HasRelationship( relatedEntityType, navigationName, ConfigurationSource.Explicit, - targetIsPrincipal: DependentEntityType == relatedEntityType ? true : (bool?)null).Metadata); + targetIsPrincipal: DependentEntityType == relatedEntityType ? true : (bool?)null)!.Metadata); } /// @@ -1114,7 +1116,7 @@ public virtual ReferenceNavigationBuilder H /// /// An object that can be used to configure the relationship. public virtual ReferenceNavigationBuilder HasOne( - [CanBeNull] Expression> navigationExpression = null) + [CanBeNull] Expression>? navigationExpression = null) where TNewRelatedEntity : class { var navigation = navigationExpression?.GetMemberAccess(); @@ -1126,7 +1128,7 @@ public virtual ReferenceNavigationBuilder H navigation, DependentEntityType.Builder.HasRelationship( relatedEntityType, navigation, ConfigurationSource.Explicit, - targetIsPrincipal: DependentEntityType == relatedEntityType ? true : (bool?)null).Metadata); + targetIsPrincipal: DependentEntityType == relatedEntityType ? true : (bool?)null)!.Metadata); } /// diff --git a/src/EFCore/Metadata/Builders/OwnershipBuilder.cs b/src/EFCore/Metadata/Builders/OwnershipBuilder.cs index ebd592e1284..cecc4c5e6bf 100644 --- a/src/EFCore/Metadata/Builders/OwnershipBuilder.cs +++ b/src/EFCore/Metadata/Builders/OwnershipBuilder.cs @@ -7,6 +7,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Internal; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Builders { /// @@ -40,7 +42,7 @@ public OwnershipBuilder( [EntityFrameworkInternal] protected OwnershipBuilder( [NotNull] InternalForeignKeyBuilder builder, - [CanBeNull] OwnershipBuilder oldBuilder, + [NotNull] OwnershipBuilder oldBuilder, bool foreignKeySet = false, bool principalKeySet = false, bool requiredSet = false) @@ -93,7 +95,7 @@ public virtual OwnershipBuilder HasForeignKey( Builder = Builder.HasForeignKey( Check.NotNull(foreignKeyPropertyNames, nameof(foreignKeyPropertyNames)), (EntityType)DependentEntityType, - ConfigurationSource.Explicit); + ConfigurationSource.Explicit)!; return new OwnershipBuilder( Builder, this, @@ -113,7 +115,7 @@ public virtual OwnershipBuilder HasPrincipalKey( { Builder = Builder.HasPrincipalKey( Check.NotNull(keyPropertyNames, nameof(keyPropertyNames)), - ConfigurationSource.Explicit); + ConfigurationSource.Explicit)!; return new OwnershipBuilder( Builder, this, diff --git a/src/EFCore/Metadata/Builders/OwnershipBuilder`.cs b/src/EFCore/Metadata/Builders/OwnershipBuilder`.cs index a7e5e10e9ce..b5ddc86b65d 100644 --- a/src/EFCore/Metadata/Builders/OwnershipBuilder`.cs +++ b/src/EFCore/Metadata/Builders/OwnershipBuilder`.cs @@ -9,6 +9,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Internal; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Builders { /// @@ -44,7 +46,7 @@ public OwnershipBuilder( [EntityFrameworkInternal] protected OwnershipBuilder( [NotNull] InternalForeignKeyBuilder builder, - [CanBeNull] OwnershipBuilder oldBuilder, + [NotNull] OwnershipBuilder oldBuilder, bool foreignKeySet = false, bool principalKeySet = false, bool requiredSet = false) @@ -92,7 +94,7 @@ protected OwnershipBuilder( Builder = Builder.HasForeignKey( Check.NotNull(foreignKeyPropertyNames, nameof(foreignKeyPropertyNames)), (EntityType)DependentEntityType, - ConfigurationSource.Explicit); + ConfigurationSource.Explicit)!; return new OwnershipBuilder( Builder, this, @@ -134,7 +136,7 @@ public virtual OwnershipBuilder HasForeignKey( Builder = Builder.HasForeignKey( Check.NotNull(foreignKeyExpression, nameof(foreignKeyExpression)).GetMemberAccessList(), (EntityType)DependentEntityType, - ConfigurationSource.Explicit); + ConfigurationSource.Explicit)!; return new OwnershipBuilder( Builder, this, @@ -154,7 +156,7 @@ public virtual OwnershipBuilder HasForeignKey( { Builder = Builder.HasPrincipalKey( Check.NotNull(keyPropertyNames, nameof(keyPropertyNames)), - ConfigurationSource.Explicit); + ConfigurationSource.Explicit)!; return new OwnershipBuilder( Builder, this, @@ -183,7 +185,7 @@ public virtual OwnershipBuilder HasPrincipalKey( { Builder = Builder.HasPrincipalKey( Check.NotNull(keyExpression, nameof(keyExpression)).GetMemberAccessList(), - ConfigurationSource.Explicit); + ConfigurationSource.Explicit)!; return new OwnershipBuilder( Builder, this, diff --git a/src/EFCore/Metadata/Builders/PropertyBuilder.cs b/src/EFCore/Metadata/Builders/PropertyBuilder.cs index 2bd3c1262f8..f673f857b15 100644 --- a/src/EFCore/Metadata/Builders/PropertyBuilder.cs +++ b/src/EFCore/Metadata/Builders/PropertyBuilder.cs @@ -11,6 +11,8 @@ using Microsoft.EntityFrameworkCore.Utilities; using Microsoft.EntityFrameworkCore.ValueGeneration; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Builders { /// @@ -210,7 +212,7 @@ public virtual PropertyBuilder HasValueGenerator() /// /// A type that inherits from . /// The same builder instance so that multiple configuration calls can be chained. - public virtual PropertyBuilder HasValueGenerator([CanBeNull] Type valueGeneratorType) + public virtual PropertyBuilder HasValueGenerator([CanBeNull] Type? valueGeneratorType) { Builder.HasValueGenerator(valueGeneratorType, ConfigurationSource.Explicit); @@ -393,7 +395,7 @@ public virtual PropertyBuilder HasConversion() /// /// The type to convert to and from. /// The same builder instance so that multiple configuration calls can be chained. - public virtual PropertyBuilder HasConversion([CanBeNull] Type providerClrType) + public virtual PropertyBuilder HasConversion([CanBeNull] Type? providerClrType) { Builder.HasConversion(providerClrType, ConfigurationSource.Explicit); @@ -406,7 +408,7 @@ public virtual PropertyBuilder HasConversion([CanBeNull] Type providerClrType) /// /// The converter to use. /// The same builder instance so that multiple configuration calls can be chained. - public virtual PropertyBuilder HasConversion([CanBeNull] ValueConverter converter) + public virtual PropertyBuilder HasConversion([CanBeNull] ValueConverter? converter) { Builder.HasConversion(converter, ConfigurationSource.Explicit); @@ -420,7 +422,7 @@ public virtual PropertyBuilder HasConversion([CanBeNull] ValueConverter converte /// The comparer to use for values before conversion. /// The type to convert to and from. /// The same builder instance so that multiple configuration calls can be chained. - public virtual PropertyBuilder HasConversion([CanBeNull] ValueComparer valueComparer) + public virtual PropertyBuilder HasConversion([CanBeNull] ValueComparer? valueComparer) => HasConversion(typeof(TProvider), valueComparer); /// @@ -430,7 +432,7 @@ public virtual PropertyBuilder HasConversion([CanBeNull] ValueCompare /// The type to convert to and from. /// The comparer to use for values before conversion. /// The same builder instance so that multiple configuration calls can be chained. - public virtual PropertyBuilder HasConversion([CanBeNull] Type providerClrType, [CanBeNull] ValueComparer valueComparer) + public virtual PropertyBuilder HasConversion([CanBeNull] Type? providerClrType, [CanBeNull] ValueComparer? valueComparer) { Builder.HasConversion(providerClrType, ConfigurationSource.Explicit); Builder.HasValueComparer(valueComparer, ConfigurationSource.Explicit); @@ -445,7 +447,7 @@ public virtual PropertyBuilder HasConversion([CanBeNull] Type providerClrType, [ /// The converter to use. /// The comparer to use for values before conversion. /// The same builder instance so that multiple configuration calls can be chained. - public virtual PropertyBuilder HasConversion([CanBeNull] ValueConverter converter, [CanBeNull] ValueComparer valueComparer) + public virtual PropertyBuilder HasConversion([CanBeNull] ValueConverter? converter, [CanBeNull] ValueComparer? valueComparer) { Builder.HasConversion(converter, ConfigurationSource.Explicit); Builder.HasValueComparer(valueComparer, ConfigurationSource.Explicit); @@ -460,7 +462,7 @@ public virtual PropertyBuilder HasConversion([CanBeNull] ValueConverter converte /// /// A string that represents the current object. [EditorBrowsable(EditorBrowsableState.Never)] - public override string ToString() + public override string? ToString() => base.ToString(); /// @@ -470,7 +472,7 @@ public override string ToString() /// if the specified object is equal to the current object; otherwise, . [EditorBrowsable(EditorBrowsableState.Never)] // ReSharper disable once BaseObjectEqualsIsObjectEquals - public override bool Equals(object obj) + public override bool Equals(object? obj) => base.Equals(obj); /// diff --git a/src/EFCore/Metadata/Builders/PropertyBuilder`.cs b/src/EFCore/Metadata/Builders/PropertyBuilder`.cs index 88fc704ac15..2b05e21d23f 100644 --- a/src/EFCore/Metadata/Builders/PropertyBuilder`.cs +++ b/src/EFCore/Metadata/Builders/PropertyBuilder`.cs @@ -10,6 +10,8 @@ using Microsoft.EntityFrameworkCore.Utilities; using Microsoft.EntityFrameworkCore.ValueGeneration; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Builders { /// @@ -156,7 +158,7 @@ public PropertyBuilder([NotNull] IMutableProperty property) /// /// A type that inherits from . /// The same builder instance so that multiple configuration calls can be chained. - public new virtual PropertyBuilder HasValueGenerator([CanBeNull] Type valueGeneratorType) + public new virtual PropertyBuilder HasValueGenerator([CanBeNull] Type? valueGeneratorType) => (PropertyBuilder)base.HasValueGenerator(valueGeneratorType); /// @@ -276,7 +278,7 @@ public PropertyBuilder([NotNull] IMutableProperty property) /// /// The type to convert to and from. /// The same builder instance so that multiple configuration calls can be chained. - public new virtual PropertyBuilder HasConversion([CanBeNull] Type providerClrType) + public new virtual PropertyBuilder HasConversion([CanBeNull] Type? providerClrType) => (PropertyBuilder)base.HasConversion(providerClrType); /// @@ -302,8 +304,8 @@ public virtual PropertyBuilder HasConversion( /// The store type generated by the converter. /// The converter to use. /// The same builder instance so that multiple configuration calls can be chained. - public virtual PropertyBuilder HasConversion([CanBeNull] ValueConverter converter) - => HasConversion((ValueConverter)converter); + public virtual PropertyBuilder HasConversion([CanBeNull] ValueConverter? converter) + => HasConversion((ValueConverter?)converter); /// /// Configures the property so that the property value is converted to and from the database @@ -311,7 +313,7 @@ public virtual PropertyBuilder HasConversion([CanBeNull] V /// /// The converter to use. /// The same builder instance so that multiple configuration calls can be chained. - public new virtual PropertyBuilder HasConversion([CanBeNull] ValueConverter converter) + public new virtual PropertyBuilder HasConversion([CanBeNull] ValueConverter? converter) => (PropertyBuilder)base.HasConversion(converter); /// @@ -321,7 +323,7 @@ public virtual PropertyBuilder HasConversion([CanBeNull] V /// The type to convert to and from. /// The comparer to use for values before conversion. /// The same builder instance so that multiple configuration calls can be chained. - public new virtual PropertyBuilder HasConversion([CanBeNull] ValueComparer valueComparer) + public new virtual PropertyBuilder HasConversion([CanBeNull] ValueComparer? valueComparer) => (PropertyBuilder)base.HasConversion(valueComparer); /// @@ -332,8 +334,8 @@ public virtual PropertyBuilder HasConversion([CanBeNull] V /// The comparer to use for values before conversion. /// The same builder instance so that multiple configuration calls can be chained. public new virtual PropertyBuilder HasConversion( - [CanBeNull] Type providerClrType, - [CanBeNull] ValueComparer valueComparer) + [CanBeNull] Type? providerClrType, + [CanBeNull] ValueComparer? valueComparer) => (PropertyBuilder)base.HasConversion(providerClrType, valueComparer); /// @@ -348,7 +350,7 @@ public virtual PropertyBuilder HasConversion([CanBeNull] V public virtual PropertyBuilder HasConversion( [NotNull] Expression> convertToProviderExpression, [NotNull] Expression> convertFromProviderExpression, - [CanBeNull] ValueComparer valueComparer) + [CanBeNull] ValueComparer? valueComparer) => HasConversion( new ValueConverter( Check.NotNull(convertToProviderExpression, nameof(convertToProviderExpression)), @@ -364,9 +366,9 @@ public virtual PropertyBuilder HasConversion( /// The comparer to use for values before conversion. /// The same builder instance so that multiple configuration calls can be chained. public virtual PropertyBuilder HasConversion( - [CanBeNull] ValueConverter converter, - [CanBeNull] ValueComparer valueComparer) - => HasConversion((ValueConverter)converter, valueComparer); + [CanBeNull] ValueConverter? converter, + [CanBeNull] ValueComparer? valueComparer) + => HasConversion((ValueConverter?)converter, valueComparer); /// /// Configures the property so that the property value is converted to and from the database @@ -376,8 +378,8 @@ public virtual PropertyBuilder HasConversion( /// The comparer to use for values before conversion. /// The same builder instance so that multiple configuration calls can be chained. public new virtual PropertyBuilder HasConversion( - [CanBeNull] ValueConverter converter, - [CanBeNull] ValueComparer valueComparer) + [CanBeNull] ValueConverter? converter, + [CanBeNull] ValueComparer? valueComparer) => (PropertyBuilder)base.HasConversion(converter, valueComparer); /// diff --git a/src/EFCore/Metadata/Builders/ReferenceCollectionBuilder.cs b/src/EFCore/Metadata/Builders/ReferenceCollectionBuilder.cs index baaaf6e06ce..c50cc190bf5 100644 --- a/src/EFCore/Metadata/Builders/ReferenceCollectionBuilder.cs +++ b/src/EFCore/Metadata/Builders/ReferenceCollectionBuilder.cs @@ -9,6 +9,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Internal; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Builders { /// @@ -46,7 +48,7 @@ public ReferenceCollectionBuilder( [EntityFrameworkInternal] protected ReferenceCollectionBuilder( [NotNull] InternalForeignKeyBuilder builder, - [CanBeNull] ReferenceCollectionBuilder oldBuilder, + [NotNull] ReferenceCollectionBuilder oldBuilder, bool foreignKeySet = false, bool principalKeySet = false, bool requiredSet = false) @@ -108,7 +110,7 @@ public virtual ReferenceCollectionBuilder HasForeignKey([NotNull] params string[ /// [EntityFrameworkInternal] protected virtual InternalForeignKeyBuilder HasForeignKeyBuilder([NotNull] IReadOnlyList foreignKeyPropertyNames) - => Builder.HasForeignKey(foreignKeyPropertyNames, (EntityType)DependentEntityType, ConfigurationSource.Explicit); + => Builder.HasForeignKey(foreignKeyPropertyNames, (EntityType)DependentEntityType, ConfigurationSource.Explicit)!; /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -118,7 +120,7 @@ protected virtual InternalForeignKeyBuilder HasForeignKeyBuilder([NotNull] IRead /// [EntityFrameworkInternal] protected virtual InternalForeignKeyBuilder HasForeignKeyBuilder([NotNull] IReadOnlyList foreignKeyMembers) - => Builder.HasForeignKey(foreignKeyMembers, (EntityType)DependentEntityType, ConfigurationSource.Explicit); + => Builder.HasForeignKey(foreignKeyMembers, (EntityType)DependentEntityType, ConfigurationSource.Explicit)!; /// /// Configures the unique property(s) that this relationship targets. Typically you would only call this @@ -142,7 +144,7 @@ public virtual ReferenceCollectionBuilder HasPrincipalKey([NotNull] params strin /// [EntityFrameworkInternal] protected virtual InternalForeignKeyBuilder HasPrincipalKeyBuilder([NotNull] IReadOnlyList keyPropertyNames) - => Builder.HasPrincipalKey(keyPropertyNames, ConfigurationSource.Explicit); + => Builder.HasPrincipalKey(keyPropertyNames, ConfigurationSource.Explicit)!; /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -152,7 +154,7 @@ protected virtual InternalForeignKeyBuilder HasPrincipalKeyBuilder([NotNull] IRe /// [EntityFrameworkInternal] protected virtual InternalForeignKeyBuilder HasPrincipalKeyBuilder([NotNull] IReadOnlyList keyMembers) - => Builder.HasPrincipalKey(keyMembers, ConfigurationSource.Explicit); + => Builder.HasPrincipalKey(keyMembers, ConfigurationSource.Explicit)!; /// /// Configures whether this is a required relationship (i.e. whether the foreign key property(s) can @@ -161,10 +163,7 @@ protected virtual InternalForeignKeyBuilder HasPrincipalKeyBuilder([NotNull] IRe /// A value indicating whether this is a required relationship. /// The same builder instance so that multiple configuration calls can be chained. public virtual ReferenceCollectionBuilder IsRequired(bool required = true) - => new( - Builder.IsRequired(required, ConfigurationSource.Explicit), - this, - requiredSet: true); + => new(Builder.IsRequired(required, ConfigurationSource.Explicit)!, this, requiredSet: true); /// /// Configures the operation applied to dependent entities in the relationship when the @@ -173,6 +172,6 @@ public virtual ReferenceCollectionBuilder IsRequired(bool required = true) /// The action to perform. /// The same builder instance so that multiple configuration calls can be chained. public virtual ReferenceCollectionBuilder OnDelete(DeleteBehavior deleteBehavior) - => new(Builder.OnDelete(deleteBehavior, ConfigurationSource.Explicit), this); + => new(Builder.OnDelete(deleteBehavior, ConfigurationSource.Explicit)!, this); } } diff --git a/src/EFCore/Metadata/Builders/ReferenceCollectionBuilder`.cs b/src/EFCore/Metadata/Builders/ReferenceCollectionBuilder`.cs index ffa6c144a84..757003b13b4 100644 --- a/src/EFCore/Metadata/Builders/ReferenceCollectionBuilder`.cs +++ b/src/EFCore/Metadata/Builders/ReferenceCollectionBuilder`.cs @@ -9,6 +9,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Internal; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Builders { /// @@ -50,7 +52,7 @@ public ReferenceCollectionBuilder( [EntityFrameworkInternal] protected ReferenceCollectionBuilder( [NotNull] InternalForeignKeyBuilder builder, - [CanBeNull] ReferenceCollectionBuilder oldBuilder, + [NotNull] ReferenceCollectionBuilder oldBuilder, bool foreignKeySet = false, bool principalKeySet = false, bool requiredSet = false) @@ -179,7 +181,7 @@ public virtual ReferenceCollectionBuilder Ha /// A value indicating whether this is a required relationship. /// The same builder instance so that multiple configuration calls can be chained. public new virtual ReferenceCollectionBuilder IsRequired(bool required = true) - => new(Builder.IsRequired(required, ConfigurationSource.Explicit), this, requiredSet: true); + => new(Builder.IsRequired(required, ConfigurationSource.Explicit)!, this, requiredSet: true); /// /// Configures the operation applied to dependent entities in the relationship when the @@ -188,6 +190,6 @@ public virtual ReferenceCollectionBuilder Ha /// The action to perform. /// The same builder instance so that multiple configuration calls can be chained. public new virtual ReferenceCollectionBuilder OnDelete(DeleteBehavior deleteBehavior) - => new(Builder.OnDelete(deleteBehavior, ConfigurationSource.Explicit), this); + => new(Builder.OnDelete(deleteBehavior, ConfigurationSource.Explicit)!, this); } } diff --git a/src/EFCore/Metadata/Builders/ReferenceNavigationBuilder.cs b/src/EFCore/Metadata/Builders/ReferenceNavigationBuilder.cs index 6ceabcd69e8..12b1c73bc92 100644 --- a/src/EFCore/Metadata/Builders/ReferenceNavigationBuilder.cs +++ b/src/EFCore/Metadata/Builders/ReferenceNavigationBuilder.cs @@ -12,6 +12,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Internal; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Builders { /// @@ -36,7 +38,7 @@ public class ReferenceNavigationBuilder : IInfrastructure [EntityFrameworkInternal] - protected virtual string ReferenceName { [DebuggerStepThrough] get; } + protected virtual string? ReferenceName { [DebuggerStepThrough] get; } /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -90,7 +92,7 @@ public ReferenceNavigationBuilder( /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [EntityFrameworkInternal] - protected virtual MemberInfo ReferenceMember { [DebuggerStepThrough] get; } + protected virtual MemberInfo? ReferenceMember { [DebuggerStepThrough] get; } /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -131,7 +133,7 @@ IConventionForeignKeyBuilder IInfrastructure.Insta /// If null or not specified, there is no navigation property on the other end of the relationship. /// /// An object to further configure the relationship. - public virtual ReferenceCollectionBuilder WithMany([CanBeNull] string collection = null) + public virtual ReferenceCollectionBuilder WithMany([CanBeNull] string? collection = null) { return new( RelatedEntityType, @@ -146,7 +148,7 @@ public virtual ReferenceCollectionBuilder WithMany([CanBeNull] string collection /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [EntityFrameworkInternal] - protected virtual InternalForeignKeyBuilder WithManyBuilder([CanBeNull] string navigationName) + protected virtual InternalForeignKeyBuilder WithManyBuilder([CanBeNull] string? navigationName) => WithManyBuilder(MemberIdentity.Create(navigationName)); /// @@ -156,13 +158,13 @@ protected virtual InternalForeignKeyBuilder WithManyBuilder([CanBeNull] string n /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [EntityFrameworkInternal] - protected virtual InternalForeignKeyBuilder WithManyBuilder([CanBeNull] MemberInfo navigationMemberInfo) + protected virtual InternalForeignKeyBuilder WithManyBuilder([CanBeNull] MemberInfo? navigationMemberInfo) => WithManyBuilder(MemberIdentity.Create(navigationMemberInfo)); private InternalForeignKeyBuilder WithManyBuilder(MemberIdentity collection) { var builder = Builder.HasEntityTypes( - (EntityType)RelatedEntityType, (EntityType)DeclaringEntityType, ConfigurationSource.Explicit); + (EntityType)RelatedEntityType, (EntityType)DeclaringEntityType, ConfigurationSource.Explicit)!; var collectionName = collection.Name; if (builder.Metadata.IsUnique && builder.Metadata.PrincipalToDependent != null @@ -172,7 +174,7 @@ private InternalForeignKeyBuilder WithManyBuilder(MemberIdentity collection) InternalForeignKeyBuilder.ThrowForConflictingNavigation(builder.Metadata, collectionName, false); } - builder = builder.IsUnique(false, ConfigurationSource.Explicit); + builder = builder.IsUnique(false, ConfigurationSource.Explicit)!; var foreignKey = builder.Metadata; if (collectionName != null && foreignKey.PrincipalToDependent != null @@ -185,10 +187,10 @@ private InternalForeignKeyBuilder WithManyBuilder(MemberIdentity collection) return collection.MemberInfo == null || ReferenceMember == null ? builder.HasNavigations( ReferenceName, collection.Name, - (EntityType)RelatedEntityType, (EntityType)DeclaringEntityType, ConfigurationSource.Explicit) + (EntityType)RelatedEntityType, (EntityType)DeclaringEntityType, ConfigurationSource.Explicit)! : builder.HasNavigations( ReferenceMember, collection.MemberInfo, - (EntityType)RelatedEntityType, (EntityType)DeclaringEntityType, ConfigurationSource.Explicit); + (EntityType)RelatedEntityType, (EntityType)DeclaringEntityType, ConfigurationSource.Explicit)!; } /// @@ -206,11 +208,8 @@ private InternalForeignKeyBuilder WithManyBuilder(MemberIdentity collection) /// If null or not specified, there is no navigation property on the other end of the relationship. /// /// An object that can be used to configure the relationship. - public virtual ReferenceReferenceBuilder WithOne([CanBeNull] string reference = null) - => new( - DeclaringEntityType, - RelatedEntityType, - WithOneBuilder(Check.NullButNotEmpty(reference, nameof(reference))).Metadata); + public virtual ReferenceReferenceBuilder WithOne([CanBeNull] string? reference = null) + => new(DeclaringEntityType, RelatedEntityType, WithOneBuilder(Check.NullButNotEmpty(reference, nameof(reference))).Metadata); /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -219,7 +218,7 @@ public virtual ReferenceReferenceBuilder WithOne([CanBeNull] string reference = /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [EntityFrameworkInternal] - protected virtual InternalForeignKeyBuilder WithOneBuilder([CanBeNull] string navigationName) + protected virtual InternalForeignKeyBuilder WithOneBuilder([CanBeNull] string? navigationName) => WithOneBuilder(MemberIdentity.Create(navigationName)); /// @@ -229,8 +228,7 @@ protected virtual InternalForeignKeyBuilder WithOneBuilder([CanBeNull] string na /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [EntityFrameworkInternal] - protected virtual InternalForeignKeyBuilder WithOneBuilder( - [CanBeNull] MemberInfo navigationMemberInfo) + protected virtual InternalForeignKeyBuilder WithOneBuilder([CanBeNull] MemberInfo? navigationMemberInfo) => WithOneBuilder(MemberIdentity.Create(navigationMemberInfo)); private InternalForeignKeyBuilder WithOneBuilder(MemberIdentity reference) @@ -245,7 +243,7 @@ private InternalForeignKeyBuilder WithOneBuilder(MemberIdentity reference) } using var batch = Builder.Metadata.DeclaringEntityType.Model.DelayConventions(); - var builder = Builder.IsUnique(true, ConfigurationSource.Explicit); + var builder = Builder.IsUnique(true, ConfigurationSource.Explicit)!; var foreignKey = builder.Metadata; if (foreignKey.IsSelfReferencing() && referenceName != null @@ -283,23 +281,23 @@ private InternalForeignKeyBuilder WithOneBuilder(MemberIdentity reference) builder = referenceProperty == null || ReferenceMember == null ? builder.HasNavigations( referenceName, ReferenceName, - (EntityType)DeclaringEntityType, (EntityType)RelatedEntityType, ConfigurationSource.Explicit) + (EntityType)DeclaringEntityType, (EntityType)RelatedEntityType, ConfigurationSource.Explicit)! : builder.HasNavigations( referenceProperty, ReferenceMember, - (EntityType)DeclaringEntityType, (EntityType)RelatedEntityType, ConfigurationSource.Explicit); + (EntityType)DeclaringEntityType, (EntityType)RelatedEntityType, ConfigurationSource.Explicit)!; } else { builder = referenceProperty == null || ReferenceMember == null ? builder.HasNavigations( ReferenceName, referenceName, - (EntityType)RelatedEntityType, (EntityType)DeclaringEntityType, ConfigurationSource.Explicit) + (EntityType)RelatedEntityType, (EntityType)DeclaringEntityType, ConfigurationSource.Explicit)! : builder.HasNavigations( ReferenceMember, referenceProperty, - (EntityType)RelatedEntityType, (EntityType)DeclaringEntityType, ConfigurationSource.Explicit); + (EntityType)RelatedEntityType, (EntityType)DeclaringEntityType, ConfigurationSource.Explicit)!; } - return batch.Run(builder); + return batch.Run(builder)!; } #region Hidden System.Object members @@ -309,7 +307,7 @@ private InternalForeignKeyBuilder WithOneBuilder(MemberIdentity reference) /// /// A string that represents the current object. [EditorBrowsable(EditorBrowsableState.Never)] - public override string ToString() + public override string? ToString() => base.ToString(); /// @@ -319,7 +317,7 @@ public override string ToString() /// if the specified object is equal to the current object; otherwise, . [EditorBrowsable(EditorBrowsableState.Never)] // ReSharper disable once BaseObjectEqualsIsObjectEquals - public override bool Equals(object obj) + public override bool Equals(object? obj) => base.Equals(obj); /// diff --git a/src/EFCore/Metadata/Builders/ReferenceNavigationBuilder`.cs b/src/EFCore/Metadata/Builders/ReferenceNavigationBuilder`.cs index 90877d4f806..e270cc7d514 100644 --- a/src/EFCore/Metadata/Builders/ReferenceNavigationBuilder`.cs +++ b/src/EFCore/Metadata/Builders/ReferenceNavigationBuilder`.cs @@ -9,6 +9,8 @@ using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Builders { /// @@ -37,7 +39,7 @@ public class ReferenceNavigationBuilder : ReferenceNavi public ReferenceNavigationBuilder( [NotNull] IMutableEntityType declaringEntityType, [NotNull] IMutableEntityType relatedEntityType, - [CanBeNull] string navigationName, + [CanBeNull] string? navigationName, [NotNull] IMutableForeignKey foreignKey) : base(declaringEntityType, relatedEntityType, navigationName, foreignKey) { @@ -53,7 +55,7 @@ public ReferenceNavigationBuilder( public ReferenceNavigationBuilder( [NotNull] IMutableEntityType declaringEntityType, [NotNull] IMutableEntityType relatedEntityType, - [CanBeNull] MemberInfo navigationMemberInfo, + [CanBeNull] MemberInfo? navigationMemberInfo, [NotNull] IMutableForeignKey foreignKey) : base(declaringEntityType, relatedEntityType, navigationMemberInfo, foreignKey) { @@ -75,7 +77,7 @@ public ReferenceNavigationBuilder( /// /// An object to further configure the relationship. public new virtual ReferenceCollectionBuilder WithMany( - [CanBeNull] string navigationName = null) + [CanBeNull] string? navigationName = null) { return new( RelatedEntityType, @@ -101,7 +103,7 @@ public ReferenceNavigationBuilder( /// /// An object to further configure the relationship. public virtual ReferenceCollectionBuilder WithMany( - [CanBeNull] Expression>> navigationExpression) + [CanBeNull] Expression>>? navigationExpression) { return new( RelatedEntityType, @@ -125,7 +127,7 @@ public virtual ReferenceCollectionBuilder WithMany( /// /// An object to further configure the relationship. public new virtual ReferenceReferenceBuilder WithOne( - [CanBeNull] string navigationName = null) + [CanBeNull] string? navigationName = null) => new( DeclaringEntityType, RelatedEntityType, @@ -149,7 +151,7 @@ public virtual ReferenceCollectionBuilder WithMany( /// /// An object to further configure the relationship. public virtual ReferenceReferenceBuilder WithOne( - [CanBeNull] Expression> navigationExpression) + [CanBeNull] Expression>? navigationExpression) => new( DeclaringEntityType, RelatedEntityType, diff --git a/src/EFCore/Metadata/Builders/ReferenceReferenceBuilder.cs b/src/EFCore/Metadata/Builders/ReferenceReferenceBuilder.cs index a5bc5d68d6d..36b9113426e 100644 --- a/src/EFCore/Metadata/Builders/ReferenceReferenceBuilder.cs +++ b/src/EFCore/Metadata/Builders/ReferenceReferenceBuilder.cs @@ -12,6 +12,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Internal; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Builders { /// @@ -45,7 +47,7 @@ public ReferenceReferenceBuilder( [EntityFrameworkInternal] protected ReferenceReferenceBuilder( [NotNull] InternalForeignKeyBuilder builder, - [CanBeNull] ReferenceReferenceBuilder oldBuilder, + [NotNull] ReferenceReferenceBuilder oldBuilder, bool inverted = false, bool foreignKeySet = false, bool principalKeySet = false, @@ -106,7 +108,7 @@ public virtual ReferenceReferenceBuilder HasForeignKey( dependentEntityTypeName, Check.NotNull(foreignKeyPropertyNames, nameof(foreignKeyPropertyNames))), this, - Builder.Metadata.DeclaringEntityType.Name != ResolveEntityType(dependentEntityTypeName).Name, + Builder.Metadata.DeclaringEntityType.Name != ResolveEntityType(dependentEntityTypeName)!.Name, foreignKeySet: foreignKeyPropertyNames.Length > 0); /// @@ -155,12 +157,12 @@ public virtual ReferenceReferenceBuilder HasForeignKey( /// [EntityFrameworkInternal] protected virtual InternalForeignKeyBuilder HasForeignKeyBuilder( - [CanBeNull] EntityType dependentEntityType, + [CanBeNull] EntityType? dependentEntityType, [NotNull] string dependentEntityTypeName, [NotNull] IReadOnlyList foreignKeyPropertyNames) => HasForeignKeyBuilder( dependentEntityType, dependentEntityTypeName, - (b, d) => b.HasForeignKey(foreignKeyPropertyNames, d, ConfigurationSource.Explicit)); + (b, d) => b.HasForeignKey(foreignKeyPropertyNames, d, ConfigurationSource.Explicit)!); /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -175,10 +177,10 @@ protected virtual InternalForeignKeyBuilder HasForeignKeyBuilder( [NotNull] IReadOnlyList foreignKeyMembers) => HasForeignKeyBuilder( dependentEntityType, dependentEntityTypeName, - (b, d) => b.HasForeignKey(foreignKeyMembers, d, ConfigurationSource.Explicit)); + (b, d) => b.HasForeignKey(foreignKeyMembers, d, ConfigurationSource.Explicit)!); private InternalForeignKeyBuilder HasForeignKeyBuilder( - EntityType dependentEntityType, + EntityType? dependentEntityType, string dependentEntityTypeName, Func hasForeignKey) { @@ -193,10 +195,10 @@ private InternalForeignKeyBuilder HasForeignKeyBuilder( using var batch = dependentEntityType.Model.DelayConventions(); var builder = Builder.HasEntityTypes( - GetOtherEntityType(dependentEntityType), dependentEntityType, ConfigurationSource.Explicit); + GetOtherEntityType(dependentEntityType), dependentEntityType, ConfigurationSource.Explicit)!; builder = hasForeignKey(builder, dependentEntityType); - return batch.Run(builder); + return batch.Run(builder)!; } /// @@ -225,7 +227,7 @@ public virtual ReferenceReferenceBuilder HasPrincipalKey( principalEntityTypeName, Check.NotNull(keyPropertyNames, nameof(keyPropertyNames))), this, - inverted: Builder.Metadata.PrincipalEntityType.Name != ResolveEntityType(principalEntityTypeName).Name, + inverted: Builder.Metadata.PrincipalEntityType.Name != ResolveEntityType(principalEntityTypeName)!.Name, principalKeySet: keyPropertyNames.Length > 0); /// @@ -265,12 +267,12 @@ public virtual ReferenceReferenceBuilder HasPrincipalKey( /// [EntityFrameworkInternal] protected virtual InternalForeignKeyBuilder HasPrincipalKeyBuilder( - [CanBeNull] EntityType principalEntityType, + [CanBeNull] EntityType? principalEntityType, [NotNull] string principalEntityTypeName, [NotNull] IReadOnlyList foreignKeyPropertyNames) => HasPrincipalKeyBuilder( principalEntityType, principalEntityTypeName, - b => b.HasPrincipalKey(foreignKeyPropertyNames, ConfigurationSource.Explicit)); + b => b.HasPrincipalKey(foreignKeyPropertyNames, ConfigurationSource.Explicit)!); /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -285,10 +287,10 @@ protected virtual InternalForeignKeyBuilder HasPrincipalKeyBuilder( [NotNull] IReadOnlyList foreignKeyMembers) => HasPrincipalKeyBuilder( principalEntityType, principalEntityTypeName, - b => b.HasPrincipalKey(foreignKeyMembers, ConfigurationSource.Explicit)); + b => b.HasPrincipalKey(foreignKeyMembers, ConfigurationSource.Explicit)!); private InternalForeignKeyBuilder HasPrincipalKeyBuilder( - EntityType principalEntityType, + EntityType? principalEntityType, string principalEntityTypeName, Func hasPrincipalKey) { @@ -303,10 +305,10 @@ private InternalForeignKeyBuilder HasPrincipalKeyBuilder( using var batch = principalEntityType.Model.DelayConventions(); var builder = Builder.HasEntityTypes( - principalEntityType, GetOtherEntityType(principalEntityType), ConfigurationSource.Explicit); + principalEntityType, GetOtherEntityType(principalEntityType), ConfigurationSource.Explicit)!; builder = hasPrincipalKey(builder); - return batch.Run(builder); + return batch.Run(builder)!; } /// @@ -316,7 +318,7 @@ private InternalForeignKeyBuilder HasPrincipalKeyBuilder( /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [EntityFrameworkInternal] - protected virtual EntityType ResolveEntityType([NotNull] string entityTypeName) + protected virtual EntityType? ResolveEntityType([NotNull] string entityTypeName) { if (DeclaringEntityType.Name == entityTypeName) { @@ -356,7 +358,7 @@ protected virtual EntityType ResolveEntityType([NotNull] string entityTypeName) /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [EntityFrameworkInternal] - protected virtual EntityType ResolveEntityType([NotNull] Type entityType) + protected virtual EntityType? ResolveEntityType([NotNull] Type entityType) { if (DeclaringEntityType.ClrType == entityType) { @@ -376,7 +378,7 @@ private EntityType GetOtherEntityType(EntityType entityType) /// A value indicating whether this is a required relationship. /// The same builder instance so that multiple configuration calls can be chained. public virtual ReferenceReferenceBuilder IsRequired(bool required = true) - => new(Builder.IsRequired(required, ConfigurationSource.Explicit), this, requiredSet: true); + => new(Builder.IsRequired(required, ConfigurationSource.Explicit)!, this, requiredSet: true); /// /// Configures the operation applied to dependent entities in the relationship when the @@ -385,6 +387,6 @@ public virtual ReferenceReferenceBuilder IsRequired(bool required = true) /// The action to perform. /// The same builder instance so that multiple configuration calls can be chained. public virtual ReferenceReferenceBuilder OnDelete(DeleteBehavior deleteBehavior) - => new(Builder.OnDelete(deleteBehavior, ConfigurationSource.Explicit), this); + => new(Builder.OnDelete(deleteBehavior, ConfigurationSource.Explicit)!, this); } } diff --git a/src/EFCore/Metadata/Builders/ReferenceReferenceBuilder`.cs b/src/EFCore/Metadata/Builders/ReferenceReferenceBuilder`.cs index ef6f35f1997..33c315a393e 100644 --- a/src/EFCore/Metadata/Builders/ReferenceReferenceBuilder`.cs +++ b/src/EFCore/Metadata/Builders/ReferenceReferenceBuilder`.cs @@ -9,6 +9,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Internal; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Builders { /// @@ -44,7 +46,7 @@ public ReferenceReferenceBuilder( [EntityFrameworkInternal] protected ReferenceReferenceBuilder( [NotNull] InternalForeignKeyBuilder builder, - [CanBeNull] ReferenceReferenceBuilder oldBuilder, + [NotNull] ReferenceReferenceBuilder oldBuilder, bool inverted = false, bool foreignKeySet = false, bool principalKeySet = false, @@ -100,7 +102,8 @@ protected ReferenceReferenceBuilder( dependentEntityTypeName, Check.NotNull(foreignKeyPropertyNames, nameof(foreignKeyPropertyNames))), this, - inverted: Builder.Metadata.DeclaringEntityType.Name != ResolveEntityType(dependentEntityTypeName).Name, + // TODO-NULLABLE: NRE if entity type cannot be resolved? + inverted: Builder.Metadata.DeclaringEntityType.Name != ResolveEntityType(dependentEntityTypeName)!.Name, foreignKeySet: foreignKeyPropertyNames.Length > 0); /// @@ -210,7 +213,8 @@ public virtual ReferenceReferenceBuilder HasForeignKey< where TDependentEntity : class => new( HasForeignKeyBuilder( - ResolveEntityType(typeof(TDependentEntity)), + // TODO-NULLABLE: NRE if entity type cannot be resolved? + ResolveEntityType(typeof(TDependentEntity))!, typeof(TDependentEntity).ShortDisplayName(), Check.NotNull(foreignKeyExpression, nameof(foreignKeyExpression)).GetMemberAccessList()), this, @@ -294,8 +298,7 @@ public virtual ReferenceReferenceBuilder HasPrincipalKe /// entity type. /// /// - /// The entity type that is the principal in this relationship. That is, the type - /// that has the reference key properties. + /// The entity type that is the principal in this relationship. That is, the type that has the reference key properties. /// /// /// @@ -313,7 +316,7 @@ public virtual ReferenceReferenceBuilder HasPrincipalKe where TPrincipalEntity : class => new( HasPrincipalKeyBuilder( - ResolveEntityType(typeof(TPrincipalEntity)), + ResolveEntityType(typeof(TPrincipalEntity))!, typeof(TPrincipalEntity).ShortDisplayName(), Check.NotNull(keyExpression, nameof(keyExpression)).GetMemberAccessList()), this, @@ -327,10 +330,7 @@ public virtual ReferenceReferenceBuilder HasPrincipalKe /// A value indicating whether this is a required relationship. /// The same builder instance so that multiple configuration calls can be chained. public new virtual ReferenceReferenceBuilder IsRequired(bool required = true) - => new( - Builder.IsRequired(required, ConfigurationSource.Explicit), - this, - requiredSet: true); + => new(Builder.IsRequired(required, ConfigurationSource.Explicit)!, this, requiredSet: true); /// /// Configures the operation applied to dependent entities in the relationship when the @@ -339,6 +339,6 @@ public virtual ReferenceReferenceBuilder HasPrincipalKe /// The action to perform. /// The same builder instance so that multiple configuration calls can be chained. public new virtual ReferenceReferenceBuilder OnDelete(DeleteBehavior deleteBehavior) - => new(Builder.OnDelete(deleteBehavior, ConfigurationSource.Explicit), this); + => new(Builder.OnDelete(deleteBehavior, ConfigurationSource.Explicit)!, this); } } diff --git a/src/EFCore/Metadata/Builders/RelationshipBuilderBase.cs b/src/EFCore/Metadata/Builders/RelationshipBuilderBase.cs index 7471da6a206..8c84c527d56 100644 --- a/src/EFCore/Metadata/Builders/RelationshipBuilderBase.cs +++ b/src/EFCore/Metadata/Builders/RelationshipBuilderBase.cs @@ -8,6 +8,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Internal; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Builders { /// @@ -15,10 +17,12 @@ namespace Microsoft.EntityFrameworkCore.Metadata.Builders /// public abstract class RelationshipBuilderBase : IInfrastructure { - private readonly IReadOnlyList _foreignKeyProperties; - private readonly IReadOnlyList _principalKeyProperties; + private readonly IReadOnlyList? _foreignKeyProperties; + private readonly IReadOnlyList? _principalKeyProperties; private readonly bool? _required; + // TODO-NULLABLE: Refactored the construction here, please confirm it makes sense + /// /// 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 @@ -30,8 +34,12 @@ protected RelationshipBuilderBase( [NotNull] IMutableEntityType principalEntityType, [NotNull] IMutableEntityType dependentEntityType, [NotNull] IMutableForeignKey foreignKey) - : this(((ForeignKey)foreignKey).Builder, null) { + Check.NotNull(principalEntityType, nameof(principalEntityType)); + Check.NotNull(dependentEntityType, nameof(dependentEntityType)); + + Builder = ((ForeignKey)foreignKey).Builder; + PrincipalEntityType = principalEntityType; DependentEntityType = dependentEntityType; } @@ -45,7 +53,7 @@ protected RelationshipBuilderBase( [EntityFrameworkInternal] protected RelationshipBuilderBase( [NotNull] InternalForeignKeyBuilder builder, - [CanBeNull] RelationshipBuilderBase oldBuilder, + [NotNull] RelationshipBuilderBase oldBuilder, bool foreignKeySet = false, bool principalKeySet = false, bool requiredSet = false) @@ -53,31 +61,28 @@ protected RelationshipBuilderBase( Check.NotNull(builder, nameof(builder)); Builder = builder; - if (oldBuilder != null) - { - PrincipalEntityType = oldBuilder.PrincipalEntityType; - DependentEntityType = oldBuilder.DependentEntityType; - _foreignKeyProperties = foreignKeySet - ? builder.Metadata.Properties - : ((EntityType)oldBuilder.DependentEntityType).Builder.GetActualProperties(oldBuilder._foreignKeyProperties, null); - _principalKeyProperties = principalKeySet - ? builder.Metadata.PrincipalKey.Properties - : ((EntityType)oldBuilder.PrincipalEntityType).Builder.GetActualProperties(oldBuilder._principalKeyProperties, null); - _required = requiredSet - ? builder.Metadata.IsRequired - : oldBuilder._required; - - var foreignKey = builder.Metadata; - ForeignKey.AreCompatible( - (EntityType)oldBuilder.PrincipalEntityType, - (EntityType)oldBuilder.DependentEntityType, - foreignKey.DependentToPrincipal?.GetIdentifyingMemberInfo(), - foreignKey.PrincipalToDependent?.GetIdentifyingMemberInfo(), - _foreignKeyProperties, - _principalKeyProperties, - foreignKey.IsUnique, - shouldThrow: true); - } + PrincipalEntityType = oldBuilder.PrincipalEntityType; + DependentEntityType = oldBuilder.DependentEntityType; + _foreignKeyProperties = foreignKeySet + ? builder.Metadata.Properties + : ((EntityType)oldBuilder.DependentEntityType).Builder.GetActualProperties(oldBuilder._foreignKeyProperties, null); + _principalKeyProperties = principalKeySet + ? builder.Metadata.PrincipalKey.Properties + : ((EntityType)oldBuilder.PrincipalEntityType).Builder.GetActualProperties(oldBuilder._principalKeyProperties, null); + _required = requiredSet + ? builder.Metadata.IsRequired + : oldBuilder._required; + + var foreignKey = builder.Metadata; + ForeignKey.AreCompatible( + (EntityType)oldBuilder.PrincipalEntityType, + (EntityType)oldBuilder.DependentEntityType, + foreignKey.DependentToPrincipal?.GetIdentifyingMemberInfo(), + foreignKey.PrincipalToDependent?.GetIdentifyingMemberInfo(), + _foreignKeyProperties, + _principalKeyProperties, + foreignKey.IsUnique, + shouldThrow: true); } /// @@ -126,7 +131,7 @@ IConventionForeignKeyBuilder IInfrastructure.Insta /// /// A string that represents the current object. [EditorBrowsable(EditorBrowsableState.Never)] - public override string ToString() + public override string? ToString() => base.ToString(); /// @@ -136,7 +141,7 @@ public override string ToString() /// if the specified object is equal to the current object; otherwise, . [EditorBrowsable(EditorBrowsableState.Never)] // ReSharper disable once BaseObjectEqualsIsObjectEquals - public override bool Equals(object obj) + public override bool Equals(object? obj) => base.Equals(obj); /// diff --git a/src/EFCore/Metadata/Conventions/BackingFieldAttributeConvention.cs b/src/EFCore/Metadata/Conventions/BackingFieldAttributeConvention.cs index b7964d098e5..38070c35bad 100644 --- a/src/EFCore/Metadata/Conventions/BackingFieldAttributeConvention.cs +++ b/src/EFCore/Metadata/Conventions/BackingFieldAttributeConvention.cs @@ -6,6 +6,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// diff --git a/src/EFCore/Metadata/Conventions/BackingFieldConvention.cs b/src/EFCore/Metadata/Conventions/BackingFieldConvention.cs index 8ddf424f55a..9a5e7d459dd 100644 --- a/src/EFCore/Metadata/Conventions/BackingFieldConvention.cs +++ b/src/EFCore/Metadata/Conventions/BackingFieldConvention.cs @@ -12,6 +12,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata.Internal; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// @@ -111,7 +113,7 @@ private void DiscoverField(IConventionPropertyBaseBuilder conventionPropertyBase } } - private FieldInfo GetFieldToSet(IConventionPropertyBase propertyBase) + private FieldInfo? GetFieldToSet(IConventionPropertyBase? propertyBase) { if (propertyBase == null || !ConfigurationSource.Convention.Overrides(propertyBase.GetFieldInfoConfigurationSource()) @@ -140,9 +142,9 @@ private FieldInfo GetFieldToSet(IConventionPropertyBase propertyBase) return null; } - private static FieldInfo TryMatchFieldName( + private static FieldInfo? TryMatchFieldName( IConventionPropertyBase propertyBase, - IConventionEntityType entityType, + IConventionEntityType? entityType, Type entityClrType) { var propertyName = propertyBase.Name; @@ -164,7 +166,7 @@ private static FieldInfo TryMatchFieldName( } else { - fields = entityType.GetRuntimeFields(); + fields = entityType.GetRuntimeFields()!; } var sortedFields = fields.OrderBy(p => p.Key, StringComparer.Ordinal).ToArray(); @@ -187,13 +189,13 @@ private static FieldInfo TryMatchFieldName( return match; } - private static FieldInfo TryMatch( + private static FieldInfo? TryMatch( KeyValuePair[] array, string prefix, string middle, string suffix, - IConventionPropertyBase propertyBase, - FieldInfo existingMatch, + IConventionPropertyBase? propertyBase, + FieldInfo? existingMatch, Type entityClrType, string propertyName) { @@ -223,7 +225,7 @@ private static FieldInfo TryMatch( if (existingMatch != null && newMatch != existingMatch) { - propertyBase.SetOrRemoveAnnotation( + propertyBase!.SetOrRemoveAnnotation( CoreAnnotationNames.AmbiguousField, CoreStrings.ConflictingBackingFields( propertyName, entityClrType.ShortDisplayName(), existingMatch.Name, newMatch.Name)); diff --git a/src/EFCore/Metadata/Conventions/BaseTypeDiscoveryConvention.cs b/src/EFCore/Metadata/Conventions/BaseTypeDiscoveryConvention.cs index 9ef7a788ebc..18ae0767693 100644 --- a/src/EFCore/Metadata/Conventions/BaseTypeDiscoveryConvention.cs +++ b/src/EFCore/Metadata/Conventions/BaseTypeDiscoveryConvention.cs @@ -10,6 +10,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Internal; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// @@ -48,14 +50,14 @@ public virtual void ProcessEntityTypeAdded( } var model = entityType.Model; - var derivedTypesMap = (Dictionary>)model[CoreAnnotationNames.DerivedTypes]; + var derivedTypesMap = (Dictionary>?)model[CoreAnnotationNames.DerivedTypes]; if (derivedTypesMap == null) { derivedTypesMap = new Dictionary>(); model.SetAnnotation(CoreAnnotationNames.DerivedTypes, derivedTypesMap); } - var baseType = clrType.BaseType; + var baseType = clrType.BaseType!; if (derivedTypesMap.TryGetValue(clrType, out var derivedTypes)) { foreach (var derivedType in derivedTypes) @@ -70,7 +72,7 @@ public virtual void ProcessEntityTypeAdded( otherDerivedTypes.Remove(derivedType); } - otherBaseType = otherBaseType.BaseType; + otherBaseType = otherBaseType.BaseType!; } } @@ -82,7 +84,7 @@ public virtual void ProcessEntityTypeAdded( return; } - IConventionEntityType baseEntityType = null; + IConventionEntityType? baseEntityType = null; while (baseEntityType == null && baseType != typeof(object) && baseType != null) @@ -104,10 +106,9 @@ public virtual void ProcessEntityTypeAdded( if (!baseEntityType.HasSharedClrType && baseEntityType.FindOwnership() == null) { - entityTypeBuilder = entityTypeBuilder.HasBaseType(baseEntityType); - if (entityTypeBuilder != null) + if (entityTypeBuilder.HasBaseType(baseEntityType) is IConventionEntityTypeBuilder newEntityTypeBuilder) { - context.StopProcessingIfChanged(entityTypeBuilder); + context.StopProcessingIfChanged(newEntityTypeBuilder); } } } diff --git a/src/EFCore/Metadata/Conventions/CascadeDeleteConvention.cs b/src/EFCore/Metadata/Conventions/CascadeDeleteConvention.cs index 5adf2f6d70c..2c4537e2b7c 100644 --- a/src/EFCore/Metadata/Conventions/CascadeDeleteConvention.cs +++ b/src/EFCore/Metadata/Conventions/CascadeDeleteConvention.cs @@ -5,6 +5,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// diff --git a/src/EFCore/Metadata/Conventions/ChangeTrackingStrategyConvention.cs b/src/EFCore/Metadata/Conventions/ChangeTrackingStrategyConvention.cs index 731d551f4af..8880c3a8c73 100644 --- a/src/EFCore/Metadata/Conventions/ChangeTrackingStrategyConvention.cs +++ b/src/EFCore/Metadata/Conventions/ChangeTrackingStrategyConvention.cs @@ -6,6 +6,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata.Internal; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// diff --git a/src/EFCore/Metadata/Conventions/ConcurrencyCheckAttributeConvention.cs b/src/EFCore/Metadata/Conventions/ConcurrencyCheckAttributeConvention.cs index f01b9ae6a60..56e395f46f8 100644 --- a/src/EFCore/Metadata/Conventions/ConcurrencyCheckAttributeConvention.cs +++ b/src/EFCore/Metadata/Conventions/ConcurrencyCheckAttributeConvention.cs @@ -7,6 +7,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// diff --git a/src/EFCore/Metadata/Conventions/ConstructorBindingConvention.cs b/src/EFCore/Metadata/Conventions/ConstructorBindingConvention.cs index 555ecd947ac..cf986f31682 100644 --- a/src/EFCore/Metadata/Conventions/ConstructorBindingConvention.cs +++ b/src/EFCore/Metadata/Conventions/ConstructorBindingConvention.cs @@ -12,6 +12,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata.Internal; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// @@ -114,7 +116,7 @@ public virtual void ProcessModelFinalizing( if (foundBindings.Count == 0) { var constructorErrors = bindingFailures.SelectMany(f => f) - .GroupBy(f => f.Member as ConstructorInfo) + .GroupBy(f => (ConstructorInfo)f.Member) .Select( x => CoreStrings.ConstructorBindingFailed( string.Join("', '", x.Select(f => f.Name)), diff --git a/src/EFCore/Metadata/Conventions/ConventionSet.cs b/src/EFCore/Metadata/Conventions/ConventionSet.cs index 1887836de4c..e2073b1404a 100644 --- a/src/EFCore/Metadata/Conventions/ConventionSet.cs +++ b/src/EFCore/Metadata/Conventions/ConventionSet.cs @@ -8,6 +8,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// diff --git a/src/EFCore/Metadata/Conventions/DatabaseGeneratedAttributeConvention.cs b/src/EFCore/Metadata/Conventions/DatabaseGeneratedAttributeConvention.cs index 109eeb68730..21f421584bf 100644 --- a/src/EFCore/Metadata/Conventions/DatabaseGeneratedAttributeConvention.cs +++ b/src/EFCore/Metadata/Conventions/DatabaseGeneratedAttributeConvention.cs @@ -7,6 +7,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// diff --git a/src/EFCore/Metadata/Conventions/DbSetFindingConvention.cs b/src/EFCore/Metadata/Conventions/DbSetFindingConvention.cs index c355376ad1b..896a1c95082 100644 --- a/src/EFCore/Metadata/Conventions/DbSetFindingConvention.cs +++ b/src/EFCore/Metadata/Conventions/DbSetFindingConvention.cs @@ -5,6 +5,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// diff --git a/src/EFCore/Metadata/Conventions/DerivedTypeDiscoveryConvention.cs b/src/EFCore/Metadata/Conventions/DerivedTypeDiscoveryConvention.cs index bea401fac95..9d39801ca87 100644 --- a/src/EFCore/Metadata/Conventions/DerivedTypeDiscoveryConvention.cs +++ b/src/EFCore/Metadata/Conventions/DerivedTypeDiscoveryConvention.cs @@ -7,6 +7,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata.Internal; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// diff --git a/src/EFCore/Metadata/Conventions/DiscriminatorConvention.cs b/src/EFCore/Metadata/Conventions/DiscriminatorConvention.cs index 6db0ae61344..b840555d981 100644 --- a/src/EFCore/Metadata/Conventions/DiscriminatorConvention.cs +++ b/src/EFCore/Metadata/Conventions/DiscriminatorConvention.cs @@ -7,6 +7,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// @@ -37,22 +39,23 @@ public DiscriminatorConvention([NotNull] ProviderConventionSetBuilderDependencie /// Additional information associated with convention execution. public virtual void ProcessEntityTypeBaseTypeChanged( IConventionEntityTypeBuilder entityTypeBuilder, - IConventionEntityType newBaseType, - IConventionEntityType oldBaseType, + IConventionEntityType? newBaseType, + IConventionEntityType? oldBaseType, IConventionContext context) { if (oldBaseType != null + && oldBaseType.IsInModel && oldBaseType.BaseType == null && !oldBaseType.GetDirectlyDerivedTypes().Any()) { - oldBaseType.Builder?.HasNoDiscriminator(); + oldBaseType.Builder.HasNoDiscriminator(); } var conventionEntityTypeBuilder = entityTypeBuilder; var entityType = entityTypeBuilder.Metadata; var derivedEntityTypes = entityType.GetDerivedTypes().ToList(); - IConventionDiscriminatorBuilder discriminator; + IConventionDiscriminatorBuilder? discriminator; if (newBaseType == null) { if (derivedEntityTypes.Count == 0) @@ -99,10 +102,11 @@ public virtual void ProcessEntityTypeRemoved( { var oldBaseType = entityType.BaseType; if (oldBaseType != null + && oldBaseType.IsInModel && oldBaseType.BaseType == null && !oldBaseType.GetDirectlyDerivedTypes().Any()) { - oldBaseType.Builder?.HasNoDiscriminator(); + oldBaseType.Builder.HasNoDiscriminator(); } } diff --git a/src/EFCore/Metadata/Conventions/EntityTypeAttributeConventionBase.cs b/src/EFCore/Metadata/Conventions/EntityTypeAttributeConventionBase.cs index e0d26c00ce5..50afe796f4a 100644 --- a/src/EFCore/Metadata/Conventions/EntityTypeAttributeConventionBase.cs +++ b/src/EFCore/Metadata/Conventions/EntityTypeAttributeConventionBase.cs @@ -9,6 +9,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// diff --git a/src/EFCore/Metadata/Conventions/ForeignKeyAttributeConvention.cs b/src/EFCore/Metadata/Conventions/ForeignKeyAttributeConvention.cs index 7ce1579a221..20f18d66aab 100644 --- a/src/EFCore/Metadata/Conventions/ForeignKeyAttributeConvention.cs +++ b/src/EFCore/Metadata/Conventions/ForeignKeyAttributeConvention.cs @@ -13,6 +13,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Internal; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// @@ -75,13 +77,13 @@ public virtual void ProcessNavigationAdded( if (newRelationshipBuilder != null) { var newNavigationBuilder = onDependent - ? newRelationshipBuilder.Metadata.DependentToPrincipal.Builder - : newRelationshipBuilder.Metadata.PrincipalToDependent.Builder; + ? newRelationshipBuilder.Metadata.DependentToPrincipal!.Builder + : newRelationshipBuilder.Metadata.PrincipalToDependent!.Builder; context.StopProcessingIfChanged(newNavigationBuilder); } } - private IConventionForeignKeyBuilder UpdateRelationshipBuilder( + private IConventionForeignKeyBuilder? UpdateRelationshipBuilder( IConventionForeignKeyBuilder relationshipBuilder, IConventionContext context) { @@ -102,13 +104,14 @@ var fkPropertyOnDependent fkPropertyOnPrincipal, fkPropertyOnDependent); - relationshipBuilder = SplitNavigationsToSeparateRelationships(relationshipBuilder); - if (relationshipBuilder == null) + var newBuilder = SplitNavigationsToSeparateRelationships(relationshipBuilder); + if (newBuilder is null) { context.StopProcessing(); return null; } + relationshipBuilder = newBuilder; fkPropertyOnPrincipal = null; } @@ -124,13 +127,14 @@ var fkPropertiesOnDependentToPrincipal Dependencies.Logger.ForeignKeyAttributesOnBothNavigationsWarning( relationshipBuilder.Metadata.DependentToPrincipal, relationshipBuilder.Metadata.PrincipalToDependent); - relationshipBuilder = SplitNavigationsToSeparateRelationships(relationshipBuilder); - if (relationshipBuilder == null) + var newBuilder = SplitNavigationsToSeparateRelationships(relationshipBuilder); + if (newBuilder is null) { context.StopProcessing(); return null; } + relationshipBuilder = newBuilder; fkPropertiesOnPrincipalToDependent = null; } @@ -156,7 +160,7 @@ var fkPropertiesOnDependentToPrincipal } else { - if (foreignKey.PrincipalToDependent.IsCollection) + if (foreignKey.PrincipalToDependent!.IsCollection) { context.StopProcessing(); return null; @@ -192,13 +196,14 @@ var fkPropertiesOnDependentToPrincipal : relationshipBuilder.Metadata.PrincipalToDependent, fkProperty); - relationshipBuilder = SplitNavigationsToSeparateRelationships(relationshipBuilder); - if (relationshipBuilder == null) + var newBuilder = SplitNavigationsToSeparateRelationships(relationshipBuilder); + if (newBuilder is null) { context.StopProcessing(); return null; } + relationshipBuilder = newBuilder; upgradePrincipalToDependentNavigationSource = false; fkPropertiesToSet = fkPropertiesOnDependentToPrincipal @@ -221,19 +226,19 @@ var fkPropertiesOnDependentToPrincipal if (upgradeDependentToPrincipalNavigationSource) { newRelationshipBuilder = newRelationshipBuilder.HasNavigation( - newRelationshipBuilder.Metadata.DependentToPrincipal.Name, pointsToPrincipal: true, fromDataAnnotation: true); + newRelationshipBuilder.Metadata.DependentToPrincipal!.Name, pointsToPrincipal: true, fromDataAnnotation: true)!; } if (upgradePrincipalToDependentNavigationSource) { newRelationshipBuilder = newRelationshipBuilder.HasNavigation( - newRelationshipBuilder.Metadata.PrincipalToDependent.Name, pointsToPrincipal: false, fromDataAnnotation: true); + newRelationshipBuilder.Metadata.PrincipalToDependent!.Name, pointsToPrincipal: false, fromDataAnnotation: true)!; } if (shouldInvert) { newRelationshipBuilder = newRelationshipBuilder.HasEntityTypes( - foreignKey.DeclaringEntityType, foreignKey.PrincipalEntityType, fromDataAnnotation: true); + foreignKey.DeclaringEntityType, foreignKey.PrincipalEntityType, fromDataAnnotation: true)!; } else { @@ -260,12 +265,12 @@ var fkPropertiesOnDependentToPrincipal return newRelationshipBuilder?.HasForeignKey(fkPropertiesToSet, fromDataAnnotation: true); } - private static IConventionForeignKeyBuilder SplitNavigationsToSeparateRelationships( + private static IConventionForeignKeyBuilder? SplitNavigationsToSeparateRelationships( IConventionForeignKeyBuilder relationshipBuilder) { var foreignKey = relationshipBuilder.Metadata; - var dependentToPrincipalNavigationName = foreignKey.DependentToPrincipal.Name; - var principalToDependentNavigationName = foreignKey.PrincipalToDependent.Name; + var dependentToPrincipalNavigationName = foreignKey.DependentToPrincipal!.Name; + var principalToDependentNavigationName = foreignKey.PrincipalToDependent!.Name; if (GetInversePropertyAttribute(foreignKey.PrincipalToDependent) != null || GetInversePropertyAttribute(foreignKey.DependentToPrincipal) != null) @@ -279,11 +284,7 @@ private static IConventionForeignKeyBuilder SplitNavigationsToSeparateRelationsh foreignKey.PrincipalEntityType.DisplayName())); } - relationshipBuilder = relationshipBuilder.HasNavigation( - (string)null, - pointsToPrincipal: false, - fromDataAnnotation: true); - return relationshipBuilder == null + return relationshipBuilder.HasNavigation((string?)null, pointsToPrincipal: false, fromDataAnnotation: true) is null ? null : foreignKey.PrincipalEntityType.Builder.HasRelationship( foreignKey.DeclaringEntityType, @@ -295,20 +296,20 @@ private static IConventionForeignKeyBuilder SplitNavigationsToSeparateRelationsh : relationshipBuilder; } - private static ForeignKeyAttribute GetForeignKeyAttribute(IConventionTypeBase entityType, string propertyName) + private static ForeignKeyAttribute? GetForeignKeyAttribute(IConventionTypeBase entityType, string propertyName) => entityType.GetRuntimeProperties()?.Values .FirstOrDefault( p => string.Equals(p.GetSimpleMemberName(), propertyName, StringComparison.OrdinalIgnoreCase) && Attribute.IsDefined(p, typeof(ForeignKeyAttribute), inherit: true)) ?.GetCustomAttribute(inherit: true); - private static ForeignKeyAttribute GetForeignKeyAttribute(IConventionNavigationBase navigation) + private static ForeignKeyAttribute? GetForeignKeyAttribute(IConventionNavigationBase navigation) => GetAttribute(navigation.GetIdentifyingMemberInfo()); - private static InversePropertyAttribute GetInversePropertyAttribute(IConventionNavigation navigation) + private static InversePropertyAttribute? GetInversePropertyAttribute(IConventionNavigation navigation) => GetAttribute(navigation.GetIdentifyingMemberInfo()); - private static TAttribute GetAttribute(MemberInfo memberInfo) + private static TAttribute? GetAttribute(MemberInfo? memberInfo) where TAttribute : Attribute { if (memberInfo == null @@ -321,17 +322,17 @@ private static TAttribute GetAttribute(MemberInfo memberInfo) } [ContractAnnotation("navigationName:null => null")] - private MemberInfo FindForeignKeyAttributeOnProperty(IConventionEntityType entityType, string navigationName) + private MemberInfo? FindForeignKeyAttributeOnProperty(IConventionEntityType entityType, string? navigationName) { if (string.IsNullOrWhiteSpace(navigationName)) { return null; } - MemberInfo candidateProperty = null; + MemberInfo? candidateProperty = null; - foreach (var memberInfo in entityType.GetRuntimeProperties().Values.Cast() - .Concat(entityType.GetRuntimeFields().Values)) + foreach (var memberInfo in entityType.GetRuntimeProperties()!.Values.Cast() + .Concat(entityType.GetRuntimeFields()!.Values)) { if (entityType.Builder.IsIgnored(memberInfo.GetSimpleMemberName()) || !Attribute.IsDefined(memberInfo, typeof(ForeignKeyAttribute), inherit: true)) @@ -339,7 +340,7 @@ private MemberInfo FindForeignKeyAttributeOnProperty(IConventionEntityType entit continue; } - var attribute = memberInfo.GetCustomAttribute(inherit: true); + var attribute = memberInfo.GetCustomAttribute(inherit: true)!; if (attribute.Name != navigationName || (memberInfo is PropertyInfo propertyInfo @@ -373,7 +374,7 @@ private MemberInfo FindForeignKeyAttributeOnProperty(IConventionEntityType entit return candidateProperty; } - private Type FindCandidateNavigationPropertyType([NotNull] PropertyInfo propertyInfo) + private Type? FindCandidateNavigationPropertyType([NotNull] PropertyInfo propertyInfo) => Dependencies.MemberClassifier.FindCandidateNavigationPropertyType(propertyInfo); private bool IsNavigationToSharedType(IConventionModel model, PropertyInfo propertyInfo) @@ -381,13 +382,13 @@ private bool IsNavigationToSharedType(IConventionModel model, PropertyInfo prope || (propertyInfo.PropertyType.TryGetSequenceType() is Type elementType && model.IsShared(elementType)); - private static IReadOnlyList FindCandidateDependentPropertiesThroughNavigation( + private static IReadOnlyList? FindCandidateDependentPropertiesThroughNavigation( IConventionForeignKeyBuilder relationshipBuilder, bool pointsToPrincipal) { var navigation = pointsToPrincipal ? relationshipBuilder.Metadata.DependentToPrincipal - : relationshipBuilder.Metadata.PrincipalToDependent; + : relationshipBuilder.Metadata.PrincipalToDependent!; var navigationFkAttribute = navigation != null ? GetForeignKeyAttribute(navigation) @@ -400,13 +401,13 @@ private static IReadOnlyList FindCandidateDependentPropertiesThroughNavi if (properties.Any(string.IsNullOrWhiteSpace)) { throw new InvalidOperationException( - CoreStrings.InvalidPropertyListOnNavigation(navigation.Name, navigation.DeclaringEntityType.DisplayName())); + CoreStrings.InvalidPropertyListOnNavigation(navigation!.Name, navigation.DeclaringEntityType.DisplayName())); } var navigationPropertyTargetType = - navigation.DeclaringEntityType.GetRuntimeProperties()[navigation.Name].PropertyType; + navigation!.DeclaringEntityType.GetRuntimeProperties()![navigation.Name].PropertyType; - var otherNavigations = navigation.DeclaringEntityType.GetRuntimeProperties().Values + var otherNavigations = navigation.DeclaringEntityType.GetRuntimeProperties()!.Values .Where(p => p.PropertyType == navigationPropertyTargetType && p.GetSimpleMemberName() != navigation.Name) .OrderBy(p => p.GetSimpleMemberName()); diff --git a/src/EFCore/Metadata/Conventions/ForeignKeyIndexConvention.cs b/src/EFCore/Metadata/Conventions/ForeignKeyIndexConvention.cs index 57ecf7b16f8..5885e77a980 100644 --- a/src/EFCore/Metadata/Conventions/ForeignKeyIndexConvention.cs +++ b/src/EFCore/Metadata/Conventions/ForeignKeyIndexConvention.cs @@ -10,6 +10,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// @@ -86,7 +88,7 @@ public virtual void ProcessForeignKeyPropertiesChanged( if (!foreignKey.Properties.SequenceEqual(oldDependentProperties)) { OnForeignKeyRemoved(foreignKey.DeclaringEntityType, oldDependentProperties); - if (relationshipBuilder.Metadata.Builder != null) + if (relationshipBuilder.Metadata.IsInModel) { CreateIndex(foreignKey.Properties, foreignKey.IsUnique, foreignKey.DeclaringEntityType.Builder); } @@ -162,8 +164,8 @@ public virtual void ProcessKeyRemoved( /// Additional information associated with convention execution. public virtual void ProcessEntityTypeBaseTypeChanged( IConventionEntityTypeBuilder entityTypeBuilder, - IConventionEntityType newBaseType, - IConventionEntityType oldBaseType, + IConventionEntityType? newBaseType, + IConventionEntityType? oldBaseType, IConventionContext context) { if (entityTypeBuilder.Metadata.BaseType != newBaseType) @@ -183,7 +185,7 @@ public virtual void ProcessEntityTypeBaseTypeChanged( } else if (newBaseType != null) { - var coveringKey = baseKeys.FirstOrDefault( + var coveringKey = baseKeys!.FirstOrDefault( k => AreIndexedBy(foreignKey.Properties, foreignKey.IsUnique, k.Properties, coveringIndexUnique: true)); if (coveringKey != null) { @@ -191,7 +193,7 @@ public virtual void ProcessEntityTypeBaseTypeChanged( } else { - var coveringIndex = baseIndexes.FirstOrDefault( + var coveringIndex = baseIndexes!.FirstOrDefault( i => AreIndexedBy(foreignKey.Properties, foreignKey.IsUnique, i.Properties, i.IsUnique)); if (coveringIndex != null) { @@ -318,7 +320,7 @@ public virtual void ProcessIndexUniquenessChanged( /// Whether the index to create should be unique. /// The builder for the entity type. /// The created index. - protected virtual IConventionIndex CreateIndex( + protected virtual IConventionIndex? CreateIndex( [NotNull] IReadOnlyList properties, bool unique, [NotNull] IConventionEntityTypeBuilder entityTypeBuilder) @@ -374,7 +376,7 @@ public virtual void ProcessModelFinalizing( { var definition = CoreResources.LogRedundantIndexRemoved(Dependencies.Logger); if (!Dependencies.Logger.ShouldLog(definition) - && !Dependencies.Logger.DiagnosticSource.IsEnabled(definition.EventId.Name)) + && !Dependencies.Logger.DiagnosticSource.IsEnabled(definition.EventId.Name!)) { return; } diff --git a/src/EFCore/Metadata/Conventions/ForeignKeyPropertyDiscoveryConvention.cs b/src/EFCore/Metadata/Conventions/ForeignKeyPropertyDiscoveryConvention.cs index 1ab6ab3d4b9..5a17850fc3d 100644 --- a/src/EFCore/Metadata/Conventions/ForeignKeyPropertyDiscoveryConvention.cs +++ b/src/EFCore/Metadata/Conventions/ForeignKeyPropertyDiscoveryConvention.cs @@ -11,6 +11,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata.Internal; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// @@ -103,7 +105,7 @@ private IConventionForeignKeyBuilder ProcessForeignKey( relationshipBuilder.IsRequired(true); } - var newRelationshipBuilder = DiscoverProperties(relationshipBuilder, context); + var newRelationshipBuilder = DiscoverProperties(relationshipBuilder, context)!; // If new properties were used for this relationship we have to examine the other foreign keys // in case they can use the properties used previously. @@ -116,7 +118,7 @@ private IConventionForeignKeyBuilder ProcessForeignKey( foreach (var fk in fksToProcess) { - if (fk.Builder != null) + if (fk.IsInModel) { DiscoverProperties(fk.Builder, context); } @@ -125,7 +127,7 @@ private IConventionForeignKeyBuilder ProcessForeignKey( return newRelationshipBuilder; } - private IConventionForeignKeyBuilder DiscoverProperties( + private IConventionForeignKeyBuilder? DiscoverProperties( IConventionForeignKeyBuilder relationshipBuilder, IConventionContext context) { @@ -159,7 +161,9 @@ private IConventionForeignKeyBuilder DiscoverProperties( } batch.Dispose(); - return foreignKeyReference.Object?.Builder; + return foreignKeyReference.Object is null || !foreignKeyReference.Object.IsInModel + ? null + : foreignKeyReference.Object.Builder; } var invertible = true; @@ -172,7 +176,7 @@ private IConventionForeignKeyBuilder DiscoverProperties( && foreignKey.PrincipalEntityType.IsAssignableFrom(foreignKey.DeclaringEntityType))) { relationshipBuilder = relationshipBuilder.HasEntityTypes( - foreignKey.PrincipalEntityType, foreignKey.DeclaringEntityType); + foreignKey.PrincipalEntityType, foreignKey.DeclaringEntityType)!; invertible = false; } else if (ConfigurationSource.Convention.Overrides(foreignKey.GetPrincipalEndConfigurationSource()) @@ -198,14 +202,15 @@ private IConventionForeignKeyBuilder DiscoverProperties( { var invertedRelationshipBuilder = relationshipBuilder .HasEntityTypes(foreignKey.DeclaringEntityType, foreignKey.PrincipalEntityType); - var invertedFk = invertedRelationshipBuilder?.Metadata; - if (invertedFk?.IsSelfReferencing() == true) + if (invertedRelationshipBuilder is not null + && invertedRelationshipBuilder.Metadata is IConventionForeignKey invertedFk + && invertedFk.IsSelfReferencing()) { invertedRelationshipBuilder = invertedRelationshipBuilder.HasNavigations( invertedFk.PrincipalToDependent?.Name, invertedFk.DependentToPrincipal?.Name); } - return invertedRelationshipBuilder ?? (foreignKey.Builder == null ? null : relationshipBuilder); + return invertedRelationshipBuilder ?? (!foreignKey.IsInModel ? null : relationshipBuilder); } } @@ -235,9 +240,9 @@ private IConventionForeignKeyBuilder DiscoverProperties( { using var batch = context.DelayConventions(); var invertedRelationshipBuilder = relationshipBuilder - .HasEntityTypes(foreignKey.DeclaringEntityType, foreignKey.PrincipalEntityType); + .HasEntityTypes(foreignKey.DeclaringEntityType, foreignKey.PrincipalEntityType)!; return batch.Run( - invertedRelationshipBuilder.HasForeignKey(candidatePropertiesOnPrincipal).Metadata) + invertedRelationshipBuilder.HasForeignKey(candidatePropertiesOnPrincipal)!.Metadata) ?.Builder; } @@ -310,15 +315,15 @@ private IConventionForeignKeyBuilder DiscoverProperties( return newRelationshipBuilder; } - return relationshipBuilder.Metadata.Builder == null ? null : relationshipBuilder; + return relationshipBuilder.Metadata.IsInModel ? relationshipBuilder : null; } - private IReadOnlyList FindCandidateForeignKeyProperties( + private IReadOnlyList? FindCandidateForeignKeyProperties( IConventionForeignKey foreignKey, bool onDependent, bool matchPk = false) { - IReadOnlyList match; + IReadOnlyList? match; var navigation = onDependent ? foreignKey.DependentToPrincipal : foreignKey.PrincipalToDependent; @@ -341,7 +346,7 @@ private IReadOnlyList FindCandidateForeignKeyProperties( return match; } - private static IReadOnlyList GetCompatiblePrimaryKeyProperties( + private static IReadOnlyList? GetCompatiblePrimaryKeyProperties( IConventionEntityType dependentEntityType, IConventionEntityType principalEntityType, IReadOnlyList propertiesToReference) @@ -363,7 +368,7 @@ private bool TryFindMatchingProperties( string baseName, bool onDependent, bool matchPk, - out IReadOnlyList match) + out IReadOnlyList? match) { match = null; var dependentEntityType = onDependent @@ -483,7 +488,7 @@ private bool TryFindMatchingProperties( return true; } - private static IConventionProperty TryGetProperty(IConventionEntityType entityType, string prefix, string suffix) + private static IConventionProperty? TryGetProperty(IConventionEntityType entityType, string prefix, string suffix) { foreach (var property in entityType.GetProperties()) { @@ -523,7 +528,7 @@ public virtual void ProcessPropertyAdded( IConventionContext context) { Process(propertyBuilder, context); - if (propertyBuilder.Metadata.Builder == null) + if (!propertyBuilder.Metadata.IsInModel) { context.StopProcessing(); } @@ -561,7 +566,7 @@ private void Process(IConventionEntityType entityType, IConventionContext contex { foreach (var foreignKey in entityType.GetDeclaredForeignKeys().Concat(entityType.GetDerivedForeignKeys()).ToList()) { - if (foreignKey.Builder != null) + if (foreignKey.IsInModel) { DiscoverProperties(foreignKey.Builder, context); } @@ -569,7 +574,7 @@ private void Process(IConventionEntityType entityType, IConventionContext contex foreach (var foreignKey in entityType.GetReferencingForeignKeys().ToList()) { - if (foreignKey.Builder != null + if (foreignKey.IsInModel && ConfigurationSource.Convention.Overrides(foreignKey.GetPrincipalEndConfigurationSource())) { DiscoverProperties(foreignKey.Builder, context); @@ -586,8 +591,8 @@ private void Process(IConventionEntityType entityType, IConventionContext contex /// Additional information associated with convention execution. public virtual void ProcessPropertyFieldChanged( IConventionPropertyBuilder propertyBuilder, - FieldInfo newFieldInfo, - FieldInfo oldFieldInfo, + FieldInfo? newFieldInfo, + FieldInfo? oldFieldInfo, IConventionContext context) { Process(propertyBuilder, context); @@ -625,7 +630,7 @@ public virtual void ProcessForeignKeyUniquenessChanged( IConventionForeignKeyBuilder relationshipBuilder, IConventionContext context) { - var newRelationshipBuilder = DiscoverProperties(relationshipBuilder, context); + var newRelationshipBuilder = DiscoverProperties(relationshipBuilder, context)!; context.StopProcessingIfChanged(newRelationshipBuilder.Metadata.IsUnique); } @@ -650,7 +655,7 @@ public virtual void ProcessForeignKeyRequirednessChanged( } } - var newForeignKey = batch.Run(DiscoverProperties(relationshipBuilder, context).Metadata); + var newForeignKey = batch.Run(DiscoverProperties(relationshipBuilder, context)!.Metadata); if (newForeignKey != relationshipBuilder.Metadata || newForeignKey.IsRequired != isRequired) { @@ -671,7 +676,7 @@ public virtual void ProcessForeignKeyPropertiesChanged( IConventionKey oldPrincipalKey, IConventionContext> context) { - if (relationshipBuilder.Metadata.Builder == null + if (!relationshipBuilder.Metadata.IsInModel || relationshipBuilder.Metadata.Properties == oldDependentProperties) { return; @@ -679,10 +684,7 @@ public virtual void ProcessForeignKeyPropertiesChanged( ProcessForeignKey(relationshipBuilder, context); - if (relationshipBuilder.Metadata.Builder != null) - { - context.StopProcessingIfChanged(relationshipBuilder.Metadata.Properties); - } + context.StopProcessingIfChanged(relationshipBuilder.Metadata.Properties); } /// @@ -711,7 +713,7 @@ public virtual void ProcessKeyAdded(IConventionKeyBuilder keyBuilder, IConventio if (key.Properties.All(p => foreignKey.Properties.Contains(p)) && (!foreignKey.IsUnique || foreignKey.DeclaringEntityType.BaseType != null)) { - foreignKey.Builder.HasForeignKey((IReadOnlyList)null); + foreignKey.Builder.HasForeignKey((IReadOnlyList?)null); } } } @@ -728,7 +730,7 @@ public virtual void ProcessKeyRemoved( { if ((foreignKey.IsUnique && foreignKey.DeclaringEntityType.BaseType == null) - || foreignKey.Builder == null) + || !foreignKey.IsInModel) { continue; } @@ -746,12 +748,11 @@ public virtual void ProcessKeyRemoved( /// Additional information associated with convention execution. public virtual void ProcessEntityTypePrimaryKeyChanged( IConventionEntityTypeBuilder entityTypeBuilder, - IConventionKey newPrimaryKey, - IConventionKey previousPrimaryKey, + IConventionKey? newPrimaryKey, + IConventionKey? previousPrimaryKey, IConventionContext context) { - if (newPrimaryKey != null - && newPrimaryKey.Builder == null) + if (newPrimaryKey != null && !newPrimaryKey.IsInModel) { return; } @@ -777,13 +778,13 @@ public virtual void ProcessEntityTypePrimaryKeyChanged( /// public virtual void ProcessSkipNavigationForeignKeyChanged( IConventionSkipNavigationBuilder skipNavigationBuilder, - IConventionForeignKey foreignKey, - IConventionForeignKey oldForeignKey, + IConventionForeignKey? foreignKey, + IConventionForeignKey? oldForeignKey, IConventionContext context) { - if (foreignKey?.Builder != null + if (foreignKey?.IsInModel == true && foreignKey.GetPropertiesConfigurationSource() == null - && skipNavigationBuilder.Metadata.Inverse?.Builder != null) + && skipNavigationBuilder.Metadata.Inverse?.IsInModel == true) { DiscoverProperties(foreignKey.Builder, context); } @@ -792,14 +793,14 @@ public virtual void ProcessSkipNavigationForeignKeyChanged( /// public virtual void ProcessSkipNavigationInverseChanged( IConventionSkipNavigationBuilder skipNavigationBuilder, - IConventionSkipNavigation inverse, - IConventionSkipNavigation oldInverse, + IConventionSkipNavigation? inverse, + IConventionSkipNavigation? oldInverse, IConventionContext context) { var foreignKey = skipNavigationBuilder.Metadata.ForeignKey; if (foreignKey != null && foreignKey.GetPropertiesConfigurationSource() == null - && inverse?.Builder != null) + && inverse?.IsInModel == true) { DiscoverProperties(foreignKey.Builder, context); } diff --git a/src/EFCore/Metadata/Conventions/IConvention.cs b/src/EFCore/Metadata/Conventions/IConvention.cs index 48788d2632b..7e5e90f7ce3 100644 --- a/src/EFCore/Metadata/Conventions/IConvention.cs +++ b/src/EFCore/Metadata/Conventions/IConvention.cs @@ -1,6 +1,8 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// diff --git a/src/EFCore/Metadata/Conventions/IConventionBatch.cs b/src/EFCore/Metadata/Conventions/IConventionBatch.cs index df8a455a95a..6cdb6fa08c2 100644 --- a/src/EFCore/Metadata/Conventions/IConventionBatch.cs +++ b/src/EFCore/Metadata/Conventions/IConventionBatch.cs @@ -4,6 +4,8 @@ using System; using JetBrains.Annotations; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// @@ -16,7 +18,7 @@ public interface IConventionBatch : IDisposable /// /// The foreign key to track. /// The new foreign key object if the given one was replaced by a convention. - IConventionForeignKey Run([NotNull] IConventionForeignKey foreignKey); + IConventionForeignKey? Run([NotNull] IConventionForeignKey foreignKey); /// /// Starts tracking changes to the given foreign key. @@ -26,6 +28,7 @@ public interface IConventionBatch : IDisposable /// An object that will contain the reference to the new foreign key instance /// if the given one was replaced by a convention. /// + // TODO-NULLABLE: does this ever refer null (as is implied by the comment?) IMetadataReference Track([NotNull] IConventionForeignKey foreignKey); } } diff --git a/src/EFCore/Metadata/Conventions/IConventionContext.cs b/src/EFCore/Metadata/Conventions/IConventionContext.cs index a5cce34ded2..77ab13d73da 100644 --- a/src/EFCore/Metadata/Conventions/IConventionContext.cs +++ b/src/EFCore/Metadata/Conventions/IConventionContext.cs @@ -1,6 +1,8 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// diff --git a/src/EFCore/Metadata/Conventions/IConventionContext`.cs b/src/EFCore/Metadata/Conventions/IConventionContext`.cs index 4a4f04f3b91..b727217cf68 100644 --- a/src/EFCore/Metadata/Conventions/IConventionContext`.cs +++ b/src/EFCore/Metadata/Conventions/IConventionContext`.cs @@ -3,6 +3,8 @@ using JetBrains.Annotations; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// @@ -19,8 +21,9 @@ public interface IConventionContext : IConventionContext /// The common use case is when the metadata object was replaced by the convention. /// /// - /// The new metadata object. - void StopProcessing([NotNull] TMetadata result); + /// The new metadata object or . + // TODO-NULLABLE: TBC (here and below) + void StopProcessing([CanBeNull] TMetadata? result); /// /// @@ -31,7 +34,7 @@ public interface IConventionContext : IConventionContext /// The common use case is when the metadata object was replaced by the convention. /// /// - /// The new metadata object. - void StopProcessingIfChanged([NotNull] TMetadata result); + /// The new metadata object or . + void StopProcessingIfChanged([CanBeNull] TMetadata? result); } } diff --git a/src/EFCore/Metadata/Conventions/IEntityTypeAddedConvention.cs b/src/EFCore/Metadata/Conventions/IEntityTypeAddedConvention.cs index 293a2a0b9b3..5d20f33615d 100644 --- a/src/EFCore/Metadata/Conventions/IEntityTypeAddedConvention.cs +++ b/src/EFCore/Metadata/Conventions/IEntityTypeAddedConvention.cs @@ -4,6 +4,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Metadata.Builders; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// diff --git a/src/EFCore/Metadata/Conventions/IEntityTypeAnnotationChangedConvention.cs b/src/EFCore/Metadata/Conventions/IEntityTypeAnnotationChangedConvention.cs index 21d9936aacd..4f895b4bfc3 100644 --- a/src/EFCore/Metadata/Conventions/IEntityTypeAnnotationChangedConvention.cs +++ b/src/EFCore/Metadata/Conventions/IEntityTypeAnnotationChangedConvention.cs @@ -4,6 +4,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Metadata.Builders; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// @@ -22,8 +24,8 @@ public interface IEntityTypeAnnotationChangedConvention : IConvention void ProcessEntityTypeAnnotationChanged( [NotNull] IConventionEntityTypeBuilder entityTypeBuilder, [NotNull] string name, - [CanBeNull] IConventionAnnotation annotation, - [CanBeNull] IConventionAnnotation oldAnnotation, + [CanBeNull] IConventionAnnotation? annotation, + [CanBeNull] IConventionAnnotation? oldAnnotation, [NotNull] IConventionContext context); } } diff --git a/src/EFCore/Metadata/Conventions/IEntityTypeBaseTypeChangedConvention.cs b/src/EFCore/Metadata/Conventions/IEntityTypeBaseTypeChangedConvention.cs index a4d2a39035d..ebc2aef5ff4 100644 --- a/src/EFCore/Metadata/Conventions/IEntityTypeBaseTypeChangedConvention.cs +++ b/src/EFCore/Metadata/Conventions/IEntityTypeBaseTypeChangedConvention.cs @@ -4,6 +4,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Metadata.Builders; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// @@ -20,8 +22,8 @@ public interface IEntityTypeBaseTypeChangedConvention : IConvention /// Additional information associated with convention execution. void ProcessEntityTypeBaseTypeChanged( [NotNull] IConventionEntityTypeBuilder entityTypeBuilder, - [CanBeNull] IConventionEntityType newBaseType, - [CanBeNull] IConventionEntityType oldBaseType, + [CanBeNull] IConventionEntityType? newBaseType, + [CanBeNull] IConventionEntityType? oldBaseType, [NotNull] IConventionContext context); } } diff --git a/src/EFCore/Metadata/Conventions/IEntityTypeIgnoredConvention.cs b/src/EFCore/Metadata/Conventions/IEntityTypeIgnoredConvention.cs index eeec64cf0c1..0b08f607160 100644 --- a/src/EFCore/Metadata/Conventions/IEntityTypeIgnoredConvention.cs +++ b/src/EFCore/Metadata/Conventions/IEntityTypeIgnoredConvention.cs @@ -5,6 +5,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Metadata.Builders; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// @@ -22,7 +24,7 @@ public interface IEntityTypeIgnoredConvention : IConvention void ProcessEntityTypeIgnored( [NotNull] IConventionModelBuilder modelBuilder, [NotNull] string name, - [CanBeNull] Type type, + [CanBeNull] Type? type, [NotNull] IConventionContext context); } } diff --git a/src/EFCore/Metadata/Conventions/IEntityTypeMemberIgnoredConvention.cs b/src/EFCore/Metadata/Conventions/IEntityTypeMemberIgnoredConvention.cs index e4a24f95752..dd3b1dacae9 100644 --- a/src/EFCore/Metadata/Conventions/IEntityTypeMemberIgnoredConvention.cs +++ b/src/EFCore/Metadata/Conventions/IEntityTypeMemberIgnoredConvention.cs @@ -4,6 +4,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Metadata.Builders; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// diff --git a/src/EFCore/Metadata/Conventions/IEntityTypePrimaryKeyChangedConvention.cs b/src/EFCore/Metadata/Conventions/IEntityTypePrimaryKeyChangedConvention.cs index 36c245f1ec5..0d35a3b7015 100644 --- a/src/EFCore/Metadata/Conventions/IEntityTypePrimaryKeyChangedConvention.cs +++ b/src/EFCore/Metadata/Conventions/IEntityTypePrimaryKeyChangedConvention.cs @@ -4,6 +4,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Metadata.Builders; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// @@ -20,8 +22,8 @@ public interface IEntityTypePrimaryKeyChangedConvention : IConvention /// Additional information associated with convention execution. void ProcessEntityTypePrimaryKeyChanged( [NotNull] IConventionEntityTypeBuilder entityTypeBuilder, - [CanBeNull] IConventionKey newPrimaryKey, - [CanBeNull] IConventionKey previousPrimaryKey, + [CanBeNull] IConventionKey? newPrimaryKey, + [CanBeNull] IConventionKey? previousPrimaryKey, [NotNull] IConventionContext context); } } diff --git a/src/EFCore/Metadata/Conventions/IEntityTypeRemovedConvention.cs b/src/EFCore/Metadata/Conventions/IEntityTypeRemovedConvention.cs index fe032fb2cb3..21b6d39d4b6 100644 --- a/src/EFCore/Metadata/Conventions/IEntityTypeRemovedConvention.cs +++ b/src/EFCore/Metadata/Conventions/IEntityTypeRemovedConvention.cs @@ -4,6 +4,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Metadata.Builders; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// diff --git a/src/EFCore/Metadata/Conventions/IForeignKeyAddedConvention.cs b/src/EFCore/Metadata/Conventions/IForeignKeyAddedConvention.cs index aba80b90b92..4730052abc1 100644 --- a/src/EFCore/Metadata/Conventions/IForeignKeyAddedConvention.cs +++ b/src/EFCore/Metadata/Conventions/IForeignKeyAddedConvention.cs @@ -4,6 +4,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Metadata.Builders; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// diff --git a/src/EFCore/Metadata/Conventions/IForeignKeyAnnotationChangedConvention.cs b/src/EFCore/Metadata/Conventions/IForeignKeyAnnotationChangedConvention.cs index c5175add414..f6489a399ab 100644 --- a/src/EFCore/Metadata/Conventions/IForeignKeyAnnotationChangedConvention.cs +++ b/src/EFCore/Metadata/Conventions/IForeignKeyAnnotationChangedConvention.cs @@ -4,6 +4,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Metadata.Builders; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// @@ -22,8 +24,8 @@ public interface IForeignKeyAnnotationChangedConvention : IConvention void ProcessForeignKeyAnnotationChanged( [NotNull] IConventionForeignKeyBuilder relationshipBuilder, [NotNull] string name, - [CanBeNull] IConventionAnnotation annotation, - [CanBeNull] IConventionAnnotation oldAnnotation, + [CanBeNull] IConventionAnnotation? annotation, + [CanBeNull] IConventionAnnotation? oldAnnotation, [NotNull] IConventionContext context); } } diff --git a/src/EFCore/Metadata/Conventions/IForeignKeyDependentRequirednessChangedConvention.cs b/src/EFCore/Metadata/Conventions/IForeignKeyDependentRequirednessChangedConvention.cs index 0b328866ef9..0d67dd22cbc 100644 --- a/src/EFCore/Metadata/Conventions/IForeignKeyDependentRequirednessChangedConvention.cs +++ b/src/EFCore/Metadata/Conventions/IForeignKeyDependentRequirednessChangedConvention.cs @@ -4,6 +4,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Metadata.Builders; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// diff --git a/src/EFCore/Metadata/Conventions/IForeignKeyOwnershipChangedConvention.cs b/src/EFCore/Metadata/Conventions/IForeignKeyOwnershipChangedConvention.cs index eb47ff60232..bc91d79c765 100644 --- a/src/EFCore/Metadata/Conventions/IForeignKeyOwnershipChangedConvention.cs +++ b/src/EFCore/Metadata/Conventions/IForeignKeyOwnershipChangedConvention.cs @@ -4,6 +4,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Metadata.Builders; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// diff --git a/src/EFCore/Metadata/Conventions/IForeignKeyPrincipalEndChangedConvention.cs b/src/EFCore/Metadata/Conventions/IForeignKeyPrincipalEndChangedConvention.cs index 165c12219d9..b3b73f0d47d 100644 --- a/src/EFCore/Metadata/Conventions/IForeignKeyPrincipalEndChangedConvention.cs +++ b/src/EFCore/Metadata/Conventions/IForeignKeyPrincipalEndChangedConvention.cs @@ -4,6 +4,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Metadata.Builders; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// diff --git a/src/EFCore/Metadata/Conventions/IForeignKeyPropertiesChangedConvention.cs b/src/EFCore/Metadata/Conventions/IForeignKeyPropertiesChangedConvention.cs index 6c470ca2b31..70e9e5621c2 100644 --- a/src/EFCore/Metadata/Conventions/IForeignKeyPropertiesChangedConvention.cs +++ b/src/EFCore/Metadata/Conventions/IForeignKeyPropertiesChangedConvention.cs @@ -5,6 +5,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Metadata.Builders; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// diff --git a/src/EFCore/Metadata/Conventions/IForeignKeyRemovedConvention.cs b/src/EFCore/Metadata/Conventions/IForeignKeyRemovedConvention.cs index b6f383b8eea..0a58ce5b841 100644 --- a/src/EFCore/Metadata/Conventions/IForeignKeyRemovedConvention.cs +++ b/src/EFCore/Metadata/Conventions/IForeignKeyRemovedConvention.cs @@ -4,6 +4,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Metadata.Builders; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// diff --git a/src/EFCore/Metadata/Conventions/IForeignKeyRequirednessChangedConvention.cs b/src/EFCore/Metadata/Conventions/IForeignKeyRequirednessChangedConvention.cs index 72e486364eb..5bef931c617 100644 --- a/src/EFCore/Metadata/Conventions/IForeignKeyRequirednessChangedConvention.cs +++ b/src/EFCore/Metadata/Conventions/IForeignKeyRequirednessChangedConvention.cs @@ -4,6 +4,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Metadata.Builders; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// diff --git a/src/EFCore/Metadata/Conventions/IForeignKeyUniquenessChangedConvention.cs b/src/EFCore/Metadata/Conventions/IForeignKeyUniquenessChangedConvention.cs index a15e1051f64..bbeeeee3134 100644 --- a/src/EFCore/Metadata/Conventions/IForeignKeyUniquenessChangedConvention.cs +++ b/src/EFCore/Metadata/Conventions/IForeignKeyUniquenessChangedConvention.cs @@ -4,6 +4,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Metadata.Builders; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// diff --git a/src/EFCore/Metadata/Conventions/IIndexAddedConvention.cs b/src/EFCore/Metadata/Conventions/IIndexAddedConvention.cs index cbd1e82751f..bee013ab165 100644 --- a/src/EFCore/Metadata/Conventions/IIndexAddedConvention.cs +++ b/src/EFCore/Metadata/Conventions/IIndexAddedConvention.cs @@ -4,6 +4,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Metadata.Builders; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// diff --git a/src/EFCore/Metadata/Conventions/IIndexAnnotationChangedConvention.cs b/src/EFCore/Metadata/Conventions/IIndexAnnotationChangedConvention.cs index f24cdedeb3c..bdeee369b0f 100644 --- a/src/EFCore/Metadata/Conventions/IIndexAnnotationChangedConvention.cs +++ b/src/EFCore/Metadata/Conventions/IIndexAnnotationChangedConvention.cs @@ -4,6 +4,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Metadata.Builders; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// @@ -22,8 +24,8 @@ public interface IIndexAnnotationChangedConvention : IConvention void ProcessIndexAnnotationChanged( [NotNull] IConventionIndexBuilder indexBuilder, [NotNull] string name, - [CanBeNull] IConventionAnnotation annotation, - [CanBeNull] IConventionAnnotation oldAnnotation, + [CanBeNull] IConventionAnnotation? annotation, + [CanBeNull] IConventionAnnotation? oldAnnotation, [NotNull] IConventionContext context); } } diff --git a/src/EFCore/Metadata/Conventions/IIndexRemovedConvention.cs b/src/EFCore/Metadata/Conventions/IIndexRemovedConvention.cs index 1ffda14b129..4c5e62729eb 100644 --- a/src/EFCore/Metadata/Conventions/IIndexRemovedConvention.cs +++ b/src/EFCore/Metadata/Conventions/IIndexRemovedConvention.cs @@ -4,6 +4,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Metadata.Builders; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// diff --git a/src/EFCore/Metadata/Conventions/IIndexUniquenessChangedConvention.cs b/src/EFCore/Metadata/Conventions/IIndexUniquenessChangedConvention.cs index 10c0c0d29cc..a9505fd86a4 100644 --- a/src/EFCore/Metadata/Conventions/IIndexUniquenessChangedConvention.cs +++ b/src/EFCore/Metadata/Conventions/IIndexUniquenessChangedConvention.cs @@ -4,6 +4,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Metadata.Builders; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// diff --git a/src/EFCore/Metadata/Conventions/IKeyAddedConvention.cs b/src/EFCore/Metadata/Conventions/IKeyAddedConvention.cs index 0a41b4e8570..9c24c7c5211 100644 --- a/src/EFCore/Metadata/Conventions/IKeyAddedConvention.cs +++ b/src/EFCore/Metadata/Conventions/IKeyAddedConvention.cs @@ -4,6 +4,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Metadata.Builders; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// diff --git a/src/EFCore/Metadata/Conventions/IKeyAnnotationChangedConvention.cs b/src/EFCore/Metadata/Conventions/IKeyAnnotationChangedConvention.cs index 517b757bb70..8a97f99bab8 100644 --- a/src/EFCore/Metadata/Conventions/IKeyAnnotationChangedConvention.cs +++ b/src/EFCore/Metadata/Conventions/IKeyAnnotationChangedConvention.cs @@ -4,6 +4,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Metadata.Builders; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// @@ -22,8 +24,8 @@ public interface IKeyAnnotationChangedConvention : IConvention void ProcessKeyAnnotationChanged( [NotNull] IConventionKeyBuilder keyBuilder, [NotNull] string name, - [CanBeNull] IConventionAnnotation annotation, - [CanBeNull] IConventionAnnotation oldAnnotation, + [CanBeNull] IConventionAnnotation? annotation, + [CanBeNull] IConventionAnnotation? oldAnnotation, [NotNull] IConventionContext context); } } diff --git a/src/EFCore/Metadata/Conventions/IKeyRemovedConvention.cs b/src/EFCore/Metadata/Conventions/IKeyRemovedConvention.cs index a52dff021bf..b162cdced05 100644 --- a/src/EFCore/Metadata/Conventions/IKeyRemovedConvention.cs +++ b/src/EFCore/Metadata/Conventions/IKeyRemovedConvention.cs @@ -4,6 +4,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Metadata.Builders; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// diff --git a/src/EFCore/Metadata/Conventions/IModelAnnotationChangedConvention.cs b/src/EFCore/Metadata/Conventions/IModelAnnotationChangedConvention.cs index bcad10acc93..76cd75a2ebc 100644 --- a/src/EFCore/Metadata/Conventions/IModelAnnotationChangedConvention.cs +++ b/src/EFCore/Metadata/Conventions/IModelAnnotationChangedConvention.cs @@ -4,6 +4,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Metadata.Builders; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// @@ -22,8 +24,8 @@ public interface IModelAnnotationChangedConvention void ProcessModelAnnotationChanged( [NotNull] IConventionModelBuilder modelBuilder, [NotNull] string name, - [CanBeNull] IConventionAnnotation annotation, - [CanBeNull] IConventionAnnotation oldAnnotation, + [CanBeNull] IConventionAnnotation? annotation, + [CanBeNull] IConventionAnnotation? oldAnnotation, [NotNull] IConventionContext context); } } diff --git a/src/EFCore/Metadata/Conventions/IModelFinalizedConvention.cs b/src/EFCore/Metadata/Conventions/IModelFinalizedConvention.cs index 346829d0bc6..b205aaac853 100644 --- a/src/EFCore/Metadata/Conventions/IModelFinalizedConvention.cs +++ b/src/EFCore/Metadata/Conventions/IModelFinalizedConvention.cs @@ -3,6 +3,8 @@ using JetBrains.Annotations; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// diff --git a/src/EFCore/Metadata/Conventions/IModelFinalizingConvention.cs b/src/EFCore/Metadata/Conventions/IModelFinalizingConvention.cs index 78dc987f849..df98ff5ac3f 100644 --- a/src/EFCore/Metadata/Conventions/IModelFinalizingConvention.cs +++ b/src/EFCore/Metadata/Conventions/IModelFinalizingConvention.cs @@ -4,6 +4,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Metadata.Builders; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// diff --git a/src/EFCore/Metadata/Conventions/IModelInitializedConvention.cs b/src/EFCore/Metadata/Conventions/IModelInitializedConvention.cs index b849aedde7a..04d11eb070b 100644 --- a/src/EFCore/Metadata/Conventions/IModelInitializedConvention.cs +++ b/src/EFCore/Metadata/Conventions/IModelInitializedConvention.cs @@ -4,6 +4,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Metadata.Builders; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// diff --git a/src/EFCore/Metadata/Conventions/INavigationAddedConvention.cs b/src/EFCore/Metadata/Conventions/INavigationAddedConvention.cs index d2717832d84..54293a9f5a3 100644 --- a/src/EFCore/Metadata/Conventions/INavigationAddedConvention.cs +++ b/src/EFCore/Metadata/Conventions/INavigationAddedConvention.cs @@ -4,6 +4,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Metadata.Builders; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// diff --git a/src/EFCore/Metadata/Conventions/INavigationAnnotationChangedConvention.cs b/src/EFCore/Metadata/Conventions/INavigationAnnotationChangedConvention.cs index 6fc25a961f3..a8511e4d07b 100644 --- a/src/EFCore/Metadata/Conventions/INavigationAnnotationChangedConvention.cs +++ b/src/EFCore/Metadata/Conventions/INavigationAnnotationChangedConvention.cs @@ -4,6 +4,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Metadata.Builders; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// @@ -24,8 +26,8 @@ void ProcessNavigationAnnotationChanged( [NotNull] IConventionForeignKeyBuilder relationshipBuilder, [NotNull] IConventionNavigation navigation, [NotNull] string name, - [CanBeNull] IConventionAnnotation annotation, - [CanBeNull] IConventionAnnotation oldAnnotation, + [CanBeNull] IConventionAnnotation? annotation, + [CanBeNull] IConventionAnnotation? oldAnnotation, [NotNull] IConventionContext context); } } diff --git a/src/EFCore/Metadata/Conventions/INavigationRemovedConvention.cs b/src/EFCore/Metadata/Conventions/INavigationRemovedConvention.cs index 7c31cdfcc09..6089e2b3238 100644 --- a/src/EFCore/Metadata/Conventions/INavigationRemovedConvention.cs +++ b/src/EFCore/Metadata/Conventions/INavigationRemovedConvention.cs @@ -5,6 +5,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Metadata.Builders; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// @@ -24,7 +26,7 @@ void ProcessNavigationRemoved( [NotNull] IConventionEntityTypeBuilder sourceEntityTypeBuilder, [NotNull] IConventionEntityTypeBuilder targetEntityTypeBuilder, [NotNull] string navigationName, - [CanBeNull] MemberInfo memberInfo, + [CanBeNull] MemberInfo? memberInfo, [NotNull] IConventionContext context); } } diff --git a/src/EFCore/Metadata/Conventions/IPropertyAddedConvention.cs b/src/EFCore/Metadata/Conventions/IPropertyAddedConvention.cs index 38f3a7f504c..04b28f2c037 100644 --- a/src/EFCore/Metadata/Conventions/IPropertyAddedConvention.cs +++ b/src/EFCore/Metadata/Conventions/IPropertyAddedConvention.cs @@ -4,6 +4,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Metadata.Builders; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// diff --git a/src/EFCore/Metadata/Conventions/IPropertyAnnotationChangedConvention.cs b/src/EFCore/Metadata/Conventions/IPropertyAnnotationChangedConvention.cs index c806d9b94d0..79769b9e517 100644 --- a/src/EFCore/Metadata/Conventions/IPropertyAnnotationChangedConvention.cs +++ b/src/EFCore/Metadata/Conventions/IPropertyAnnotationChangedConvention.cs @@ -4,6 +4,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Metadata.Builders; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// @@ -22,8 +24,8 @@ public interface IPropertyAnnotationChangedConvention : IConvention void ProcessPropertyAnnotationChanged( [NotNull] IConventionPropertyBuilder propertyBuilder, [NotNull] string name, - [CanBeNull] IConventionAnnotation annotation, - [CanBeNull] IConventionAnnotation oldAnnotation, + [CanBeNull] IConventionAnnotation? annotation, + [CanBeNull] IConventionAnnotation? oldAnnotation, [NotNull] IConventionContext context); } } diff --git a/src/EFCore/Metadata/Conventions/IPropertyFieldChangedConvention.cs b/src/EFCore/Metadata/Conventions/IPropertyFieldChangedConvention.cs index cbe67bb9797..26e6130ce5a 100644 --- a/src/EFCore/Metadata/Conventions/IPropertyFieldChangedConvention.cs +++ b/src/EFCore/Metadata/Conventions/IPropertyFieldChangedConvention.cs @@ -5,6 +5,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Metadata.Builders; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// @@ -21,8 +23,8 @@ public interface IPropertyFieldChangedConvention : IConvention /// Additional information associated with convention execution. void ProcessPropertyFieldChanged( [NotNull] IConventionPropertyBuilder propertyBuilder, - [CanBeNull] FieldInfo newFieldInfo, - [CanBeNull] FieldInfo oldFieldInfo, + [CanBeNull] FieldInfo? newFieldInfo, + [CanBeNull] FieldInfo? oldFieldInfo, [NotNull] IConventionContext context); } } diff --git a/src/EFCore/Metadata/Conventions/IPropertyNullabilityChangedConvention.cs b/src/EFCore/Metadata/Conventions/IPropertyNullabilityChangedConvention.cs index 0faa1e5f87e..dc902ecb4e9 100644 --- a/src/EFCore/Metadata/Conventions/IPropertyNullabilityChangedConvention.cs +++ b/src/EFCore/Metadata/Conventions/IPropertyNullabilityChangedConvention.cs @@ -4,6 +4,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Metadata.Builders; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// diff --git a/src/EFCore/Metadata/Conventions/IPropertyRemovedConvention.cs b/src/EFCore/Metadata/Conventions/IPropertyRemovedConvention.cs index 06efe5c2de7..b1b8c78bd21 100644 --- a/src/EFCore/Metadata/Conventions/IPropertyRemovedConvention.cs +++ b/src/EFCore/Metadata/Conventions/IPropertyRemovedConvention.cs @@ -4,6 +4,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Metadata.Builders; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// diff --git a/src/EFCore/Metadata/Conventions/ISkipNavigationAddedConvention.cs b/src/EFCore/Metadata/Conventions/ISkipNavigationAddedConvention.cs index b22b563c227..6d8a5013df0 100644 --- a/src/EFCore/Metadata/Conventions/ISkipNavigationAddedConvention.cs +++ b/src/EFCore/Metadata/Conventions/ISkipNavigationAddedConvention.cs @@ -4,6 +4,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Metadata.Builders; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// diff --git a/src/EFCore/Metadata/Conventions/ISkipNavigationAnnotationChangedConvention.cs b/src/EFCore/Metadata/Conventions/ISkipNavigationAnnotationChangedConvention.cs index 90c701529ae..b7f87d708b0 100644 --- a/src/EFCore/Metadata/Conventions/ISkipNavigationAnnotationChangedConvention.cs +++ b/src/EFCore/Metadata/Conventions/ISkipNavigationAnnotationChangedConvention.cs @@ -4,6 +4,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Metadata.Builders; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// @@ -22,8 +24,8 @@ public interface ISkipNavigationAnnotationChangedConvention : IConvention void ProcessSkipNavigationAnnotationChanged( [NotNull] IConventionSkipNavigationBuilder skipNavigationBuilder, [NotNull] string name, - [CanBeNull] IConventionAnnotation annotation, - [CanBeNull] IConventionAnnotation oldAnnotation, + [CanBeNull] IConventionAnnotation? annotation, + [CanBeNull] IConventionAnnotation? oldAnnotation, [NotNull] IConventionContext context); } } diff --git a/src/EFCore/Metadata/Conventions/ISkipNavigationForeignKeyChangedConvention.cs b/src/EFCore/Metadata/Conventions/ISkipNavigationForeignKeyChangedConvention.cs index 63f4751662d..5cf6e80cc7c 100644 --- a/src/EFCore/Metadata/Conventions/ISkipNavigationForeignKeyChangedConvention.cs +++ b/src/EFCore/Metadata/Conventions/ISkipNavigationForeignKeyChangedConvention.cs @@ -4,6 +4,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Metadata.Builders; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// @@ -20,8 +22,8 @@ public interface ISkipNavigationForeignKeyChangedConvention : IConvention /// Additional information associated with convention execution. void ProcessSkipNavigationForeignKeyChanged( [NotNull] IConventionSkipNavigationBuilder skipNavigationBuilder, - [CanBeNull] IConventionForeignKey foreignKey, - [CanBeNull] IConventionForeignKey oldForeignKey, + [CanBeNull] IConventionForeignKey? foreignKey, + [CanBeNull] IConventionForeignKey? oldForeignKey, [NotNull] IConventionContext context); } } diff --git a/src/EFCore/Metadata/Conventions/ISkipNavigationInverseChangedConvention.cs b/src/EFCore/Metadata/Conventions/ISkipNavigationInverseChangedConvention.cs index fd55875df5b..873b30f8466 100644 --- a/src/EFCore/Metadata/Conventions/ISkipNavigationInverseChangedConvention.cs +++ b/src/EFCore/Metadata/Conventions/ISkipNavigationInverseChangedConvention.cs @@ -4,6 +4,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Metadata.Builders; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// @@ -20,8 +22,8 @@ public interface ISkipNavigationInverseChangedConvention : IConvention /// Additional information associated with convention execution. void ProcessSkipNavigationInverseChanged( [NotNull] IConventionSkipNavigationBuilder skipNavigationBuilder, - [CanBeNull] IConventionSkipNavigation inverse, - [CanBeNull] IConventionSkipNavigation oldInverse, + [CanBeNull] IConventionSkipNavigation? inverse, + [CanBeNull] IConventionSkipNavigation? oldInverse, [NotNull] IConventionContext context); } } diff --git a/src/EFCore/Metadata/Conventions/ISkipNavigationRemovedConvention.cs b/src/EFCore/Metadata/Conventions/ISkipNavigationRemovedConvention.cs index 850772fa88e..3e7f2fb1a3b 100644 --- a/src/EFCore/Metadata/Conventions/ISkipNavigationRemovedConvention.cs +++ b/src/EFCore/Metadata/Conventions/ISkipNavigationRemovedConvention.cs @@ -4,6 +4,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Metadata.Builders; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// diff --git a/src/EFCore/Metadata/Conventions/IndexAttributeConvention.cs b/src/EFCore/Metadata/Conventions/IndexAttributeConvention.cs index 92a8dd45f15..57f407605f4 100644 --- a/src/EFCore/Metadata/Conventions/IndexAttributeConvention.cs +++ b/src/EFCore/Metadata/Conventions/IndexAttributeConvention.cs @@ -10,6 +10,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// @@ -40,8 +42,8 @@ public virtual void ProcessEntityTypeAdded( /// public virtual void ProcessEntityTypeBaseTypeChanged( IConventionEntityTypeBuilder entityTypeBuilder, - IConventionEntityType newBaseType, - IConventionEntityType oldBaseType, + IConventionEntityType? newBaseType, + IConventionEntityType? oldBaseType, IConventionContext context) { if (oldBaseType == null) @@ -75,7 +77,7 @@ private static void CheckIndexAttributesAndEnsureIndex( foreach (var indexAttribute in entityType.ClrType.GetCustomAttributes(true)) { - IConventionIndexBuilder indexBuilder; + IConventionIndexBuilder? indexBuilder; if (!shouldThrow) { var indexProperties = new List(); diff --git a/src/EFCore/Metadata/Conventions/Infrastructure/IConventionSetBuilder.cs b/src/EFCore/Metadata/Conventions/Infrastructure/IConventionSetBuilder.cs index 709d18ef27b..bfce8b40ced 100644 --- a/src/EFCore/Metadata/Conventions/Infrastructure/IConventionSetBuilder.cs +++ b/src/EFCore/Metadata/Conventions/Infrastructure/IConventionSetBuilder.cs @@ -3,6 +3,8 @@ using Microsoft.Extensions.DependencyInjection; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure { /// diff --git a/src/EFCore/Metadata/Conventions/Infrastructure/IConventionSetPlugin.cs b/src/EFCore/Metadata/Conventions/Infrastructure/IConventionSetPlugin.cs index 6c816d46d27..a08ef54b62a 100644 --- a/src/EFCore/Metadata/Conventions/Infrastructure/IConventionSetPlugin.cs +++ b/src/EFCore/Metadata/Conventions/Infrastructure/IConventionSetPlugin.cs @@ -4,6 +4,8 @@ using JetBrains.Annotations; using Microsoft.Extensions.DependencyInjection; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure { /// diff --git a/src/EFCore/Metadata/Conventions/Infrastructure/IProviderConventionSetBuilder.cs b/src/EFCore/Metadata/Conventions/Infrastructure/IProviderConventionSetBuilder.cs index 504aee8901c..1ba4d964bd6 100644 --- a/src/EFCore/Metadata/Conventions/Infrastructure/IProviderConventionSetBuilder.cs +++ b/src/EFCore/Metadata/Conventions/Infrastructure/IProviderConventionSetBuilder.cs @@ -3,6 +3,8 @@ using Microsoft.Extensions.DependencyInjection; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure { /// diff --git a/src/EFCore/Metadata/Conventions/Infrastructure/ProviderConventionSetBuilder.cs b/src/EFCore/Metadata/Conventions/Infrastructure/ProviderConventionSetBuilder.cs index 7da009aa13f..81fd7c81bd9 100644 --- a/src/EFCore/Metadata/Conventions/Infrastructure/ProviderConventionSetBuilder.cs +++ b/src/EFCore/Metadata/Conventions/Infrastructure/ProviderConventionSetBuilder.cs @@ -6,6 +6,8 @@ using Microsoft.EntityFrameworkCore.Utilities; using Microsoft.Extensions.DependencyInjection; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure { /// diff --git a/src/EFCore/Metadata/Conventions/Infrastructure/ProviderConventionSetBuilderDependencies.cs b/src/EFCore/Metadata/Conventions/Infrastructure/ProviderConventionSetBuilderDependencies.cs index d8daf10c530..efa0644f518 100644 --- a/src/EFCore/Metadata/Conventions/Infrastructure/ProviderConventionSetBuilderDependencies.cs +++ b/src/EFCore/Metadata/Conventions/Infrastructure/ProviderConventionSetBuilderDependencies.cs @@ -10,6 +10,8 @@ using Microsoft.EntityFrameworkCore.Utilities; using Microsoft.Extensions.DependencyInjection; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure { /// diff --git a/src/EFCore/Metadata/Conventions/InheritanceDiscoveryConventionBase.cs b/src/EFCore/Metadata/Conventions/InheritanceDiscoveryConventionBase.cs index 5232d9f3bcd..966166e7980 100644 --- a/src/EFCore/Metadata/Conventions/InheritanceDiscoveryConventionBase.cs +++ b/src/EFCore/Metadata/Conventions/InheritanceDiscoveryConventionBase.cs @@ -5,6 +5,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// @@ -32,11 +34,11 @@ protected InheritanceDiscoveryConventionBase([NotNull] ProviderConventionSetBuil /// associated CLR type is derived from and is the closest one in the CLR hierarchy. /// /// The entity type. - protected virtual IConventionEntityType FindClosestBaseType([NotNull] IConventionEntityType entityType) + protected virtual IConventionEntityType? FindClosestBaseType([NotNull] IConventionEntityType entityType) { var baseType = entityType.ClrType.BaseType; var model = entityType.Model; - IConventionEntityType baseEntityType = null; + IConventionEntityType? baseEntityType = null; while (baseType != null && baseEntityType == null && baseType != typeof(object)) diff --git a/src/EFCore/Metadata/Conventions/Internal/ConventionBatchExtensions.cs b/src/EFCore/Metadata/Conventions/Internal/ConventionBatchExtensions.cs index 484fb505b59..0e5ae32ea6a 100644 --- a/src/EFCore/Metadata/Conventions/Internal/ConventionBatchExtensions.cs +++ b/src/EFCore/Metadata/Conventions/Internal/ConventionBatchExtensions.cs @@ -5,6 +5,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Metadata.Internal; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal { /// @@ -22,9 +24,9 @@ public static class ConventionBatchExtensions /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [DebuggerStepThrough] - public static InternalForeignKeyBuilder Run( + public static InternalForeignKeyBuilder? Run( [NotNull] this IConventionBatch batch, [NotNull] InternalForeignKeyBuilder relationshipBuilder) - => (InternalForeignKeyBuilder)batch.Run(relationshipBuilder.Metadata)?.Builder; + => (InternalForeignKeyBuilder?)batch.Run(relationshipBuilder.Metadata)?.Builder; } } diff --git a/src/EFCore/Metadata/Conventions/Internal/ConventionContext.cs b/src/EFCore/Metadata/Conventions/Internal/ConventionContext.cs index 6fff3e69a8e..120fb7f9f72 100644 --- a/src/EFCore/Metadata/Conventions/Internal/ConventionContext.cs +++ b/src/EFCore/Metadata/Conventions/Internal/ConventionContext.cs @@ -3,6 +3,8 @@ using JetBrains.Annotations; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal { /// @@ -15,7 +17,7 @@ public class ConventionContext : IConventionContext, IRead { private bool _stopProcessing; private readonly ConventionDispatcher _dispatcher; - private TMetadata _result; + private TMetadata? _result; /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -34,7 +36,7 @@ public ConventionContext([NotNull] ConventionDispatcher dispatcher) /// 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. /// - public virtual TMetadata Result + public virtual TMetadata? Result => _result; /// @@ -55,7 +57,7 @@ public virtual void StopProcessing() /// /// /// The new metadata object or . - public virtual void StopProcessing(TMetadata result) + public virtual void StopProcessing(TMetadata? result) { _stopProcessing = true; _result = result; @@ -70,8 +72,8 @@ public virtual void StopProcessing(TMetadata result) /// The common use case is when the metadata object was replaced by the convention. /// /// - /// The new metadata object. - public virtual void StopProcessingIfChanged(TMetadata result) + /// The new metadata object or . + public virtual void StopProcessingIfChanged(TMetadata? result) { if (!Equals(Result, result)) { @@ -107,7 +109,7 @@ public virtual bool ShouldStopProcessing() /// 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. /// - public virtual void ResetState([CanBeNull] TMetadata input) + public virtual void ResetState([CanBeNull] TMetadata? input) { _stopProcessing = false; _result = input; diff --git a/src/EFCore/Metadata/Conventions/Internal/ConventionDispatcher.ConventionNode.cs b/src/EFCore/Metadata/Conventions/Internal/ConventionDispatcher.ConventionNode.cs index 301285a47f0..f436283cf7a 100644 --- a/src/EFCore/Metadata/Conventions/Internal/ConventionDispatcher.ConventionNode.cs +++ b/src/EFCore/Metadata/Conventions/Internal/ConventionDispatcher.ConventionNode.cs @@ -1,6 +1,8 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal { public partial class ConventionDispatcher diff --git a/src/EFCore/Metadata/Conventions/Internal/ConventionDispatcher.ConventionScope.cs b/src/EFCore/Metadata/Conventions/Internal/ConventionDispatcher.ConventionScope.cs index 9391c3dd9b5..84ab1ceddaa 100644 --- a/src/EFCore/Metadata/Conventions/Internal/ConventionDispatcher.ConventionScope.cs +++ b/src/EFCore/Metadata/Conventions/Internal/ConventionDispatcher.ConventionScope.cs @@ -7,16 +7,18 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Metadata.Builders; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal { public partial class ConventionDispatcher { private abstract class ConventionScope : ConventionNode { - public virtual ConventionScope Parent + public virtual ConventionScope? Parent => null; - public virtual IReadOnlyList Children + public virtual IReadOnlyList? Children => null; public int GetLeafCount() @@ -53,57 +55,57 @@ public int GetLeafCount() return leafCount; } - public abstract IConventionEntityTypeBuilder OnEntityTypeAdded([NotNull] IConventionEntityTypeBuilder entityTypeBuilder); + public abstract IConventionEntityTypeBuilder? OnEntityTypeAdded([NotNull] IConventionEntityTypeBuilder entityTypeBuilder); - public abstract IConventionAnnotation OnEntityTypeAnnotationChanged( + public abstract IConventionAnnotation? OnEntityTypeAnnotationChanged( [NotNull] IConventionEntityTypeBuilder entityTypeBuilder, [NotNull] string name, - [CanBeNull] IConventionAnnotation annotation, - [CanBeNull] IConventionAnnotation oldAnnotation); + [CanBeNull] IConventionAnnotation? annotation, + [CanBeNull] IConventionAnnotation? oldAnnotation); - public abstract IConventionEntityType OnEntityTypeBaseTypeChanged( + public abstract IConventionEntityType? OnEntityTypeBaseTypeChanged( [NotNull] IConventionEntityTypeBuilder entityTypeBuilder, - [CanBeNull] IConventionEntityType newBaseType, - [CanBeNull] IConventionEntityType previousBaseType); + [CanBeNull] IConventionEntityType? newBaseType, + [CanBeNull] IConventionEntityType? previousBaseType); - public abstract string OnEntityTypeIgnored( + public abstract string? OnEntityTypeIgnored( [NotNull] IConventionModelBuilder modelBuilder, [NotNull] string name, - [CanBeNull] Type type); + [CanBeNull] Type? type); - public abstract string OnEntityTypeMemberIgnored( + public abstract string? OnEntityTypeMemberIgnored( [NotNull] IConventionEntityTypeBuilder entityTypeBuilder, [NotNull] string name); - public abstract IConventionKey OnEntityTypePrimaryKeyChanged( + public abstract IConventionKey? OnEntityTypePrimaryKeyChanged( [NotNull] IConventionEntityTypeBuilder entityTypeBuilder, - [CanBeNull] IConventionKey newPrimaryKey, - [CanBeNull] IConventionKey previousPrimaryKey); + [CanBeNull] IConventionKey? newPrimaryKey, + [CanBeNull] IConventionKey? previousPrimaryKey); - public abstract IConventionEntityType OnEntityTypeRemoved( + public abstract IConventionEntityType? OnEntityTypeRemoved( [NotNull] IConventionModelBuilder modelBuilder, [NotNull] IConventionEntityType entityType); - public abstract IConventionForeignKeyBuilder OnForeignKeyAdded([NotNull] IConventionForeignKeyBuilder relationshipBuilder); + public abstract IConventionForeignKeyBuilder? OnForeignKeyAdded([NotNull] IConventionForeignKeyBuilder relationshipBuilder); - public abstract IConventionAnnotation OnForeignKeyAnnotationChanged( + public abstract IConventionAnnotation? OnForeignKeyAnnotationChanged( [NotNull] IConventionForeignKeyBuilder relationshipBuilder, [NotNull] string name, - [CanBeNull] IConventionAnnotation annotation, - [CanBeNull] IConventionAnnotation oldAnnotation); + [CanBeNull] IConventionAnnotation? annotation, + [CanBeNull] IConventionAnnotation? oldAnnotation); public abstract bool? OnForeignKeyOwnershipChanged( [NotNull] IConventionForeignKeyBuilder relationshipBuilder); - public abstract IConventionForeignKeyBuilder OnForeignKeyPrincipalEndChanged( + public abstract IConventionForeignKeyBuilder? OnForeignKeyPrincipalEndChanged( [NotNull] IConventionForeignKeyBuilder relationshipBuilder); - public abstract IReadOnlyList OnForeignKeyPropertiesChanged( + public abstract IReadOnlyList? OnForeignKeyPropertiesChanged( [NotNull] IConventionForeignKeyBuilder relationshipBuilder, [NotNull] IReadOnlyList oldDependentProperties, [NotNull] IConventionKey oldPrincipalKey); - public abstract IConventionForeignKey OnForeignKeyRemoved( + public abstract IConventionForeignKey? OnForeignKeyRemoved( [NotNull] IConventionEntityTypeBuilder entityTypeBuilder, [NotNull] IConventionForeignKey foreignKey); @@ -116,91 +118,93 @@ public abstract IConventionForeignKey OnForeignKeyRemoved( public abstract bool? OnForeignKeyUniquenessChanged( [NotNull] IConventionForeignKeyBuilder relationshipBuilder); - public abstract IConventionIndexBuilder OnIndexAdded([NotNull] IConventionIndexBuilder indexBuilder); + public abstract IConventionIndexBuilder? OnIndexAdded([NotNull] IConventionIndexBuilder indexBuilder); - public abstract IConventionAnnotation OnIndexAnnotationChanged( + public abstract IConventionAnnotation? OnIndexAnnotationChanged( [NotNull] IConventionIndexBuilder indexBuilder, [NotNull] string name, - [CanBeNull] IConventionAnnotation annotation, - [CanBeNull] IConventionAnnotation oldAnnotation); + [CanBeNull] IConventionAnnotation? annotation, + [CanBeNull] IConventionAnnotation? oldAnnotation); - public abstract IConventionIndex OnIndexRemoved( + public abstract IConventionIndex? OnIndexRemoved( [NotNull] IConventionEntityTypeBuilder entityTypeBuilder, [NotNull] IConventionIndex index); public abstract bool? OnIndexUniquenessChanged([NotNull] IConventionIndexBuilder indexBuilder); - public abstract IConventionKeyBuilder OnKeyAdded([NotNull] IConventionKeyBuilder keyBuilder); + public abstract IConventionKeyBuilder? OnKeyAdded([NotNull] IConventionKeyBuilder keyBuilder); - public abstract IConventionAnnotation OnKeyAnnotationChanged( + public abstract IConventionAnnotation? OnKeyAnnotationChanged( [NotNull] IConventionKeyBuilder keyBuilder, [NotNull] string name, - [CanBeNull] IConventionAnnotation annotation, - [CanBeNull] IConventionAnnotation oldAnnotation); + [CanBeNull] IConventionAnnotation? annotation, + [CanBeNull] IConventionAnnotation? oldAnnotation); - public abstract IConventionKey OnKeyRemoved( + public abstract IConventionKey? OnKeyRemoved( [NotNull] IConventionEntityTypeBuilder entityTypeBuilder, [NotNull] IConventionKey key); - public abstract IConventionAnnotation OnModelAnnotationChanged( + public abstract IConventionAnnotation? OnModelAnnotationChanged( [NotNull] IConventionModelBuilder modelBuilder, [NotNull] string name, - [CanBeNull] IConventionAnnotation annotation, - [CanBeNull] IConventionAnnotation oldAnnotation); + [CanBeNull] IConventionAnnotation? annotation, + [CanBeNull] IConventionAnnotation? oldAnnotation); - public abstract IConventionNavigationBuilder OnNavigationAdded([NotNull] IConventionNavigationBuilder navigationBuilder); + public abstract IConventionNavigationBuilder? OnNavigationAdded([NotNull] IConventionNavigationBuilder navigationBuilder); - public abstract string OnNavigationRemoved( + public abstract string? OnNavigationRemoved( [NotNull] IConventionEntityTypeBuilder sourceEntityTypeBuilder, [NotNull] IConventionEntityTypeBuilder targetEntityTypeBuilder, [NotNull] string navigationName, - [CanBeNull] MemberInfo memberInfo); + [CanBeNull] MemberInfo? memberInfo); - public abstract IConventionAnnotation OnNavigationAnnotationChanged( + public abstract IConventionAnnotation? OnNavigationAnnotationChanged( [NotNull] IConventionForeignKeyBuilder relationshipBuilder, [NotNull] IConventionNavigation navigation, [NotNull] string name, - [CanBeNull] IConventionAnnotation annotation, - [CanBeNull] IConventionAnnotation oldAnnotation); + [CanBeNull] IConventionAnnotation? annotation, + [CanBeNull] IConventionAnnotation? oldAnnotation); - public abstract IConventionSkipNavigationBuilder OnSkipNavigationAdded( + public abstract IConventionSkipNavigationBuilder? OnSkipNavigationAdded( [NotNull] IConventionSkipNavigationBuilder navigationBuilder); - public abstract IConventionForeignKey OnSkipNavigationForeignKeyChanged( + public abstract IConventionForeignKey? OnSkipNavigationForeignKeyChanged( [NotNull] IConventionSkipNavigationBuilder navigationBuilder, [NotNull] IConventionForeignKey foreignKey, [NotNull] IConventionForeignKey oldForeignKey); - public abstract IConventionAnnotation OnSkipNavigationAnnotationChanged( + public abstract IConventionAnnotation? OnSkipNavigationAnnotationChanged( [NotNull] IConventionSkipNavigationBuilder navigationBuilder, [NotNull] string name, - [CanBeNull] IConventionAnnotation annotation, - [CanBeNull] IConventionAnnotation oldAnnotation); + [CanBeNull] IConventionAnnotation? annotation, + [CanBeNull] IConventionAnnotation? oldAnnotation); - public abstract IConventionSkipNavigation OnSkipNavigationInverseChanged( + // TODO-NULLABLE: note annotation change here + public abstract IConventionSkipNavigation? OnSkipNavigationInverseChanged( [NotNull] IConventionSkipNavigationBuilder navigationBuilder, - [NotNull] IConventionSkipNavigation inverse, - [NotNull] IConventionSkipNavigation oldInverse); + [CanBeNull] IConventionSkipNavigation? inverse, + [CanBeNull] IConventionSkipNavigation? oldInverse); - public abstract IConventionSkipNavigation OnSkipNavigationRemoved( + public abstract IConventionSkipNavigation? OnSkipNavigationRemoved( [NotNull] IConventionEntityTypeBuilder entityTypeBuilder, [NotNull] IConventionSkipNavigation navigation); - public abstract IConventionPropertyBuilder OnPropertyAdded([NotNull] IConventionPropertyBuilder propertyBuilder); + public abstract IConventionPropertyBuilder? OnPropertyAdded([NotNull] IConventionPropertyBuilder propertyBuilder); - public abstract IConventionAnnotation OnPropertyAnnotationChanged( + public abstract IConventionAnnotation? OnPropertyAnnotationChanged( [NotNull] IConventionPropertyBuilder propertyBuilder, [NotNull] string name, - [CanBeNull] IConventionAnnotation annotation, - [CanBeNull] IConventionAnnotation oldAnnotation); + [CanBeNull] IConventionAnnotation? annotation, + [CanBeNull] IConventionAnnotation? oldAnnotation); - public abstract FieldInfo OnPropertyFieldChanged( + public abstract FieldInfo? OnPropertyFieldChanged( [NotNull] IConventionPropertyBuilder propertyBuilder, - FieldInfo newFieldInfo, - [CanBeNull] FieldInfo oldFieldInfo); + // TODO-NULLABLE: Verify missing annotation + [CanBeNull] FieldInfo? newFieldInfo, + [CanBeNull] FieldInfo? oldFieldInfo); public abstract bool? OnPropertyNullabilityChanged([NotNull] IConventionPropertyBuilder propertyBuilder); - public abstract IConventionProperty OnPropertyRemoved( + public abstract IConventionProperty? OnPropertyRemoved( [NotNull] IConventionEntityTypeBuilder entityTypeBuilder, [NotNull] IConventionProperty property); } diff --git a/src/EFCore/Metadata/Conventions/Internal/ConventionDispatcher.DelayedConventionScope.cs b/src/EFCore/Metadata/Conventions/Internal/ConventionDispatcher.DelayedConventionScope.cs index ca2e28810d3..2041fb611fa 100644 --- a/src/EFCore/Metadata/Conventions/Internal/ConventionDispatcher.DelayedConventionScope.cs +++ b/src/EFCore/Metadata/Conventions/Internal/ConventionDispatcher.DelayedConventionScope.cs @@ -5,18 +5,19 @@ using System.Collections.Generic; using System.Diagnostics; using System.Reflection; -using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Metadata.Builders; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal { public partial class ConventionDispatcher { private sealed class DelayedConventionScope : ConventionScope { - private List _children; + private List? _children; - public DelayedConventionScope(ConventionScope parent, List children = null) + public DelayedConventionScope(ConventionScope parent, List? children = null) { Parent = parent; _children = children; @@ -24,7 +25,7 @@ public DelayedConventionScope(ConventionScope parent, List child public override ConventionScope Parent { [DebuggerStepThrough] get; } - public override IReadOnlyList Children + public override IReadOnlyList? Children { [DebuggerStepThrough] get => _children; @@ -59,7 +60,7 @@ public override IConventionEntityTypeBuilder OnEntityTypeAdded(IConventionEntity return entityTypeBuilder; } - public override string OnEntityTypeIgnored(IConventionModelBuilder modelBuilder, string name, Type type) + public override string OnEntityTypeIgnored(IConventionModelBuilder modelBuilder, string name, Type? type) { Add(new OnEntityTypeIgnoredNode(modelBuilder, name, type)); return name; @@ -79,30 +80,30 @@ public override string OnEntityTypeMemberIgnored(IConventionEntityTypeBuilder en return name; } - public override IConventionEntityType OnEntityTypeBaseTypeChanged( - [NotNull] IConventionEntityTypeBuilder entityTypeBuilder, - [CanBeNull] IConventionEntityType newBaseType, - [CanBeNull] IConventionEntityType previousBaseType) + public override IConventionEntityType? OnEntityTypeBaseTypeChanged( + IConventionEntityTypeBuilder entityTypeBuilder, + IConventionEntityType? newBaseType, + IConventionEntityType? previousBaseType) { Add(new OnEntityTypeBaseTypeChangedNode(entityTypeBuilder, newBaseType, previousBaseType)); return newBaseType; } - public override IConventionAnnotation OnEntityTypeAnnotationChanged( + public override IConventionAnnotation? OnEntityTypeAnnotationChanged( IConventionEntityTypeBuilder entityTypeBuilder, string name, - IConventionAnnotation annotation, - IConventionAnnotation oldAnnotation) + IConventionAnnotation? annotation, + IConventionAnnotation? oldAnnotation) { Add(new OnEntityTypeAnnotationChangedNode(entityTypeBuilder, name, annotation, oldAnnotation)); return annotation; } - public override IConventionAnnotation OnModelAnnotationChanged( + public override IConventionAnnotation? OnModelAnnotationChanged( IConventionModelBuilder modelBuilder, string name, - IConventionAnnotation annotation, - IConventionAnnotation oldAnnotation) + IConventionAnnotation? annotation, + IConventionAnnotation? oldAnnotation) { Add(new OnModelAnnotationChangedNode(modelBuilder, name, annotation, oldAnnotation)); return annotation; @@ -122,11 +123,11 @@ public override IConventionForeignKey OnForeignKeyRemoved( return foreignKey; } - public override IConventionAnnotation OnForeignKeyAnnotationChanged( + public override IConventionAnnotation? OnForeignKeyAnnotationChanged( IConventionForeignKeyBuilder relationshipBuilder, string name, - IConventionAnnotation annotation, - IConventionAnnotation oldAnnotation) + IConventionAnnotation? annotation, + IConventionAnnotation? oldAnnotation) { Add(new OnForeignKeyAnnotationChangedNode(relationshipBuilder, name, annotation, oldAnnotation)); return annotation; @@ -146,20 +147,20 @@ public override IConventionKey OnKeyRemoved( return key; } - public override IConventionAnnotation OnKeyAnnotationChanged( + public override IConventionAnnotation? OnKeyAnnotationChanged( IConventionKeyBuilder keyBuilder, string name, - IConventionAnnotation annotation, - IConventionAnnotation oldAnnotation) + IConventionAnnotation? annotation, + IConventionAnnotation? oldAnnotation) { Add(new OnKeyAnnotationChangedNode(keyBuilder, name, annotation, oldAnnotation)); return annotation; } - public override IConventionKey OnEntityTypePrimaryKeyChanged( + public override IConventionKey? OnEntityTypePrimaryKeyChanged( IConventionEntityTypeBuilder entityTypeBuilder, - IConventionKey newPrimaryKey, - IConventionKey previousPrimaryKey) + IConventionKey? newPrimaryKey, + IConventionKey? previousPrimaryKey) { Add(new OnEntityTypePrimaryKeyChangedNode(entityTypeBuilder, newPrimaryKey, previousPrimaryKey)); return newPrimaryKey; @@ -185,11 +186,11 @@ public override IConventionIndex OnIndexRemoved( return indexBuilder.Metadata.IsUnique; } - public override IConventionAnnotation OnIndexAnnotationChanged( + public override IConventionAnnotation? OnIndexAnnotationChanged( IConventionIndexBuilder indexBuilder, string name, - IConventionAnnotation annotation, - IConventionAnnotation oldAnnotation) + IConventionAnnotation? annotation, + IConventionAnnotation? oldAnnotation) { Add(new OnIndexAnnotationChangedNode(indexBuilder, name, annotation, oldAnnotation)); return annotation; @@ -201,12 +202,12 @@ public override IConventionNavigationBuilder OnNavigationAdded(IConventionNaviga return navigationBuilder; } - public override IConventionAnnotation OnNavigationAnnotationChanged( + public override IConventionAnnotation? OnNavigationAnnotationChanged( IConventionForeignKeyBuilder relationshipBuilder, IConventionNavigation navigation, string name, - IConventionAnnotation annotation, - IConventionAnnotation oldAnnotation) + IConventionAnnotation? annotation, + IConventionAnnotation? oldAnnotation) { Add(new OnNavigationAnnotationChangedNode(relationshipBuilder, navigation, name, annotation, oldAnnotation)); return annotation; @@ -216,7 +217,7 @@ public override string OnNavigationRemoved( IConventionEntityTypeBuilder sourceEntityTypeBuilder, IConventionEntityTypeBuilder targetEntityTypeBuilder, string navigationName, - MemberInfo memberInfo) + MemberInfo? memberInfo) { Add(new OnNavigationRemovedNode(sourceEntityTypeBuilder, targetEntityTypeBuilder, navigationName, memberInfo)); return navigationName; @@ -229,11 +230,11 @@ public override IConventionSkipNavigationBuilder OnSkipNavigationAdded( return navigationBuilder; } - public override IConventionAnnotation OnSkipNavigationAnnotationChanged( + public override IConventionAnnotation? OnSkipNavigationAnnotationChanged( IConventionSkipNavigationBuilder navigationBuilder, string name, - IConventionAnnotation annotation, - IConventionAnnotation oldAnnotation) + IConventionAnnotation? annotation, + IConventionAnnotation? oldAnnotation) { Add(new OnSkipNavigationAnnotationChangedNode(navigationBuilder, name, annotation, oldAnnotation)); return annotation; @@ -248,10 +249,10 @@ public override IConventionForeignKey OnSkipNavigationForeignKeyChanged( return foreignKey; } - public override IConventionSkipNavigation OnSkipNavigationInverseChanged( + public override IConventionSkipNavigation? OnSkipNavigationInverseChanged( IConventionSkipNavigationBuilder navigationBuilder, - IConventionSkipNavigation inverse, - IConventionSkipNavigation oldInverse) + IConventionSkipNavigation? inverse, + IConventionSkipNavigation? oldInverse) { Add(new OnSkipNavigationInverseChangedNode(navigationBuilder, inverse, oldInverse)); return inverse; @@ -321,20 +322,20 @@ public override IConventionPropertyBuilder OnPropertyAdded(IConventionPropertyBu return propertyBuilder.Metadata.IsNullable; } - public override FieldInfo OnPropertyFieldChanged( + public override FieldInfo? OnPropertyFieldChanged( IConventionPropertyBuilder propertyBuilder, - FieldInfo newFieldInfo, - FieldInfo oldFieldInfo) + FieldInfo? newFieldInfo, + FieldInfo? oldFieldInfo) { Add(new OnPropertyFieldChangedNode(propertyBuilder, newFieldInfo, oldFieldInfo)); return newFieldInfo; } - public override IConventionAnnotation OnPropertyAnnotationChanged( + public override IConventionAnnotation? OnPropertyAnnotationChanged( IConventionPropertyBuilder propertyBuilder, string name, - IConventionAnnotation annotation, - IConventionAnnotation oldAnnotation) + IConventionAnnotation? annotation, + IConventionAnnotation? oldAnnotation) { Add(new OnPropertyAnnotationChangedNode(propertyBuilder, name, annotation, oldAnnotation)); return annotation; @@ -354,8 +355,8 @@ private sealed class OnModelAnnotationChangedNode : ConventionNode public OnModelAnnotationChangedNode( IConventionModelBuilder modelBuilder, string name, - IConventionAnnotation annotation, - IConventionAnnotation oldAnnotation) + IConventionAnnotation? annotation, + IConventionAnnotation? oldAnnotation) { ModelBuilder = modelBuilder; Name = name; @@ -365,8 +366,8 @@ public OnModelAnnotationChangedNode( public IConventionModelBuilder ModelBuilder { get; } public string Name { get; } - public IConventionAnnotation Annotation { get; } - public IConventionAnnotation OldAnnotation { get; } + public IConventionAnnotation? Annotation { get; } + public IConventionAnnotation? OldAnnotation { get; } public override void Run(ConventionDispatcher dispatcher) => dispatcher._immediateConventionScope.OnModelAnnotationChanged( @@ -388,7 +389,7 @@ public override void Run(ConventionDispatcher dispatcher) private sealed class OnEntityTypeIgnoredNode : ConventionNode { - public OnEntityTypeIgnoredNode(IConventionModelBuilder modelBuilder, string name, Type type) + public OnEntityTypeIgnoredNode(IConventionModelBuilder modelBuilder, string name, Type? type) { ModelBuilder = modelBuilder; Name = name; @@ -397,7 +398,7 @@ public OnEntityTypeIgnoredNode(IConventionModelBuilder modelBuilder, string name public IConventionModelBuilder ModelBuilder { get; } public string Name { get; } - public Type Type { get; } + public Type? Type { get; } public override void Run(ConventionDispatcher dispatcher) => dispatcher._immediateConventionScope.OnEntityTypeIgnored(ModelBuilder, Name, Type); @@ -437,8 +438,8 @@ private sealed class OnEntityTypeBaseTypeChangedNode : ConventionNode { public OnEntityTypeBaseTypeChangedNode( IConventionEntityTypeBuilder entityTypeBuilder, - IConventionEntityType newBaseType, - IConventionEntityType previousBaseType) + IConventionEntityType? newBaseType, + IConventionEntityType? previousBaseType) { EntityTypeBuilder = entityTypeBuilder; NewBaseType = newBaseType; @@ -446,8 +447,8 @@ public OnEntityTypeBaseTypeChangedNode( } public IConventionEntityTypeBuilder EntityTypeBuilder { get; } - public IConventionEntityType NewBaseType { get; } - public IConventionEntityType PreviousBaseType { get; } + public IConventionEntityType? NewBaseType { get; } + public IConventionEntityType? PreviousBaseType { get; } public override void Run(ConventionDispatcher dispatcher) => dispatcher._immediateConventionScope.OnEntityTypeBaseTypeChanged( @@ -459,8 +460,8 @@ private sealed class OnEntityTypeAnnotationChangedNode : ConventionNode public OnEntityTypeAnnotationChangedNode( IConventionEntityTypeBuilder entityTypeBuilder, string name, - IConventionAnnotation annotation, - IConventionAnnotation oldAnnotation) + IConventionAnnotation? annotation, + IConventionAnnotation? oldAnnotation) { EntityTypeBuilder = entityTypeBuilder; Name = name; @@ -470,8 +471,8 @@ public OnEntityTypeAnnotationChangedNode( public IConventionEntityTypeBuilder EntityTypeBuilder { get; } public string Name { get; } - public IConventionAnnotation Annotation { get; } - public IConventionAnnotation OldAnnotation { get; } + public IConventionAnnotation? Annotation { get; } + public IConventionAnnotation? OldAnnotation { get; } public override void Run(ConventionDispatcher dispatcher) => dispatcher._immediateConventionScope.OnEntityTypeAnnotationChanged( @@ -511,8 +512,8 @@ private sealed class OnForeignKeyAnnotationChangedNode : ConventionNode public OnForeignKeyAnnotationChangedNode( IConventionForeignKeyBuilder relationshipBuilder, string name, - IConventionAnnotation annotation, - IConventionAnnotation oldAnnotation) + IConventionAnnotation? annotation, + IConventionAnnotation? oldAnnotation) { RelationshipBuilder = relationshipBuilder; Name = name; @@ -522,8 +523,8 @@ public OnForeignKeyAnnotationChangedNode( public IConventionForeignKeyBuilder RelationshipBuilder { get; } public string Name { get; } - public IConventionAnnotation Annotation { get; } - public IConventionAnnotation OldAnnotation { get; } + public IConventionAnnotation? Annotation { get; } + public IConventionAnnotation? OldAnnotation { get; } public override void Run(ConventionDispatcher dispatcher) => dispatcher._immediateConventionScope.OnForeignKeyAnnotationChanged( @@ -635,8 +636,8 @@ public OnNavigationAnnotationChangedNode( IConventionForeignKeyBuilder relationshipBuilder, IConventionNavigation navigation, string name, - IConventionAnnotation annotation, - IConventionAnnotation oldAnnotation) + IConventionAnnotation? annotation, + IConventionAnnotation? oldAnnotation) { RelationshipBuilder = relationshipBuilder; Navigation = navigation; @@ -648,8 +649,8 @@ public OnNavigationAnnotationChangedNode( public IConventionForeignKeyBuilder RelationshipBuilder { get; } public IConventionNavigation Navigation { get; } public string Name { get; } - public IConventionAnnotation Annotation { get; } - public IConventionAnnotation OldAnnotation { get; } + public IConventionAnnotation? Annotation { get; } + public IConventionAnnotation? OldAnnotation { get; } public override void Run(ConventionDispatcher dispatcher) => dispatcher._immediateConventionScope.OnNavigationAnnotationChanged( @@ -662,7 +663,7 @@ public OnNavigationRemovedNode( IConventionEntityTypeBuilder sourceEntityTypeBuilder, IConventionEntityTypeBuilder targetEntityTypeBuilder, string navigationName, - MemberInfo memberInfo) + MemberInfo? memberInfo) { SourceEntityTypeBuilder = sourceEntityTypeBuilder; TargetEntityTypeBuilder = targetEntityTypeBuilder; @@ -673,7 +674,7 @@ public OnNavigationRemovedNode( public IConventionEntityTypeBuilder SourceEntityTypeBuilder { get; } public IConventionEntityTypeBuilder TargetEntityTypeBuilder { get; } public string NavigationName { get; } - public MemberInfo MemberInfo { get; } + public MemberInfo? MemberInfo { get; } public override void Run(ConventionDispatcher dispatcher) => dispatcher._immediateConventionScope.OnNavigationRemoved( @@ -698,8 +699,8 @@ private sealed class OnSkipNavigationAnnotationChangedNode : ConventionNode public OnSkipNavigationAnnotationChangedNode( IConventionSkipNavigationBuilder navigationBuilder, string name, - IConventionAnnotation annotation, - IConventionAnnotation oldAnnotation) + IConventionAnnotation? annotation, + IConventionAnnotation? oldAnnotation) { NavigationBuilder = navigationBuilder; Name = name; @@ -709,8 +710,8 @@ public OnSkipNavigationAnnotationChangedNode( public IConventionSkipNavigationBuilder NavigationBuilder { get; } public string Name { get; } - public IConventionAnnotation Annotation { get; } - public IConventionAnnotation OldAnnotation { get; } + public IConventionAnnotation? Annotation { get; } + public IConventionAnnotation? OldAnnotation { get; } public override void Run(ConventionDispatcher dispatcher) => dispatcher._immediateConventionScope.OnSkipNavigationAnnotationChanged( @@ -741,8 +742,8 @@ private sealed class OnSkipNavigationInverseChangedNode : ConventionNode { public OnSkipNavigationInverseChangedNode( IConventionSkipNavigationBuilder navigationBuilder, - IConventionSkipNavigation inverse, - IConventionSkipNavigation oldInverse) + IConventionSkipNavigation? inverse, + IConventionSkipNavigation? oldInverse) { NavigationBuilder = navigationBuilder; Inverse = inverse; @@ -750,8 +751,8 @@ public OnSkipNavigationInverseChangedNode( } public IConventionSkipNavigationBuilder NavigationBuilder { get; } - public IConventionSkipNavigation Inverse { get; } - public IConventionSkipNavigation OldInverse { get; } + public IConventionSkipNavigation? Inverse { get; } + public IConventionSkipNavigation? OldInverse { get; } public override void Run(ConventionDispatcher dispatcher) => dispatcher._immediateConventionScope.OnSkipNavigationInverseChanged(NavigationBuilder, Inverse, OldInverse); @@ -807,8 +808,8 @@ private sealed class OnKeyAnnotationChangedNode : ConventionNode public OnKeyAnnotationChangedNode( IConventionKeyBuilder keyBuilder, string name, - IConventionAnnotation annotation, - IConventionAnnotation oldAnnotation) + IConventionAnnotation? annotation, + IConventionAnnotation? oldAnnotation) { KeyBuilder = keyBuilder; Name = name; @@ -818,8 +819,8 @@ public OnKeyAnnotationChangedNode( public IConventionKeyBuilder KeyBuilder { get; } public string Name { get; } - public IConventionAnnotation Annotation { get; } - public IConventionAnnotation OldAnnotation { get; } + public IConventionAnnotation? Annotation { get; } + public IConventionAnnotation? OldAnnotation { get; } public override void Run(ConventionDispatcher dispatcher) => dispatcher._immediateConventionScope.OnKeyAnnotationChanged( @@ -830,8 +831,8 @@ private sealed class OnEntityTypePrimaryKeyChangedNode : ConventionNode { public OnEntityTypePrimaryKeyChangedNode( IConventionEntityTypeBuilder entityTypeBuilder, - IConventionKey newPrimaryKey, - IConventionKey previousPrimaryKey) + IConventionKey? newPrimaryKey, + IConventionKey? previousPrimaryKey) { EntityTypeBuilder = entityTypeBuilder; NewPrimaryKey = newPrimaryKey; @@ -839,8 +840,8 @@ public OnEntityTypePrimaryKeyChangedNode( } public IConventionEntityTypeBuilder EntityTypeBuilder { get; } - public IConventionKey NewPrimaryKey { get; } - public IConventionKey PreviousPrimaryKey { get; } + public IConventionKey? NewPrimaryKey { get; } + public IConventionKey? PreviousPrimaryKey { get; } public override void Run(ConventionDispatcher dispatcher) => dispatcher._immediateConventionScope.OnEntityTypePrimaryKeyChanged( @@ -893,8 +894,8 @@ private sealed class OnIndexAnnotationChangedNode : ConventionNode public OnIndexAnnotationChangedNode( IConventionIndexBuilder indexBuilder, string name, - IConventionAnnotation annotation, - IConventionAnnotation oldAnnotation) + IConventionAnnotation? annotation, + IConventionAnnotation? oldAnnotation) { IndexBuilder = indexBuilder; Name = name; @@ -904,8 +905,8 @@ public OnIndexAnnotationChangedNode( public IConventionIndexBuilder IndexBuilder { get; } public string Name { get; } - public IConventionAnnotation Annotation { get; } - public IConventionAnnotation OldAnnotation { get; } + public IConventionAnnotation? Annotation { get; } + public IConventionAnnotation? OldAnnotation { get; } public override void Run(ConventionDispatcher dispatcher) => dispatcher._immediateConventionScope.OnIndexAnnotationChanged( @@ -940,7 +941,7 @@ public override void Run(ConventionDispatcher dispatcher) private sealed class OnPropertyFieldChangedNode : ConventionNode { - public OnPropertyFieldChangedNode(IConventionPropertyBuilder propertyBuilder, FieldInfo newFieldInfo, FieldInfo oldFieldInfo) + public OnPropertyFieldChangedNode(IConventionPropertyBuilder propertyBuilder, FieldInfo? newFieldInfo, FieldInfo? oldFieldInfo) { PropertyBuilder = propertyBuilder; NewFieldInfo = newFieldInfo; @@ -948,8 +949,8 @@ public OnPropertyFieldChangedNode(IConventionPropertyBuilder propertyBuilder, Fi } public IConventionPropertyBuilder PropertyBuilder { get; } - public FieldInfo NewFieldInfo { get; } - public FieldInfo OldFieldInfo { get; } + public FieldInfo? NewFieldInfo { get; } + public FieldInfo? OldFieldInfo { get; } public override void Run(ConventionDispatcher dispatcher) => dispatcher._immediateConventionScope.OnPropertyFieldChanged(PropertyBuilder, NewFieldInfo, OldFieldInfo); @@ -960,8 +961,8 @@ private sealed class OnPropertyAnnotationChangedNode : ConventionNode public OnPropertyAnnotationChangedNode( IConventionPropertyBuilder propertyBuilder, string name, - IConventionAnnotation annotation, - IConventionAnnotation oldAnnotation) + IConventionAnnotation? annotation, + IConventionAnnotation? oldAnnotation) { PropertyBuilder = propertyBuilder; Name = name; @@ -971,8 +972,8 @@ public OnPropertyAnnotationChangedNode( public IConventionPropertyBuilder PropertyBuilder { get; } public string Name { get; } - public IConventionAnnotation Annotation { get; } - public IConventionAnnotation OldAnnotation { get; } + public IConventionAnnotation? Annotation { get; } + public IConventionAnnotation? OldAnnotation { get; } public override void Run(ConventionDispatcher dispatcher) => dispatcher._immediateConventionScope.OnPropertyAnnotationChanged( diff --git a/src/EFCore/Metadata/Conventions/Internal/ConventionDispatcher.ImmediateConventionScope.cs b/src/EFCore/Metadata/Conventions/Internal/ConventionDispatcher.ImmediateConventionScope.cs index 3a135ed4d92..e7603a5c3a8 100644 --- a/src/EFCore/Metadata/Conventions/Internal/ConventionDispatcher.ImmediateConventionScope.cs +++ b/src/EFCore/Metadata/Conventions/Internal/ConventionDispatcher.ImmediateConventionScope.cs @@ -5,10 +5,11 @@ using System.Collections.Generic; using System.Reflection; using JetBrains.Annotations; -using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal { public partial class ConventionDispatcher @@ -24,7 +25,6 @@ private sealed class ImmediateConventionScope : ConventionScope private readonly ConventionContext _skipNavigationBuilderConventionContext; private readonly ConventionContext _skipNavigationConventionContext; private readonly ConventionContext _navigationConventionBuilderContext; - private readonly ConventionContext _navigationConventionContext; private readonly ConventionContext _indexBuilderConventionContext; private readonly ConventionContext _indexConventionContext; private readonly ConventionContext _keyBuilderConventionContext; @@ -49,7 +49,6 @@ public ImmediateConventionScope([NotNull] ConventionSet conventionSet, Conventio _skipNavigationBuilderConventionContext = new ConventionContext(dispatcher); _skipNavigationConventionContext = new ConventionContext(dispatcher); _navigationConventionBuilderContext = new ConventionContext(dispatcher); - _navigationConventionContext = new ConventionContext(dispatcher); _indexBuilderConventionContext = new ConventionContext(dispatcher); _indexConventionContext = new ConventionContext(dispatcher); _keyBuilderConventionContext = new ConventionContext(dispatcher); @@ -67,7 +66,7 @@ public ImmediateConventionScope([NotNull] ConventionSet conventionSet, Conventio public override void Run(ConventionDispatcher dispatcher) => Check.DebugAssert(false, "Immediate convention scope cannot be run again."); - public IConventionModelBuilder OnModelFinalizing([NotNull] IConventionModelBuilder modelBuilder) + public IConventionModelBuilder? OnModelFinalizing([NotNull] IConventionModelBuilder modelBuilder) { _modelBuilderConventionContext.ResetState(modelBuilder); foreach (var modelConvention in _conventionSet.ModelFinalizingConventions) @@ -86,7 +85,7 @@ public IConventionModelBuilder OnModelFinalizing([NotNull] IConventionModelBuild return modelBuilder; } - public IModel OnModelFinalized([NotNull] IModel model) + public IModel? OnModelFinalized([NotNull] IModel model) { foreach (var modelConvention in _conventionSet.ModelFinalizedConventions) { @@ -96,7 +95,7 @@ public IModel OnModelFinalized([NotNull] IModel model) return model; } - public IConventionModelBuilder OnModelInitialized([NotNull] IConventionModelBuilder modelBuilder) + public IConventionModelBuilder? OnModelInitialized([NotNull] IConventionModelBuilder modelBuilder) { using (_dispatcher.DelayConventions()) { @@ -114,11 +113,11 @@ public IConventionModelBuilder OnModelInitialized([NotNull] IConventionModelBuil return modelBuilder; } - public override IConventionAnnotation OnModelAnnotationChanged( + public override IConventionAnnotation? OnModelAnnotationChanged( IConventionModelBuilder modelBuilder, string name, - IConventionAnnotation annotation, - IConventionAnnotation oldAnnotation) + IConventionAnnotation? annotation, + IConventionAnnotation? oldAnnotation) { using (_dispatcher.DelayConventions()) { @@ -138,14 +137,14 @@ public override IConventionAnnotation OnModelAnnotationChanged( return annotation; } - public override IConventionEntityTypeBuilder OnEntityTypeAdded(IConventionEntityTypeBuilder entityTypeBuilder) + public override IConventionEntityTypeBuilder? OnEntityTypeAdded(IConventionEntityTypeBuilder entityTypeBuilder) { using (_dispatcher.DelayConventions()) { _entityTypeBuilderConventionContext.ResetState(entityTypeBuilder); foreach (var entityTypeConvention in _conventionSet.EntityTypeAddedConventions) { - if (entityTypeBuilder.Metadata.Builder == null) + if (!entityTypeBuilder.Metadata.IsInModel) { return null; } @@ -158,7 +157,7 @@ public override IConventionEntityTypeBuilder OnEntityTypeAdded(IConventionEntity } } - if (entityTypeBuilder.Metadata.Builder == null) + if (!entityTypeBuilder.Metadata.IsInModel) { return null; } @@ -166,7 +165,7 @@ public override IConventionEntityTypeBuilder OnEntityTypeAdded(IConventionEntity return entityTypeBuilder; } - public override string OnEntityTypeIgnored(IConventionModelBuilder modelBuilder, string name, Type type) + public override string? OnEntityTypeIgnored(IConventionModelBuilder modelBuilder, string name, Type? type) { using (_dispatcher.DelayConventions()) { @@ -194,7 +193,7 @@ public override string OnEntityTypeIgnored(IConventionModelBuilder modelBuilder, return name; } - public override IConventionEntityType OnEntityTypeRemoved( + public override IConventionEntityType? OnEntityTypeRemoved( IConventionModelBuilder modelBuilder, IConventionEntityType entityType) { @@ -214,9 +213,9 @@ public override IConventionEntityType OnEntityTypeRemoved( return entityType; } - public override string OnEntityTypeMemberIgnored(IConventionEntityTypeBuilder entityTypeBuilder, string name) + public override string? OnEntityTypeMemberIgnored(IConventionEntityTypeBuilder entityTypeBuilder, string name) { - if (entityTypeBuilder.Metadata.Builder == null) + if (!entityTypeBuilder.Metadata.IsInModel) { return null; } @@ -251,17 +250,17 @@ public override string OnEntityTypeMemberIgnored(IConventionEntityTypeBuilder en return name; } - public override IConventionEntityType OnEntityTypeBaseTypeChanged( + public override IConventionEntityType? OnEntityTypeBaseTypeChanged( IConventionEntityTypeBuilder entityTypeBuilder, - IConventionEntityType newBaseType, - IConventionEntityType previousBaseType) + IConventionEntityType? newBaseType, + IConventionEntityType? previousBaseType) { using (_dispatcher.DelayConventions()) { _entityTypeConventionContext.ResetState(newBaseType); foreach (var entityTypeConvention in _conventionSet.EntityTypeBaseTypeChangedConventions) { - if (entityTypeBuilder.Metadata.Builder == null) + if (!entityTypeBuilder.Metadata.IsInModel) { return null; } @@ -275,7 +274,7 @@ public override IConventionEntityType OnEntityTypeBaseTypeChanged( } } - if (entityTypeBuilder.Metadata.Builder == null) + if (!entityTypeBuilder.Metadata.IsInModel) { return null; } @@ -283,12 +282,12 @@ public override IConventionEntityType OnEntityTypeBaseTypeChanged( return newBaseType; } - public override IConventionKey OnEntityTypePrimaryKeyChanged( + public override IConventionKey? OnEntityTypePrimaryKeyChanged( IConventionEntityTypeBuilder entityTypeBuilder, - IConventionKey newPrimaryKey, - IConventionKey previousPrimaryKey) + IConventionKey? newPrimaryKey, + IConventionKey? previousPrimaryKey) { - if (entityTypeBuilder.Metadata.Builder == null) + if (!entityTypeBuilder.Metadata.IsInModel) { return null; } @@ -314,8 +313,7 @@ public override IConventionKey OnEntityTypePrimaryKeyChanged( } } - if (newPrimaryKey != null - && newPrimaryKey.Builder == null) + if (newPrimaryKey != null && !newPrimaryKey.IsInModel) { return null; } @@ -323,18 +321,18 @@ public override IConventionKey OnEntityTypePrimaryKeyChanged( return newPrimaryKey; } - public override IConventionAnnotation OnEntityTypeAnnotationChanged( + public override IConventionAnnotation? OnEntityTypeAnnotationChanged( IConventionEntityTypeBuilder entityTypeBuilder, string name, - IConventionAnnotation annotation, - IConventionAnnotation oldAnnotation) + IConventionAnnotation? annotation, + IConventionAnnotation? oldAnnotation) { using (_dispatcher.DelayConventions()) { _annotationConventionContext.ResetState(annotation); foreach (var entityTypeConvention in _conventionSet.EntityTypeAnnotationChangedConventions) { - if (entityTypeBuilder.Metadata.Builder == null) + if (!entityTypeBuilder.Metadata.IsInModel) { return null; } @@ -348,7 +346,7 @@ public override IConventionAnnotation OnEntityTypeAnnotationChanged( } } - if (entityTypeBuilder.Metadata.Builder == null) + if (!entityTypeBuilder.Metadata.IsInModel) { return null; } @@ -356,10 +354,10 @@ public override IConventionAnnotation OnEntityTypeAnnotationChanged( return annotation; } - public override IConventionForeignKeyBuilder OnForeignKeyAdded(IConventionForeignKeyBuilder relationshipBuilder) + public override IConventionForeignKeyBuilder? OnForeignKeyAdded(IConventionForeignKeyBuilder relationshipBuilder) { - if (relationshipBuilder.Metadata.DeclaringEntityType.Builder == null - || relationshipBuilder.Metadata.PrincipalEntityType.Builder == null) + if (!relationshipBuilder.Metadata.DeclaringEntityType.IsInModel + || !relationshipBuilder.Metadata.PrincipalEntityType.IsInModel) { return null; } @@ -369,7 +367,7 @@ public override IConventionForeignKeyBuilder OnForeignKeyAdded(IConventionForeig _relationshipBuilderConventionContext.ResetState(relationshipBuilder); foreach (var foreignKeyConvention in _conventionSet.ForeignKeyAddedConventions) { - if (relationshipBuilder.Metadata.Builder == null) + if (!relationshipBuilder.Metadata.IsInModel) { return null; } @@ -382,7 +380,7 @@ public override IConventionForeignKeyBuilder OnForeignKeyAdded(IConventionForeig } } - if (relationshipBuilder.Metadata.Builder == null) + if (!relationshipBuilder.Metadata.IsInModel) { return null; } @@ -390,11 +388,11 @@ public override IConventionForeignKeyBuilder OnForeignKeyAdded(IConventionForeig return relationshipBuilder; } - public override IConventionForeignKey OnForeignKeyRemoved( + public override IConventionForeignKey? OnForeignKeyRemoved( IConventionEntityTypeBuilder entityTypeBuilder, IConventionForeignKey foreignKey) { - if (entityTypeBuilder.Metadata.Builder == null) + if (!entityTypeBuilder.Metadata.IsInModel) { return null; } @@ -415,7 +413,7 @@ public override IConventionForeignKey OnForeignKeyRemoved( return foreignKey; } - public override IReadOnlyList OnForeignKeyPropertiesChanged( + public override IReadOnlyList? OnForeignKeyPropertiesChanged( IConventionForeignKeyBuilder relationshipBuilder, IReadOnlyList oldDependentProperties, IConventionKey oldPrincipalKey) @@ -448,7 +446,7 @@ public override IReadOnlyList OnForeignKeyPropertiesChanged } } - if (relationshipBuilder.Metadata.Builder == null) + if (!relationshipBuilder.Metadata.IsInModel) { return null; } @@ -463,7 +461,7 @@ public override IReadOnlyList OnForeignKeyPropertiesChanged _boolConventionContext.ResetState(relationshipBuilder.Metadata.IsUnique); foreach (var foreignKeyConvention in _conventionSet.ForeignKeyUniquenessChangedConventions) { - if (relationshipBuilder.Metadata.Builder == null) + if (!relationshipBuilder.Metadata.IsInModel) { return null; } @@ -477,7 +475,7 @@ public override IReadOnlyList OnForeignKeyPropertiesChanged } } - if (relationshipBuilder.Metadata.Builder == null) + if (!relationshipBuilder.Metadata.IsInModel) { return null; } @@ -493,7 +491,7 @@ public override IReadOnlyList OnForeignKeyPropertiesChanged _boolConventionContext.ResetState(relationshipBuilder.Metadata.IsRequired); foreach (var foreignKeyConvention in _conventionSet.ForeignKeyRequirednessChangedConventions) { - if (relationshipBuilder.Metadata.Builder == null) + if (!relationshipBuilder.Metadata.IsInModel) { return null; } @@ -507,7 +505,7 @@ public override IReadOnlyList OnForeignKeyPropertiesChanged } } - if (relationshipBuilder.Metadata.Builder == null) + if (!relationshipBuilder.Metadata.IsInModel) { return null; } @@ -516,14 +514,14 @@ public override IReadOnlyList OnForeignKeyPropertiesChanged } public override bool? OnForeignKeyDependentRequirednessChanged( - [NotNull] IConventionForeignKeyBuilder relationshipBuilder) + IConventionForeignKeyBuilder relationshipBuilder) { using (_dispatcher.DelayConventions()) { _boolConventionContext.ResetState(relationshipBuilder.Metadata.IsRequiredDependent); foreach (var foreignKeyConvention in _conventionSet.ForeignKeyDependentRequirednessChangedConventions) { - if (relationshipBuilder.Metadata.Builder == null) + if (!relationshipBuilder.Metadata.IsInModel) { return null; } @@ -537,7 +535,7 @@ public override IReadOnlyList OnForeignKeyPropertiesChanged } } - if (relationshipBuilder.Metadata.Builder == null) + if (!relationshipBuilder.Metadata.IsInModel) { return null; } @@ -553,7 +551,7 @@ public override IReadOnlyList OnForeignKeyPropertiesChanged _boolConventionContext.ResetState(relationshipBuilder.Metadata.IsOwnership); foreach (var foreignKeyConvention in _conventionSet.ForeignKeyOwnershipChangedConventions) { - if (relationshipBuilder.Metadata.Builder == null) + if (!relationshipBuilder.Metadata.IsInModel) { return null; } @@ -566,7 +564,7 @@ public override IReadOnlyList OnForeignKeyPropertiesChanged } } - if (relationshipBuilder.Metadata.Builder == null) + if (!relationshipBuilder.Metadata.IsInModel) { return null; } @@ -574,7 +572,7 @@ public override IReadOnlyList OnForeignKeyPropertiesChanged return _boolConventionContext.Result; } - public override IConventionForeignKeyBuilder OnForeignKeyPrincipalEndChanged( + public override IConventionForeignKeyBuilder? OnForeignKeyPrincipalEndChanged( IConventionForeignKeyBuilder relationshipBuilder) { using (_dispatcher.DelayConventions()) @@ -582,7 +580,7 @@ public override IConventionForeignKeyBuilder OnForeignKeyPrincipalEndChanged( _relationshipBuilderConventionContext.ResetState(relationshipBuilder); foreach (var foreignKeyConvention in _conventionSet.ForeignKeyPrincipalEndChangedConventions) { - if (relationshipBuilder.Metadata.Builder == null) + if (!relationshipBuilder.Metadata.IsInModel) { return null; } @@ -596,7 +594,7 @@ public override IConventionForeignKeyBuilder OnForeignKeyPrincipalEndChanged( } } - if (relationshipBuilder.Metadata.Builder == null) + if (!relationshipBuilder.Metadata.IsInModel) { return null; } @@ -604,13 +602,13 @@ public override IConventionForeignKeyBuilder OnForeignKeyPrincipalEndChanged( return relationshipBuilder; } - public override IConventionAnnotation OnForeignKeyAnnotationChanged( + public override IConventionAnnotation? OnForeignKeyAnnotationChanged( IConventionForeignKeyBuilder relationshipBuilder, string name, - IConventionAnnotation annotation, - IConventionAnnotation oldAnnotation) + IConventionAnnotation? annotation, + IConventionAnnotation? oldAnnotation) { - if (relationshipBuilder.Metadata.Builder == null) + if (!relationshipBuilder.Metadata.IsInModel) { return null; } @@ -632,9 +630,9 @@ public override IConventionAnnotation OnForeignKeyAnnotationChanged( return annotation; } - public override IConventionNavigationBuilder OnNavigationAdded(IConventionNavigationBuilder navigationBuilder) + public override IConventionNavigationBuilder? OnNavigationAdded(IConventionNavigationBuilder navigationBuilder) { - if (navigationBuilder.Metadata.Builder == null) + if (!navigationBuilder.Metadata.IsInModel) { return null; } @@ -652,7 +650,7 @@ public override IConventionNavigationBuilder OnNavigationAdded(IConventionNaviga } } - if (navigationBuilder.Metadata.Builder == null) + if (!navigationBuilder.Metadata.IsInModel) { return null; } @@ -660,14 +658,14 @@ public override IConventionNavigationBuilder OnNavigationAdded(IConventionNaviga return navigationBuilder; } - public override IConventionAnnotation OnNavigationAnnotationChanged( + public override IConventionAnnotation? OnNavigationAnnotationChanged( IConventionForeignKeyBuilder relationshipBuilder, IConventionNavigation navigation, string name, - IConventionAnnotation annotation, - IConventionAnnotation oldAnnotation) + IConventionAnnotation? annotation, + IConventionAnnotation? oldAnnotation) { - if (relationshipBuilder.Metadata.Builder == null + if (!relationshipBuilder.Metadata.IsInModel || relationshipBuilder.Metadata.GetNavigation(navigation.IsOnDependent) != navigation) { return null; @@ -690,13 +688,13 @@ public override IConventionAnnotation OnNavigationAnnotationChanged( return annotation; } - public override string OnNavigationRemoved( + public override string? OnNavigationRemoved( IConventionEntityTypeBuilder sourceEntityTypeBuilder, IConventionEntityTypeBuilder targetEntityTypeBuilder, string navigationName, - MemberInfo memberInfo) + MemberInfo? memberInfo) { - if (sourceEntityTypeBuilder.Metadata.Builder == null) + if (!sourceEntityTypeBuilder.Metadata.IsInModel) { return null; } @@ -729,10 +727,10 @@ public override string OnNavigationRemoved( return navigationName; } - public override IConventionSkipNavigationBuilder OnSkipNavigationAdded( + public override IConventionSkipNavigationBuilder? OnSkipNavigationAdded( IConventionSkipNavigationBuilder navigationBuilder) { - if (navigationBuilder.Metadata.DeclaringEntityType.Builder == null) + if (!navigationBuilder.Metadata.DeclaringEntityType.IsInModel) { return null; } @@ -742,7 +740,7 @@ public override IConventionSkipNavigationBuilder OnSkipNavigationAdded( _skipNavigationBuilderConventionContext.ResetState(navigationBuilder); foreach (var skipNavigationConvention in _conventionSet.SkipNavigationAddedConventions) { - if (navigationBuilder.Metadata.Builder == null) + if (!navigationBuilder.Metadata.IsInModel) { return null; } @@ -755,7 +753,7 @@ public override IConventionSkipNavigationBuilder OnSkipNavigationAdded( } } - if (navigationBuilder.Metadata.Builder == null) + if (!navigationBuilder.Metadata.IsInModel) { return null; } @@ -763,13 +761,13 @@ public override IConventionSkipNavigationBuilder OnSkipNavigationAdded( return navigationBuilder; } - public override IConventionAnnotation OnSkipNavigationAnnotationChanged( + public override IConventionAnnotation? OnSkipNavigationAnnotationChanged( IConventionSkipNavigationBuilder navigationBuilder, string name, - IConventionAnnotation annotation, - IConventionAnnotation oldAnnotation) + IConventionAnnotation? annotation, + IConventionAnnotation? oldAnnotation) { - if (navigationBuilder.Metadata.Builder == null) + if (!navigationBuilder.Metadata.IsInModel) { return null; } @@ -779,7 +777,7 @@ public override IConventionAnnotation OnSkipNavigationAnnotationChanged( _annotationConventionContext.ResetState(annotation); foreach (var skipNavigationConvention in _conventionSet.SkipNavigationAnnotationChangedConventions) { - if (navigationBuilder.Metadata.Builder != null + if (navigationBuilder.Metadata.IsInModel && navigationBuilder.Metadata.FindAnnotation(name) != annotation) { Check.DebugAssert(false, "annotation removed"); @@ -798,12 +796,12 @@ public override IConventionAnnotation OnSkipNavigationAnnotationChanged( return annotation; } - public override IConventionForeignKey OnSkipNavigationForeignKeyChanged( + public override IConventionForeignKey? OnSkipNavigationForeignKeyChanged( IConventionSkipNavigationBuilder navigationBuilder, IConventionForeignKey foreignKey, IConventionForeignKey oldForeignKey) { - if (navigationBuilder.Metadata.DeclaringEntityType.Builder == null) + if (!navigationBuilder.Metadata.DeclaringEntityType.IsInModel) { return null; } @@ -828,7 +826,7 @@ public override IConventionForeignKey OnSkipNavigationForeignKeyChanged( } } - if (navigationBuilder.Metadata.Builder == null) + if (!navigationBuilder.Metadata.IsInModel) { return null; } @@ -836,12 +834,12 @@ public override IConventionForeignKey OnSkipNavigationForeignKeyChanged( return foreignKey; } - public override IConventionSkipNavigation OnSkipNavigationInverseChanged( + public override IConventionSkipNavigation? OnSkipNavigationInverseChanged( IConventionSkipNavigationBuilder navigationBuilder, - IConventionSkipNavigation inverse, - IConventionSkipNavigation oldInverse) + IConventionSkipNavigation? inverse, + IConventionSkipNavigation? oldInverse) { - if (navigationBuilder.Metadata.DeclaringEntityType.Builder == null) + if (!navigationBuilder.Metadata.DeclaringEntityType.IsInModel) { return null; } @@ -860,7 +858,7 @@ public override IConventionSkipNavigation OnSkipNavigationInverseChanged( } } - if (navigationBuilder.Metadata.Builder == null) + if (!navigationBuilder.Metadata.IsInModel) { return null; } @@ -868,11 +866,11 @@ public override IConventionSkipNavigation OnSkipNavigationInverseChanged( return inverse; } - public override IConventionSkipNavigation OnSkipNavigationRemoved( + public override IConventionSkipNavigation? OnSkipNavigationRemoved( IConventionEntityTypeBuilder entityTypeBuilder, IConventionSkipNavigation navigation) { - if (entityTypeBuilder.Metadata.Builder == null) + if (!entityTypeBuilder.Metadata.IsInModel) { return null; } @@ -894,9 +892,9 @@ public override IConventionSkipNavigation OnSkipNavigationRemoved( return navigation; } - public override IConventionKeyBuilder OnKeyAdded(IConventionKeyBuilder keyBuilder) + public override IConventionKeyBuilder? OnKeyAdded(IConventionKeyBuilder keyBuilder) { - if (keyBuilder.Metadata.DeclaringEntityType.Builder == null) + if (!keyBuilder.Metadata.DeclaringEntityType.IsInModel) { return null; } @@ -906,7 +904,7 @@ public override IConventionKeyBuilder OnKeyAdded(IConventionKeyBuilder keyBuilde _keyBuilderConventionContext.ResetState(keyBuilder); foreach (var keyConvention in _conventionSet.KeyAddedConventions) { - if (keyBuilder.Metadata.Builder == null) + if (!keyBuilder.Metadata.IsInModel) { return null; } @@ -919,7 +917,7 @@ public override IConventionKeyBuilder OnKeyAdded(IConventionKeyBuilder keyBuilde } } - if (keyBuilder.Metadata.Builder == null) + if (!keyBuilder.Metadata.IsInModel) { return null; } @@ -927,9 +925,9 @@ public override IConventionKeyBuilder OnKeyAdded(IConventionKeyBuilder keyBuilde return keyBuilder; } - public override IConventionKey OnKeyRemoved(IConventionEntityTypeBuilder entityTypeBuilder, IConventionKey key) + public override IConventionKey? OnKeyRemoved(IConventionEntityTypeBuilder entityTypeBuilder, IConventionKey key) { - if (entityTypeBuilder.Metadata.Builder == null) + if (!entityTypeBuilder.Metadata.IsInModel) { return null; } @@ -950,13 +948,13 @@ public override IConventionKey OnKeyRemoved(IConventionEntityTypeBuilder entityT return key; } - public override IConventionAnnotation OnKeyAnnotationChanged( + public override IConventionAnnotation? OnKeyAnnotationChanged( IConventionKeyBuilder keyBuilder, string name, - IConventionAnnotation annotation, - IConventionAnnotation oldAnnotation) + IConventionAnnotation? annotation, + IConventionAnnotation? oldAnnotation) { - if (keyBuilder.Metadata.Builder == null) + if (!keyBuilder.Metadata.IsInModel) { return null; } @@ -978,9 +976,9 @@ public override IConventionAnnotation OnKeyAnnotationChanged( return annotation; } - public override IConventionIndexBuilder OnIndexAdded(IConventionIndexBuilder indexBuilder) + public override IConventionIndexBuilder? OnIndexAdded(IConventionIndexBuilder indexBuilder) { - if (indexBuilder.Metadata.DeclaringEntityType.Builder == null) + if (!indexBuilder.Metadata.DeclaringEntityType.IsInModel) { return null; } @@ -990,7 +988,7 @@ public override IConventionIndexBuilder OnIndexAdded(IConventionIndexBuilder ind _indexBuilderConventionContext.ResetState(indexBuilder); foreach (var indexConvention in _conventionSet.IndexAddedConventions) { - if (indexBuilder.Metadata.Builder == null) + if (!indexBuilder.Metadata.IsInModel) { return null; } @@ -1003,7 +1001,7 @@ public override IConventionIndexBuilder OnIndexAdded(IConventionIndexBuilder ind } } - if (indexBuilder.Metadata.Builder == null) + if (!indexBuilder.Metadata.IsInModel) { return null; } @@ -1011,9 +1009,9 @@ public override IConventionIndexBuilder OnIndexAdded(IConventionIndexBuilder ind return indexBuilder; } - public override IConventionIndex OnIndexRemoved(IConventionEntityTypeBuilder entityTypeBuilder, IConventionIndex index) + public override IConventionIndex? OnIndexRemoved(IConventionEntityTypeBuilder entityTypeBuilder, IConventionIndex index) { - if (entityTypeBuilder.Metadata.Builder == null) + if (!entityTypeBuilder.Metadata.IsInModel) { return null; } @@ -1041,7 +1039,7 @@ public override IConventionIndex OnIndexRemoved(IConventionEntityTypeBuilder ent _boolConventionContext.ResetState(indexBuilder.Metadata.IsUnique); foreach (var indexConvention in _conventionSet.IndexUniquenessChangedConventions) { - if (indexBuilder.Metadata.Builder == null) + if (!indexBuilder.Metadata.IsInModel) { return null; } @@ -1054,7 +1052,7 @@ public override IConventionIndex OnIndexRemoved(IConventionEntityTypeBuilder ent } } - if (indexBuilder.Metadata.Builder == null) + if (!indexBuilder.Metadata.IsInModel) { return null; } @@ -1062,13 +1060,13 @@ public override IConventionIndex OnIndexRemoved(IConventionEntityTypeBuilder ent return _boolConventionContext.Result; } - public override IConventionAnnotation OnIndexAnnotationChanged( + public override IConventionAnnotation? OnIndexAnnotationChanged( IConventionIndexBuilder indexBuilder, string name, - IConventionAnnotation annotation, - IConventionAnnotation oldAnnotation) + IConventionAnnotation? annotation, + IConventionAnnotation? oldAnnotation) { - if (indexBuilder.Metadata.Builder == null) + if (!indexBuilder.Metadata.IsInModel) { return null; } @@ -1090,9 +1088,9 @@ public override IConventionAnnotation OnIndexAnnotationChanged( return annotation; } - public override IConventionPropertyBuilder OnPropertyAdded(IConventionPropertyBuilder propertyBuilder) + public override IConventionPropertyBuilder? OnPropertyAdded(IConventionPropertyBuilder propertyBuilder) { - if (propertyBuilder.Metadata.DeclaringEntityType.Builder == null) + if (!propertyBuilder.Metadata.DeclaringEntityType.IsInModel) { return null; } @@ -1102,7 +1100,7 @@ public override IConventionPropertyBuilder OnPropertyAdded(IConventionPropertyBu _propertyBuilderConventionContext.ResetState(propertyBuilder); foreach (var propertyConvention in _conventionSet.PropertyAddedConventions) { - if (propertyBuilder.Metadata.Builder == null) + if (!propertyBuilder.Metadata.IsInModel) { return null; } @@ -1115,7 +1113,7 @@ public override IConventionPropertyBuilder OnPropertyAdded(IConventionPropertyBu } } - if (propertyBuilder.Metadata.Builder == null) + if (!propertyBuilder.Metadata.IsInModel) { return null; } @@ -1125,7 +1123,7 @@ public override IConventionPropertyBuilder OnPropertyAdded(IConventionPropertyBu public override bool? OnPropertyNullabilityChanged(IConventionPropertyBuilder propertyBuilder) { - if (propertyBuilder.Metadata.DeclaringEntityType.Builder == null) + if (!propertyBuilder.Metadata.DeclaringEntityType.IsInModel) { return null; } @@ -1135,7 +1133,7 @@ public override IConventionPropertyBuilder OnPropertyAdded(IConventionPropertyBu _boolConventionContext.ResetState(propertyBuilder.Metadata.IsNullable); foreach (var propertyConvention in _conventionSet.PropertyNullabilityChangedConventions) { - if (propertyBuilder.Metadata.Builder == null) + if (!propertyBuilder.Metadata.IsInModel) { return null; } @@ -1148,7 +1146,7 @@ public override IConventionPropertyBuilder OnPropertyAdded(IConventionPropertyBu } } - if (propertyBuilder.Metadata.Builder == null) + if (!propertyBuilder.Metadata.IsInModel) { return null; } @@ -1156,13 +1154,13 @@ public override IConventionPropertyBuilder OnPropertyAdded(IConventionPropertyBu return _boolConventionContext.Result; } - public override FieldInfo OnPropertyFieldChanged( + public override FieldInfo? OnPropertyFieldChanged( IConventionPropertyBuilder propertyBuilder, - FieldInfo newFieldInfo, - FieldInfo oldFieldInfo) + FieldInfo? newFieldInfo, + FieldInfo? oldFieldInfo) { - if (propertyBuilder.Metadata.Builder == null - || propertyBuilder.Metadata.DeclaringEntityType.Builder == null) + if (!propertyBuilder.Metadata.IsInModel + || !propertyBuilder.Metadata.DeclaringEntityType.IsInModel) { return null; } @@ -1181,14 +1179,14 @@ public override FieldInfo OnPropertyFieldChanged( return _fieldInfoConventionContext.Result; } - public override IConventionAnnotation OnPropertyAnnotationChanged( + public override IConventionAnnotation? OnPropertyAnnotationChanged( IConventionPropertyBuilder propertyBuilder, string name, - IConventionAnnotation annotation, - IConventionAnnotation oldAnnotation) + IConventionAnnotation? annotation, + IConventionAnnotation? oldAnnotation) { - if (propertyBuilder.Metadata.Builder == null - || propertyBuilder.Metadata.DeclaringEntityType.Builder == null) + if (!propertyBuilder.Metadata.IsInModel + || !propertyBuilder.Metadata.DeclaringEntityType.IsInModel) { return null; } @@ -1211,11 +1209,11 @@ public override IConventionAnnotation OnPropertyAnnotationChanged( return annotation; } - public override IConventionProperty OnPropertyRemoved( + public override IConventionProperty? OnPropertyRemoved( IConventionEntityTypeBuilder entityTypeBuilder, IConventionProperty property) { - if (entityTypeBuilder.Metadata.Builder == null) + if (!entityTypeBuilder.Metadata.IsInModel) { return null; } diff --git a/src/EFCore/Metadata/Conventions/Internal/ConventionDispatcher.cs b/src/EFCore/Metadata/Conventions/Internal/ConventionDispatcher.cs index 57660ba39dd..89af1122fe4 100644 --- a/src/EFCore/Metadata/Conventions/Internal/ConventionDispatcher.cs +++ b/src/EFCore/Metadata/Conventions/Internal/ConventionDispatcher.cs @@ -10,6 +10,9 @@ using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Metadata.Internal; using Microsoft.EntityFrameworkCore.Utilities; +using CA = System.Diagnostics.CodeAnalysis; + +#nullable enable namespace Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal { @@ -51,7 +54,7 @@ public ConventionDispatcher([NotNull] ConventionSet conventionSet) /// 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. /// - public virtual IConventionModelBuilder OnModelInitialized([NotNull] IConventionModelBuilder modelBuilder) + public virtual IConventionModelBuilder? OnModelInitialized([NotNull] IConventionModelBuilder modelBuilder) => _immediateConventionScope.OnModelInitialized(modelBuilder); /// @@ -60,7 +63,7 @@ public virtual IConventionModelBuilder OnModelInitialized([NotNull] IConventionM /// 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. /// - public virtual IConventionModelBuilder OnModelFinalizing([NotNull] IConventionModelBuilder modelBuilder) + public virtual IConventionModelBuilder? OnModelFinalizing([NotNull] IConventionModelBuilder modelBuilder) => _immediateConventionScope.OnModelFinalizing(modelBuilder); /// @@ -69,7 +72,7 @@ public virtual IConventionModelBuilder OnModelFinalizing([NotNull] IConventionMo /// 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. /// - public virtual IModel OnModelFinalized([NotNull] IModel model) + public virtual IModel? OnModelFinalized([NotNull] IModel model) => _immediateConventionScope.OnModelFinalized(model); /// @@ -78,11 +81,11 @@ public virtual IModel OnModelFinalized([NotNull] IModel model) /// 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. /// - public virtual IConventionAnnotation OnModelAnnotationChanged( + public virtual IConventionAnnotation? OnModelAnnotationChanged( [NotNull] IConventionModelBuilder modelBuilder, [NotNull] string name, - [CanBeNull] IConventionAnnotation annotation, - [CanBeNull] IConventionAnnotation oldAnnotation) + [CanBeNull] IConventionAnnotation? annotation, + [CanBeNull] IConventionAnnotation? oldAnnotation) { if (CoreAnnotationNames.AllNames.Contains(name)) { @@ -102,7 +105,7 @@ public virtual IConventionAnnotation OnModelAnnotationChanged( /// 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. /// - public virtual IConventionEntityTypeBuilder OnEntityTypeAdded([NotNull] IConventionEntityTypeBuilder entityTypeBuilder) + public virtual IConventionEntityTypeBuilder? OnEntityTypeAdded([NotNull] IConventionEntityTypeBuilder entityTypeBuilder) => _scope.OnEntityTypeAdded(entityTypeBuilder); /// @@ -111,10 +114,10 @@ public virtual IConventionEntityTypeBuilder OnEntityTypeAdded([NotNull] IConvent /// 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. /// - public virtual string OnEntityTypeIgnored( + public virtual string? OnEntityTypeIgnored( [NotNull] IConventionModelBuilder modelBuilder, [NotNull] string name, - [CanBeNull] Type type) + [CanBeNull] Type? type) => _scope.OnEntityTypeIgnored(modelBuilder, name, type); /// @@ -123,7 +126,7 @@ public virtual string OnEntityTypeIgnored( /// 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. /// - public virtual IConventionEntityType OnEntityTypeRemoved( + public virtual IConventionEntityType? OnEntityTypeRemoved( [NotNull] IConventionModelBuilder modelBuilder, [NotNull] IConventionEntityType type) => _scope.OnEntityTypeRemoved(modelBuilder, type); @@ -134,7 +137,7 @@ public virtual IConventionEntityType OnEntityTypeRemoved( /// 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. /// - public virtual string OnEntityTypeMemberIgnored( + public virtual string? OnEntityTypeMemberIgnored( [NotNull] IConventionEntityTypeBuilder entityTypeBuilder, [NotNull] string name) => _scope.OnEntityTypeMemberIgnored(entityTypeBuilder, name); @@ -145,10 +148,10 @@ public virtual string OnEntityTypeMemberIgnored( /// 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. /// - public virtual IConventionEntityType OnEntityTypeBaseTypeChanged( + public virtual IConventionEntityType? OnEntityTypeBaseTypeChanged( [NotNull] IConventionEntityTypeBuilder entityTypeBuilder, - [CanBeNull] IConventionEntityType newBaseType, - [CanBeNull] IConventionEntityType previousBaseType) + [CanBeNull] IConventionEntityType? newBaseType, + [CanBeNull] IConventionEntityType? previousBaseType) => _scope.OnEntityTypeBaseTypeChanged(entityTypeBuilder, newBaseType, previousBaseType); /// @@ -157,11 +160,11 @@ public virtual IConventionEntityType OnEntityTypeBaseTypeChanged( /// 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. /// - public virtual IConventionAnnotation OnEntityTypeAnnotationChanged( + public virtual IConventionAnnotation? OnEntityTypeAnnotationChanged( [NotNull] IConventionEntityTypeBuilder entityTypeBuilder, [NotNull] string name, - [CanBeNull] IConventionAnnotation annotation, - [CanBeNull] IConventionAnnotation oldAnnotation) + [CanBeNull] IConventionAnnotation? annotation, + [CanBeNull] IConventionAnnotation? oldAnnotation) { if (CoreAnnotationNames.AllNames.Contains(name)) { @@ -181,7 +184,7 @@ public virtual IConventionAnnotation OnEntityTypeAnnotationChanged( /// 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. /// - public virtual IConventionForeignKeyBuilder OnForeignKeyAdded([NotNull] IConventionForeignKeyBuilder relationshipBuilder) + public virtual IConventionForeignKeyBuilder? OnForeignKeyAdded([NotNull] IConventionForeignKeyBuilder relationshipBuilder) => _scope.OnForeignKeyAdded(relationshipBuilder); /// @@ -190,7 +193,7 @@ public virtual IConventionForeignKeyBuilder OnForeignKeyAdded([NotNull] IConvent /// 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. /// - public virtual IConventionForeignKey OnForeignKeyRemoved( + public virtual IConventionForeignKey? OnForeignKeyRemoved( [NotNull] IConventionEntityTypeBuilder entityTypeBuilder, [NotNull] IConventionForeignKey foreignKey) => _scope.OnForeignKeyRemoved(entityTypeBuilder, foreignKey); @@ -201,7 +204,7 @@ public virtual IConventionForeignKey OnForeignKeyRemoved( /// 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. /// - public virtual IReadOnlyList OnForeignKeyPropertiesChanged( + public virtual IReadOnlyList? OnForeignKeyPropertiesChanged( [NotNull] IConventionForeignKeyBuilder relationshipBuilder, [NotNull] IReadOnlyList oldDependentProperties, [NotNull] IConventionKey oldPrincipalKey) @@ -256,7 +259,7 @@ public virtual IReadOnlyList OnForeignKeyPropertiesChanged( /// 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. /// - public virtual IConventionForeignKeyBuilder OnForeignKeyPrincipalEndChanged( + public virtual IConventionForeignKeyBuilder? OnForeignKeyPrincipalEndChanged( [NotNull] IConventionForeignKeyBuilder relationshipBuilder) => _scope.OnForeignKeyPrincipalEndChanged(relationshipBuilder); @@ -266,11 +269,11 @@ public virtual IConventionForeignKeyBuilder OnForeignKeyPrincipalEndChanged( /// 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. /// - public virtual IConventionAnnotation OnForeignKeyAnnotationChanged( + public virtual IConventionAnnotation? OnForeignKeyAnnotationChanged( [NotNull] IConventionForeignKeyBuilder relationshipBuilder, [NotNull] string name, - [CanBeNull] IConventionAnnotation annotation, - [CanBeNull] IConventionAnnotation oldAnnotation) + [CanBeNull] IConventionAnnotation? annotation, + [CanBeNull] IConventionAnnotation? oldAnnotation) { if (CoreAnnotationNames.AllNames.Contains(name)) { @@ -290,7 +293,7 @@ public virtual IConventionAnnotation OnForeignKeyAnnotationChanged( /// 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. /// - public virtual IConventionNavigationBuilder OnNavigationAdded([NotNull] IConventionNavigationBuilder navigationBuilder) + public virtual IConventionNavigationBuilder? OnNavigationAdded([NotNull] IConventionNavigationBuilder navigationBuilder) => _scope.OnNavigationAdded(navigationBuilder); /// @@ -299,11 +302,11 @@ public virtual IConventionNavigationBuilder OnNavigationAdded([NotNull] IConvent /// 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. /// - public virtual string OnNavigationRemoved( + public virtual string? OnNavigationRemoved( [NotNull] IConventionEntityTypeBuilder sourceEntityTypeBuilder, [NotNull] IConventionEntityTypeBuilder targetEntityTypeBuilder, [NotNull] string navigationName, - [CanBeNull] MemberInfo memberInfo) + [CanBeNull] MemberInfo? memberInfo) => _scope.OnNavigationRemoved( sourceEntityTypeBuilder, targetEntityTypeBuilder, @@ -316,12 +319,12 @@ public virtual string OnNavigationRemoved( /// 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. /// - public virtual IConventionAnnotation OnNavigationAnnotationChanged( + public virtual IConventionAnnotation? OnNavigationAnnotationChanged( [NotNull] IConventionForeignKeyBuilder relationshipBuilder, [NotNull] IConventionNavigation navigation, [NotNull] string name, - [CanBeNull] IConventionAnnotation annotation, - [CanBeNull] IConventionAnnotation oldAnnotation) + [CanBeNull] IConventionAnnotation? annotation, + [CanBeNull] IConventionAnnotation? oldAnnotation) { if (CoreAnnotationNames.AllNames.Contains(name)) { @@ -342,7 +345,7 @@ public virtual IConventionAnnotation OnNavigationAnnotationChanged( /// 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. /// - public virtual IConventionSkipNavigationBuilder OnSkipNavigationAdded( + public virtual IConventionSkipNavigationBuilder? OnSkipNavigationAdded( [NotNull] IConventionSkipNavigationBuilder navigationBuilder) => _scope.OnSkipNavigationAdded(navigationBuilder); @@ -352,7 +355,7 @@ public virtual IConventionSkipNavigationBuilder OnSkipNavigationAdded( /// 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. /// - public virtual IConventionForeignKey OnSkipNavigationForeignKeyChanged( + public virtual IConventionForeignKey? OnSkipNavigationForeignKeyChanged( [NotNull] IConventionSkipNavigationBuilder navigationBuilder, [NotNull] IConventionForeignKey foreignKey, [NotNull] IConventionForeignKey oldForeignKey) @@ -364,10 +367,10 @@ public virtual IConventionForeignKey OnSkipNavigationForeignKeyChanged( /// 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. /// - public virtual IConventionSkipNavigation OnSkipNavigationInverseChanged( + public virtual IConventionSkipNavigation? OnSkipNavigationInverseChanged( [NotNull] IConventionSkipNavigationBuilder navigationBuilder, - [CanBeNull] IConventionSkipNavigation inverse, - [CanBeNull] IConventionSkipNavigation oldInverse) + [CanBeNull] IConventionSkipNavigation? inverse, + [CanBeNull] IConventionSkipNavigation? oldInverse) => _scope.OnSkipNavigationInverseChanged(navigationBuilder, inverse, oldInverse); /// @@ -376,7 +379,7 @@ public virtual IConventionSkipNavigation OnSkipNavigationInverseChanged( /// 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. /// - public virtual IConventionSkipNavigation OnSkipNavigationRemoved( + public virtual IConventionSkipNavigation? OnSkipNavigationRemoved( [NotNull] IConventionEntityTypeBuilder entityTypeBuilder, [NotNull] IConventionSkipNavigation navigation) => _scope.OnSkipNavigationRemoved(entityTypeBuilder, navigation); @@ -387,11 +390,11 @@ public virtual IConventionSkipNavigation OnSkipNavigationRemoved( /// 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. /// - public virtual IConventionAnnotation OnSkipNavigationAnnotationChanged( + public virtual IConventionAnnotation? OnSkipNavigationAnnotationChanged( [NotNull] IConventionSkipNavigationBuilder navigationBuilder, [NotNull] string name, - [CanBeNull] IConventionAnnotation annotation, - [CanBeNull] IConventionAnnotation oldAnnotation) + [CanBeNull] IConventionAnnotation? annotation, + [CanBeNull] IConventionAnnotation? oldAnnotation) { if (CoreAnnotationNames.AllNames.Contains(name)) { @@ -411,7 +414,7 @@ public virtual IConventionAnnotation OnSkipNavigationAnnotationChanged( /// 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. /// - public virtual IConventionKeyBuilder OnKeyAdded([NotNull] IConventionKeyBuilder keyBuilder) + public virtual IConventionKeyBuilder? OnKeyAdded([NotNull] IConventionKeyBuilder keyBuilder) => _scope.OnKeyAdded(keyBuilder); /// @@ -420,7 +423,7 @@ public virtual IConventionKeyBuilder OnKeyAdded([NotNull] IConventionKeyBuilder /// 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. /// - public virtual IConventionKey OnKeyRemoved([NotNull] IConventionEntityTypeBuilder entityTypeBuilder, [NotNull] IConventionKey key) + public virtual IConventionKey? OnKeyRemoved([NotNull] IConventionEntityTypeBuilder entityTypeBuilder, [NotNull] IConventionKey key) => _scope.OnKeyRemoved(entityTypeBuilder, key); /// @@ -429,11 +432,11 @@ public virtual IConventionKey OnKeyRemoved([NotNull] IConventionEntityTypeBuilde /// 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. /// - public virtual IConventionAnnotation OnKeyAnnotationChanged( + public virtual IConventionAnnotation? OnKeyAnnotationChanged( [NotNull] IConventionKeyBuilder keyBuilder, [NotNull] string name, - [CanBeNull] IConventionAnnotation annotation, - [CanBeNull] IConventionAnnotation oldAnnotation) + [CanBeNull] IConventionAnnotation? annotation, + [CanBeNull] IConventionAnnotation? oldAnnotation) { if (CoreAnnotationNames.AllNames.Contains(name)) { @@ -453,10 +456,10 @@ public virtual IConventionAnnotation OnKeyAnnotationChanged( /// 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. /// - public virtual IConventionKey OnPrimaryKeyChanged( + public virtual IConventionKey? OnPrimaryKeyChanged( [NotNull] IConventionEntityTypeBuilder entityTypeBuilder, - [CanBeNull] IConventionKey newPrimaryKey, - [CanBeNull] IConventionKey previousPrimaryKey) + [CanBeNull] IConventionKey? newPrimaryKey, + [CanBeNull] IConventionKey? previousPrimaryKey) => _scope.OnEntityTypePrimaryKeyChanged(entityTypeBuilder, newPrimaryKey, previousPrimaryKey); /// @@ -465,7 +468,7 @@ public virtual IConventionKey OnPrimaryKeyChanged( /// 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. /// - public virtual IConventionIndexBuilder OnIndexAdded([NotNull] IConventionIndexBuilder indexBuilder) + public virtual IConventionIndexBuilder? OnIndexAdded([NotNull] IConventionIndexBuilder indexBuilder) => _scope.OnIndexAdded(indexBuilder); /// @@ -474,7 +477,7 @@ public virtual IConventionIndexBuilder OnIndexAdded([NotNull] IConventionIndexBu /// 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. /// - public virtual IConventionIndex OnIndexRemoved( + public virtual IConventionIndex? OnIndexRemoved( [NotNull] IConventionEntityTypeBuilder entityTypeBuilder, [NotNull] IConventionIndex index) => _scope.OnIndexRemoved(entityTypeBuilder, index); @@ -494,11 +497,11 @@ public virtual IConventionIndex OnIndexRemoved( /// 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. /// - public virtual IConventionAnnotation OnIndexAnnotationChanged( + public virtual IConventionAnnotation? OnIndexAnnotationChanged( [NotNull] IConventionIndexBuilder indexBuilder, [NotNull] string name, - [CanBeNull] IConventionAnnotation annotation, - [CanBeNull] IConventionAnnotation oldAnnotation) + [CanBeNull] IConventionAnnotation? annotation, + [CanBeNull] IConventionAnnotation? oldAnnotation) { if (CoreAnnotationNames.AllNames.Contains(name)) { @@ -518,7 +521,7 @@ public virtual IConventionAnnotation OnIndexAnnotationChanged( /// 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. /// - public virtual IConventionPropertyBuilder OnPropertyAdded([NotNull] IConventionPropertyBuilder propertyBuilder) + public virtual IConventionPropertyBuilder? OnPropertyAdded([NotNull] IConventionPropertyBuilder propertyBuilder) => _scope.OnPropertyAdded(propertyBuilder); /// @@ -527,7 +530,7 @@ public virtual IConventionPropertyBuilder OnPropertyAdded([NotNull] IConventionP /// 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. /// - public virtual IConventionProperty OnPropertyRemoved( + public virtual IConventionProperty? OnPropertyRemoved( [NotNull] IConventionEntityTypeBuilder entityTypeBuilder, [NotNull] IConventionProperty property) => _scope.OnPropertyRemoved(entityTypeBuilder, property); @@ -547,10 +550,10 @@ public virtual IConventionProperty OnPropertyRemoved( /// 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. /// - public virtual FieldInfo OnPropertyFieldChanged( + public virtual FieldInfo? OnPropertyFieldChanged( [NotNull] IConventionPropertyBuilder propertyBuilder, - [CanBeNull] FieldInfo newFieldInfo, - [CanBeNull] FieldInfo oldFieldInfo) + [CanBeNull] FieldInfo? newFieldInfo, + [CanBeNull] FieldInfo? oldFieldInfo) => _scope.OnPropertyFieldChanged(propertyBuilder, newFieldInfo, oldFieldInfo); /// @@ -559,11 +562,11 @@ public virtual FieldInfo OnPropertyFieldChanged( /// 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. /// - public virtual IConventionAnnotation OnPropertyAnnotationChanged( + public virtual IConventionAnnotation? OnPropertyAnnotationChanged( [NotNull] IConventionPropertyBuilder propertyBuilder, [NotNull] string name, - [CanBeNull] IConventionAnnotation annotation, - [CanBeNull] IConventionAnnotation oldAnnotation) + [CanBeNull] IConventionAnnotation? annotation, + [CanBeNull] IConventionAnnotation? oldAnnotation) { if (CoreAnnotationNames.AllNames.Contains(name)) { @@ -592,13 +595,15 @@ public virtual IConventionBatch DelayConventions() /// 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. /// - public virtual T Track([NotNull] Func func, [CanBeNull] ref IConventionForeignKey foreignKey) + public virtual T Track([NotNull] Func func, [CanBeNull] [CA.DisallowNull] ref IConventionForeignKey? foreignKey) { var batch = DelayConventions(); using var foreignKeyReference = Tracker.Track(foreignKey); var result = func(); batch.Dispose(); - foreignKey = foreignKeyReference.Object?.Builder == null ? null : foreignKeyReference.Object; + foreignKey = foreignKeyReference.Object is null || !foreignKeyReference.Object.IsInModel + ? null + : foreignKeyReference.Object; return result; } @@ -649,7 +654,7 @@ private void Run() return; } - _dispatcher._scope = currentScope.Parent; + _dispatcher._scope = currentScope.Parent!; if (currentScope.Children == null) { @@ -668,7 +673,7 @@ private void Run() } } - public IConventionForeignKey Run(IConventionForeignKey foreignKey) + public IConventionForeignKey? Run(IConventionForeignKey foreignKey) { if (_runCount == null) { @@ -677,7 +682,9 @@ public IConventionForeignKey Run(IConventionForeignKey foreignKey) using var foreignKeyReference = _dispatcher.Tracker.Track(foreignKey); Run(); - return foreignKeyReference.Object?.Builder == null ? null : foreignKeyReference.Object; + return foreignKeyReference.Object is null || !foreignKeyReference.Object.IsInModel + ? null + : foreignKeyReference.Object; } public void Dispose() diff --git a/src/EFCore/Metadata/Conventions/Internal/IReadableConventionContext.cs b/src/EFCore/Metadata/Conventions/Internal/IReadableConventionContext.cs index dc36c0c2959..46492cbddd4 100644 --- a/src/EFCore/Metadata/Conventions/Internal/IReadableConventionContext.cs +++ b/src/EFCore/Metadata/Conventions/Internal/IReadableConventionContext.cs @@ -1,6 +1,8 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal { /// diff --git a/src/EFCore/Metadata/Conventions/Internal/MetadataTracker.cs b/src/EFCore/Metadata/Conventions/Internal/MetadataTracker.cs index 43db35eb781..66f90245d63 100644 --- a/src/EFCore/Metadata/Conventions/Internal/MetadataTracker.cs +++ b/src/EFCore/Metadata/Conventions/Internal/MetadataTracker.cs @@ -6,6 +6,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Internal; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal { /// @@ -27,8 +29,8 @@ public class MetadataTracker : IReferenceRoot public virtual void Update([NotNull] ForeignKey oldForeignKey, [NotNull] ForeignKey newForeignKey) { Check.DebugAssert( - oldForeignKey.Builder == null && newForeignKey.Builder != null, - "oldForeignKey.Builder is not null or newForeignKey.Builder is null"); + !oldForeignKey.IsInModel && newForeignKey.IsInModel, + $"{nameof(oldForeignKey)} is in the model or {nameof(newForeignKey)} isn't"); if (_trackedForeignKeys.TryGetValue(oldForeignKey, out var reference)) { diff --git a/src/EFCore/Metadata/Conventions/Internal/RuntimeConventionSetBuilder.cs b/src/EFCore/Metadata/Conventions/Internal/RuntimeConventionSetBuilder.cs index daf67df0aee..99f88384892 100644 --- a/src/EFCore/Metadata/Conventions/Internal/RuntimeConventionSetBuilder.cs +++ b/src/EFCore/Metadata/Conventions/Internal/RuntimeConventionSetBuilder.cs @@ -7,6 +7,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure; using Microsoft.Extensions.DependencyInjection; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal { /// diff --git a/src/EFCore/Metadata/Conventions/InversePropertyAttributeConvention.cs b/src/EFCore/Metadata/Conventions/InversePropertyAttributeConvention.cs index b4f37a5be59..9b5c7ab280e 100644 --- a/src/EFCore/Metadata/Conventions/InversePropertyAttributeConvention.cs +++ b/src/EFCore/Metadata/Conventions/InversePropertyAttributeConvention.cs @@ -14,6 +14,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Internal; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// @@ -76,7 +78,7 @@ private void Process( ConfigureInverseNavigation(entityTypeBuilder, navigationMemberInfo, targetEntityTypeBuilder, attribute); } - private IConventionForeignKeyBuilder ConfigureInverseNavigation( + private IConventionForeignKeyBuilder? ConfigureInverseNavigation( IConventionEntityTypeBuilder entityTypeBuilder, MemberInfo navigationMemberInfo, IConventionEntityTypeBuilder targetEntityTypeBuilder, @@ -84,11 +86,11 @@ private IConventionForeignKeyBuilder ConfigureInverseNavigation( { var entityType = entityTypeBuilder.Metadata; var targetClrType = targetEntityTypeBuilder.Metadata.ClrType; - var inverseNavigationPropertyInfo = targetEntityTypeBuilder.Metadata.GetRuntimeProperties().Values + var inverseNavigationPropertyInfo = targetEntityTypeBuilder.Metadata.GetRuntimeProperties()!.Values .FirstOrDefault(p => string.Equals(p.GetSimpleMemberName(), attribute.Property, StringComparison.OrdinalIgnoreCase)); if (inverseNavigationPropertyInfo == null - || !Dependencies.MemberClassifier.FindCandidateNavigationPropertyType(inverseNavigationPropertyInfo) + || !Dependencies.MemberClassifier.FindCandidateNavigationPropertyType(inverseNavigationPropertyInfo)! .IsAssignableFrom(entityType.ClrType)) { throw new InvalidOperationException( @@ -107,7 +109,7 @@ private IConventionForeignKeyBuilder ConfigureInverseNavigation( // Check for InversePropertyAttribute on the inverse navigation to verify that it matches. if (Attribute.IsDefined(inverseNavigationPropertyInfo, typeof(InversePropertyAttribute))) { - var inverseAttribute = inverseNavigationPropertyInfo.GetCustomAttribute(true); + var inverseAttribute = inverseNavigationPropertyInfo.GetCustomAttribute(true)!; if (inverseAttribute.Property != navigationMemberInfo.GetSimpleMemberName()) { throw new InvalidOperationException( @@ -149,25 +151,25 @@ private IConventionForeignKeyBuilder ConfigureInverseNavigation( var existingInverseType = existingInverse?.DeclaringEntityType; if (existingInverse != null && IsAmbiguousInverse( - existingInverse.GetIdentifyingMemberInfo(), existingInverseType, referencingNavigationsWithAttribute)) + existingInverse.GetIdentifyingMemberInfo()!, existingInverseType!, referencingNavigationsWithAttribute)) { existingInverse.DeclaringEntityType.Builder.HasNoSkipNavigation(existingInverse, fromDataAnnotation: true); - inverseSkipNavigation.DeclaringEntityType.Builder.HasNoSkipNavigation( + inverseSkipNavigation!.DeclaringEntityType.Builder.HasNoSkipNavigation( inverseSkipNavigation, fromDataAnnotation: true); } - if (existingSkipNavigation.Builder != null) + if (existingSkipNavigation.IsInModel) { entityType.Builder.HasNoSkipNavigation(existingSkipNavigation, fromDataAnnotation: true); } - if (existingSkipNavigationInverse?.Builder != null) + if (existingSkipNavigationInverse?.IsInModel == true) { existingSkipNavigationInverse.DeclaringEntityType.Builder .HasNoSkipNavigation(existingSkipNavigationInverse, fromDataAnnotation: true); } - var existingAmbiguousNavigation = FindActualEntityType(ambiguousInverse.Value.Item2) + var existingAmbiguousNavigation = FindActualEntityType(ambiguousInverse.Value.Item2)! .FindSkipNavigation(ambiguousInverse.Value.Item1); if (existingAmbiguousNavigation != null) { @@ -175,7 +177,7 @@ private IConventionForeignKeyBuilder ConfigureInverseNavigation( existingAmbiguousNavigation, fromDataAnnotation: true); } - return entityType.FindSkipNavigation(navigationMemberInfo)?.ForeignKey.Builder; + return entityType.FindSkipNavigation(navigationMemberInfo)?.ForeignKey!.Builder; } else { @@ -183,14 +185,14 @@ private IConventionForeignKeyBuilder ConfigureInverseNavigation( var existingInverseType = existingInverse?.DeclaringEntityType; if (existingInverse != null && IsAmbiguousInverse( - existingInverse.GetIdentifyingMemberInfo(), existingInverseType, referencingNavigationsWithAttribute)) + existingInverse.GetIdentifyingMemberInfo()!, existingInverseType!, referencingNavigationsWithAttribute)) { var fk = existingInverse.ForeignKey; if (fk.IsOwnership || fk.DeclaringEntityType.Builder.HasNoRelationship(fk, fromDataAnnotation: true) == null) { fk.Builder.HasNavigation( - (string)null, + (string?)null, existingInverse.IsOnDependent, fromDataAnnotation: true); } @@ -204,13 +206,13 @@ private IConventionForeignKeyBuilder ConfigureInverseNavigation( || fk.DeclaringEntityType.Builder.HasNoRelationship(fk, fromDataAnnotation: true) == null) { fk.Builder.HasNavigation( - (string)null, + (string?)null, existingNavigation.IsOnDependent, fromDataAnnotation: true); } } - var existingAmbiguousNavigation = FindActualEntityType(ambiguousInverse.Value.Item2) + var existingAmbiguousNavigation = FindActualEntityType(ambiguousInverse.Value.Item2)! .FindNavigation(ambiguousInverse.Value.Item1); if (existingAmbiguousNavigation != null) { @@ -219,7 +221,7 @@ private IConventionForeignKeyBuilder ConfigureInverseNavigation( || fk.DeclaringEntityType.Builder.HasNoRelationship(fk, fromDataAnnotation: true) == null) { fk.Builder.HasNavigation( - (string)null, + (string?)null, existingAmbiguousNavigation.IsOnDependent, fromDataAnnotation: true); } @@ -246,15 +248,15 @@ private IConventionForeignKeyBuilder ConfigureInverseNavigation( && !entityType.IsInOwnershipPath(targetEntityTypeBuilder.Metadata)) { if (navigationMemberInfo.DeclaringType != entityType.ClrType - && (entityType.Model.GetEntityTypes(navigationMemberInfo.DeclaringType).Any() + && (entityType.Model.GetEntityTypes(navigationMemberInfo.DeclaringType!).Any() || (navigationMemberInfo.DeclaringType != entityType.ClrType.BaseType - && entityType.Model.GetEntityTypes(entityType.ClrType.BaseType).Any()))) + && entityType.Model.GetEntityTypes(entityType.ClrType.BaseType!).Any()))) { return null; } return targetEntityTypeBuilder.HasOwnership( - entityTypeBuilder.Metadata.ClrType, + entityTypeBuilder.Metadata.ClrType!, inverseNavigationPropertyInfo, navigationMemberInfo, fromDataAnnotation: true); @@ -332,7 +334,7 @@ public override void ProcessNavigationAdded( var newRelationshipBuilder = ConfigureInverseNavigation( navigation.DeclaringEntityType.Builder, - navigation.GetIdentifyingMemberInfo(), + navigation.GetIdentifyingMemberInfo()!, navigation.TargetEntityType.Builder, attribute); @@ -352,8 +354,8 @@ public override void ProcessNavigationAdded( /// public override void ProcessEntityTypeBaseTypeChanged( IConventionEntityTypeBuilder entityTypeBuilder, - IConventionEntityType newBaseType, - IConventionEntityType oldBaseType, + IConventionEntityType? newBaseType, + IConventionEntityType? oldBaseType, MemberInfo navigationMemberInfo, Type targetClrType, InversePropertyAttribute attribute, @@ -481,9 +483,10 @@ public static bool IsAmbiguous( return false; } - while (targetEntityType != null) + var currentEntityType = targetEntityType; + while (currentEntityType != null) { - var navigationMap = GetInverseNavigations(targetEntityType); + var navigationMap = GetInverseNavigations(currentEntityType); if (navigationMap != null) { foreach (var inverseNavigationTuple in navigationMap.Values) @@ -496,7 +499,7 @@ public static bool IsAmbiguous( } } - targetEntityType = targetEntityType.BaseType; + currentEntityType = currentEntityType.BaseType; } return false; @@ -517,8 +520,8 @@ private static (MemberInfo, IConventionEntityType)? FindAmbiguousInverse( foreach (var referencingTuple in referencingNavigationsWithAttribute) { var inverseEntityType = FindActualEntityType(referencingTuple.InverseEntityType); - if (inverseEntityType?.Builder.IsIgnored( - referencingTuple.Inverse.GetSimpleMemberName(), fromDataAnnotation: true) != false) + if (inverseEntityType is null + || inverseEntityType.Builder.IsIgnored(referencingTuple.Inverse.GetSimpleMemberName(), fromDataAnnotation: true)) { continue; } @@ -619,10 +622,10 @@ private static void RemoveInverseNavigation( } } - private static IConventionEntityType FindActualEntityType(IConventionEntityType entityType) + private static IConventionEntityType? FindActualEntityType(IConventionEntityType entityType) => ((Model)entityType.Model).FindActualEntityType((EntityType)entityType); - private static Dictionary References)> + private static Dictionary References)>? GetInverseNavigations( IConventionAnnotatable entityType) => entityType.FindAnnotation(CoreAnnotationNames.InverseNavigations)?.Value diff --git a/src/EFCore/Metadata/Conventions/KeyAttributeConvention.cs b/src/EFCore/Metadata/Conventions/KeyAttributeConvention.cs index 4fd03ee87c0..00333850370 100644 --- a/src/EFCore/Metadata/Conventions/KeyAttributeConvention.cs +++ b/src/EFCore/Metadata/Conventions/KeyAttributeConvention.cs @@ -12,6 +12,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata.Internal; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// diff --git a/src/EFCore/Metadata/Conventions/KeyDiscoveryConvention.cs b/src/EFCore/Metadata/Conventions/KeyDiscoveryConvention.cs index 7460470fded..750dd4222df 100644 --- a/src/EFCore/Metadata/Conventions/KeyDiscoveryConvention.cs +++ b/src/EFCore/Metadata/Conventions/KeyDiscoveryConvention.cs @@ -10,6 +10,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// @@ -69,7 +71,7 @@ protected virtual void TryConfigurePrimaryKey([NotNull] IConventionEntityTypeBui return; } - List keyProperties = null; + List? keyProperties = null; var ownership = entityType.FindOwnership(); if (ownership != null && ownership.DeclaringEntityType != entityType) @@ -103,10 +105,10 @@ protected virtual void TryConfigurePrimaryKey([NotNull] IConventionEntityTypeBui var primaryKey = entityType.FindPrimaryKey(); var shadowProperty = primaryKey?.Properties.Last(); if (shadowProperty == null - || primaryKey.Properties.Count == 1 + || primaryKey!.Properties.Count == 1 || ownership.Properties.Contains(shadowProperty)) { - shadowProperty = entityTypeBuilder.CreateUniqueProperty(typeof(int), "Id", required: true).Metadata; + shadowProperty = entityTypeBuilder.CreateUniqueProperty(typeof(int), "Id", required: true)!.Metadata; } keyProperties.Clear(); @@ -198,8 +200,8 @@ public virtual void ProcessEntityTypeAdded( /// public virtual void ProcessEntityTypeBaseTypeChanged( IConventionEntityTypeBuilder entityTypeBuilder, - IConventionEntityType newBaseType, - IConventionEntityType oldBaseType, + IConventionEntityType? newBaseType, + IConventionEntityType? oldBaseType, IConventionContext context) { if (entityTypeBuilder.Metadata.BaseType != newBaseType) @@ -251,7 +253,7 @@ public virtual void ProcessForeignKeyPropertiesChanged( var foreignKey = relationshipBuilder.Metadata; if (foreignKey.IsOwnership && !foreignKey.Properties.SequenceEqual(oldDependentProperties) - && relationshipBuilder.Metadata.Builder != null) + && relationshipBuilder.Metadata.IsInModel) { TryConfigurePrimaryKey(foreignKey.DeclaringEntityType.Builder); } @@ -291,8 +293,8 @@ public virtual void ProcessForeignKeyUniquenessChanged( /// public virtual void ProcessSkipNavigationForeignKeyChanged( IConventionSkipNavigationBuilder skipNavigationBuilder, - IConventionForeignKey foreignKey, - IConventionForeignKey oldForeignKey, + IConventionForeignKey? foreignKey, + IConventionForeignKey? oldForeignKey, IConventionContext context) { var joinEntityTypeBuilder = skipNavigationBuilder.Metadata.ForeignKey?.DeclaringEntityType.Builder; diff --git a/src/EFCore/Metadata/Conventions/KeylessEntityTypeAttributeConvention.cs b/src/EFCore/Metadata/Conventions/KeylessEntityTypeAttributeConvention.cs index c1e87a347d3..2779df69a8c 100644 --- a/src/EFCore/Metadata/Conventions/KeylessEntityTypeAttributeConvention.cs +++ b/src/EFCore/Metadata/Conventions/KeylessEntityTypeAttributeConvention.cs @@ -5,6 +5,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// diff --git a/src/EFCore/Metadata/Conventions/ManyToManyJoinEntityTypeConvention.cs b/src/EFCore/Metadata/Conventions/ManyToManyJoinEntityTypeConvention.cs index 0ea590aeb5b..09c96aefe0f 100644 --- a/src/EFCore/Metadata/Conventions/ManyToManyJoinEntityTypeConvention.cs +++ b/src/EFCore/Metadata/Conventions/ManyToManyJoinEntityTypeConvention.cs @@ -10,6 +10,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Internal; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// @@ -48,8 +50,8 @@ public virtual void ProcessSkipNavigationAdded( /// public virtual void ProcessSkipNavigationInverseChanged( IConventionSkipNavigationBuilder skipNavigationBuilder, - IConventionSkipNavigation inverse, - IConventionSkipNavigation oldInverse, + IConventionSkipNavigation? inverse, + IConventionSkipNavigation? oldInverse, IConventionContext context) { CreateJoinEntityType(skipNavigationBuilder); @@ -58,13 +60,14 @@ public virtual void ProcessSkipNavigationInverseChanged( /// public virtual void ProcessSkipNavigationForeignKeyChanged( IConventionSkipNavigationBuilder skipNavigationBuilder, - IConventionForeignKey foreignKey, - IConventionForeignKey oldForeignKey, + IConventionForeignKey? foreignKey, + IConventionForeignKey? oldForeignKey, IConventionContext context) { var joinEntityType = oldForeignKey?.DeclaringEntityType; var navigation = skipNavigationBuilder.Metadata; - if (joinEntityType?.Builder != null + if (joinEntityType is not null + && joinEntityType.IsInModel && navigation.IsCollection && navigation.ForeignKey?.DeclaringEntityType != joinEntityType) { @@ -79,7 +82,8 @@ public virtual void ProcessSkipNavigationRemoved( IConventionContext context) { var joinEntityType = navigation.ForeignKey?.DeclaringEntityType; - if (joinEntityType?.Builder != null + if (joinEntityType is not null + && joinEntityType.IsInModel && navigation.IsCollection) { ((InternalModelBuilder)joinEntityType.Model.Builder).RemoveImplicitJoinEntity((EntityType)joinEntityType); @@ -127,7 +131,7 @@ private void CreateJoinEntityType(IConventionSkipNavigationBuilder skipNavigatio } var joinEntityTypeBuilder = model.Builder.SharedTypeEntity( - joinEntityTypeName, Model.DefaultPropertyBagType, ConfigurationSource.Convention); + joinEntityTypeName, Model.DefaultPropertyBagType, ConfigurationSource.Convention)!; var leftForeignKey = CreateSkipNavigationForeignKey(skipNavigation, joinEntityTypeBuilder); if (leftForeignKey == null) @@ -147,7 +151,7 @@ private void CreateJoinEntityType(IConventionSkipNavigationBuilder skipNavigatio inverseSkipNavigation.Builder.HasForeignKey(rightForeignKey, ConfigurationSource.Convention); } - private static ForeignKey CreateSkipNavigationForeignKey( + private static ForeignKey? CreateSkipNavigationForeignKey( SkipNavigation skipNavigation, InternalEntityTypeBuilder joinEntityTypeBuilder) => joinEntityTypeBuilder @@ -155,8 +159,8 @@ private static ForeignKey CreateSkipNavigationForeignKey( skipNavigation.DeclaringEntityType, ConfigurationSource.Convention, required: true, - skipNavigation.Inverse.Name) - .IsUnique(false, ConfigurationSource.Convention) + skipNavigation.Inverse!.Name)! + .IsUnique(false, ConfigurationSource.Convention)! .Metadata; } } diff --git a/src/EFCore/Metadata/Conventions/MaxLengthAttributeConvention.cs b/src/EFCore/Metadata/Conventions/MaxLengthAttributeConvention.cs index 887d0a01deb..d6db3b0f9be 100644 --- a/src/EFCore/Metadata/Conventions/MaxLengthAttributeConvention.cs +++ b/src/EFCore/Metadata/Conventions/MaxLengthAttributeConvention.cs @@ -7,6 +7,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// diff --git a/src/EFCore/Metadata/Conventions/ModelCleanupConvention.cs b/src/EFCore/Metadata/Conventions/ModelCleanupConvention.cs index e70b9ee815f..c7add5f5668 100644 --- a/src/EFCore/Metadata/Conventions/ModelCleanupConvention.cs +++ b/src/EFCore/Metadata/Conventions/ModelCleanupConvention.cs @@ -9,6 +9,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Internal; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// @@ -113,13 +115,13 @@ public override IEnumerable GetOutgoingNeighbors(IConvent => from.GetForeignKeys().Where(fk => fk.DependentToPrincipal != null).Select(fk => fk.PrincipalEntityType) .Union( from.GetReferencingForeignKeys().Where(fk => fk.PrincipalToDependent != null).Select(fk => fk.DeclaringEntityType)) - .Union(from.GetSkipNavigations().Where(sn => sn.ForeignKey != null).Select(sn => sn.ForeignKey.DeclaringEntityType)) + .Union(from.GetSkipNavigations().Where(sn => sn.ForeignKey != null).Select(sn => sn.ForeignKey!.DeclaringEntityType)) .Union(from.GetSkipNavigations().Where(sn => sn.TargetEntityType != null).Select(sn => sn.TargetEntityType)); public override IEnumerable GetIncomingNeighbors(IConventionEntityType to) => to.GetForeignKeys().Where(fk => fk.PrincipalToDependent != null).Select(fk => fk.PrincipalEntityType) .Union(to.GetReferencingForeignKeys().Where(fk => fk.DependentToPrincipal != null).Select(fk => fk.DeclaringEntityType)) - .Union(to.GetSkipNavigations().Where(sn => sn.ForeignKey != null).Select(sn => sn.ForeignKey.DeclaringEntityType)) + .Union(to.GetSkipNavigations().Where(sn => sn.ForeignKey != null).Select(sn => sn.ForeignKey!.DeclaringEntityType)) .Union(to.GetSkipNavigations().Where(sn => sn.TargetEntityType != null).Select(sn => sn.TargetEntityType)); public override void Clear() diff --git a/src/EFCore/Metadata/Conventions/NavigationAttributeConventionBase.cs b/src/EFCore/Metadata/Conventions/NavigationAttributeConventionBase.cs index 819651a9d7d..6dd1aeb8fca 100644 --- a/src/EFCore/Metadata/Conventions/NavigationAttributeConventionBase.cs +++ b/src/EFCore/Metadata/Conventions/NavigationAttributeConventionBase.cs @@ -12,6 +12,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Internal; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// @@ -73,7 +75,7 @@ public virtual void ProcessEntityTypeAdded( public virtual void ProcessEntityTypeIgnored( IConventionModelBuilder modelBuilder, string name, - Type type, + Type? type, IConventionContext context) { if (type == null) @@ -151,8 +153,8 @@ public virtual void ProcessEntityTypeRemoved( /// public virtual void ProcessEntityTypeBaseTypeChanged( IConventionEntityTypeBuilder entityTypeBuilder, - IConventionEntityType newBaseType, - IConventionEntityType oldBaseType, + IConventionEntityType? newBaseType, + IConventionEntityType? oldBaseType, IConventionContext context) { var entityType = entityTypeBuilder.Metadata; @@ -183,10 +185,10 @@ public virtual void ProcessEntityTypeBaseTypeChanged( } } - private List<(PropertyInfo, Type)> GetNavigationsWithAttribute(IConventionEntityType entityType) + private List<(PropertyInfo, Type)>? GetNavigationsWithAttribute(IConventionEntityType entityType) { var navigations = new List<(PropertyInfo, Type)>(); - foreach (var navigationPropertyInfo in entityType.GetRuntimeProperties().Values) + foreach (var navigationPropertyInfo in entityType.GetRuntimeProperties()!.Values) { var targetClrType = FindCandidateNavigationWithAttributePropertyType(navigationPropertyInfo); if (targetClrType == null) @@ -289,7 +291,7 @@ public virtual void ProcessEntityTypeMemberIgnored( } } - private Type FindCandidateNavigationWithAttributePropertyType([NotNull] PropertyInfo propertyInfo) + private Type? FindCandidateNavigationWithAttributePropertyType([NotNull] PropertyInfo propertyInfo) { var targetClrType = Dependencies.MemberClassifier.FindCandidateNavigationPropertyType(propertyInfo); return targetClrType == null @@ -326,7 +328,7 @@ protected static IEnumerable GetAttributes( private static IEnumerable GetAttributes( [NotNull] IConventionEntityType entityType, - [NotNull] MemberInfo memberInfo) + [CanBeNull] MemberInfo? memberInfo) where TCustomAttribute : Attribute { if (memberInfo == null) @@ -403,8 +405,8 @@ public virtual void ProcessEntityTypeRemoved( /// Additional information associated with convention execution. public virtual void ProcessEntityTypeBaseTypeChanged( [NotNull] IConventionEntityTypeBuilder entityTypeBuilder, - [CanBeNull] IConventionEntityType newBaseType, - [CanBeNull] IConventionEntityType oldBaseType, + [CanBeNull] IConventionEntityType? newBaseType, + [CanBeNull] IConventionEntityType? oldBaseType, [NotNull] MemberInfo navigationMemberInfo, [NotNull] Type targetClrType, [NotNull] TAttribute attribute, @@ -460,8 +462,8 @@ public virtual void ProcessEntityTypeMemberIgnored( /// Additional information associated with convention execution. public virtual void ProcessForeignKeyPrincipalEndChanged( [NotNull] IConventionForeignKeyBuilder relationshipBuilder, - [CanBeNull] IEnumerable dependentToPrincipalAttributes, - [CanBeNull] IEnumerable principalToDependentAttributes, + [CanBeNull] IEnumerable? dependentToPrincipalAttributes, + [CanBeNull] IEnumerable? principalToDependentAttributes, [NotNull] IConventionContext context) => throw new NotSupportedException(); } diff --git a/src/EFCore/Metadata/Conventions/NavigationBackingFieldAttributeConvention.cs b/src/EFCore/Metadata/Conventions/NavigationBackingFieldAttributeConvention.cs index 1968c82fbf4..1f3c1d719bd 100644 --- a/src/EFCore/Metadata/Conventions/NavigationBackingFieldAttributeConvention.cs +++ b/src/EFCore/Metadata/Conventions/NavigationBackingFieldAttributeConvention.cs @@ -5,6 +5,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// diff --git a/src/EFCore/Metadata/Conventions/NavigationEagerLoadingConvention.cs b/src/EFCore/Metadata/Conventions/NavigationEagerLoadingConvention.cs index 96fd5c657c0..de2ef152bec 100644 --- a/src/EFCore/Metadata/Conventions/NavigationEagerLoadingConvention.cs +++ b/src/EFCore/Metadata/Conventions/NavigationEagerLoadingConvention.cs @@ -5,6 +5,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// diff --git a/src/EFCore/Metadata/Conventions/NonNullableConventionBase.cs b/src/EFCore/Metadata/Conventions/NonNullableConventionBase.cs index 4e588dd0bca..b24b1a254a1 100644 --- a/src/EFCore/Metadata/Conventions/NonNullableConventionBase.cs +++ b/src/EFCore/Metadata/Conventions/NonNullableConventionBase.cs @@ -10,6 +10,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure; using CA = System.Diagnostics.CodeAnalysis; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// @@ -153,10 +155,10 @@ public virtual void ProcessModelFinalizing( private sealed class NonNullabilityConventionState { - public Type NullableAttrType; - public Type NullableContextAttrType; - public FieldInfo NullableFlagsFieldInfo; - public FieldInfo NullableContextFlagFieldInfo; + public Type? NullableAttrType; + public Type? NullableContextAttrType; + public FieldInfo? NullableFlagsFieldInfo; + public FieldInfo? NullableContextFlagFieldInfo; public Dictionary TypeCache { get; } = new(); } } diff --git a/src/EFCore/Metadata/Conventions/NonNullableNavigationConvention.cs b/src/EFCore/Metadata/Conventions/NonNullableNavigationConvention.cs index 6bc1249b3f1..c7f0e95e96c 100644 --- a/src/EFCore/Metadata/Conventions/NonNullableNavigationConvention.cs +++ b/src/EFCore/Metadata/Conventions/NonNullableNavigationConvention.cs @@ -8,6 +8,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Internal; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// diff --git a/src/EFCore/Metadata/Conventions/NonNullableReferencePropertyConvention.cs b/src/EFCore/Metadata/Conventions/NonNullableReferencePropertyConvention.cs index f0f15ebbab0..293a80a90cf 100644 --- a/src/EFCore/Metadata/Conventions/NonNullableReferencePropertyConvention.cs +++ b/src/EFCore/Metadata/Conventions/NonNullableReferencePropertyConvention.cs @@ -7,6 +7,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata.Internal; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// @@ -57,8 +59,8 @@ public virtual void ProcessPropertyAdded( /// Additional information associated with convention execution. public virtual void ProcessPropertyFieldChanged( IConventionPropertyBuilder propertyBuilder, - FieldInfo newFieldInfo, - FieldInfo oldFieldInfo, + FieldInfo? newFieldInfo, + FieldInfo? oldFieldInfo, IConventionContext context) { Process(propertyBuilder); diff --git a/src/EFCore/Metadata/Conventions/NotMappedEntityTypeAttributeConvention.cs b/src/EFCore/Metadata/Conventions/NotMappedEntityTypeAttributeConvention.cs index 2982a2f2f8d..51c4650a085 100644 --- a/src/EFCore/Metadata/Conventions/NotMappedEntityTypeAttributeConvention.cs +++ b/src/EFCore/Metadata/Conventions/NotMappedEntityTypeAttributeConvention.cs @@ -6,6 +6,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// diff --git a/src/EFCore/Metadata/Conventions/NotMappedMemberAttributeConvention.cs b/src/EFCore/Metadata/Conventions/NotMappedMemberAttributeConvention.cs index d69e8e20851..7d85b6dd6ae 100644 --- a/src/EFCore/Metadata/Conventions/NotMappedMemberAttributeConvention.cs +++ b/src/EFCore/Metadata/Conventions/NotMappedMemberAttributeConvention.cs @@ -11,6 +11,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Internal; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// @@ -44,8 +46,8 @@ public virtual void ProcessEntityTypeAdded( Check.NotNull(entityTypeBuilder, nameof(entityTypeBuilder)); var entityType = entityTypeBuilder.Metadata; - var members = entityType.GetRuntimeProperties().Values.Cast() - .Concat(entityType.GetRuntimeFields().Values); + var members = entityType.GetRuntimeProperties()!.Values.Cast() + .Concat(entityType.GetRuntimeFields()!.Values); foreach (var member in members) { diff --git a/src/EFCore/Metadata/Conventions/OwnedEntityTypeAttributeConvention.cs b/src/EFCore/Metadata/Conventions/OwnedEntityTypeAttributeConvention.cs index 3a53539fc5d..4aca8e2cdb7 100644 --- a/src/EFCore/Metadata/Conventions/OwnedEntityTypeAttributeConvention.cs +++ b/src/EFCore/Metadata/Conventions/OwnedEntityTypeAttributeConvention.cs @@ -5,6 +5,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// diff --git a/src/EFCore/Metadata/Conventions/OwnedTypesConvention.cs b/src/EFCore/Metadata/Conventions/OwnedTypesConvention.cs index e7e909da58e..0c9a5eeffbd 100644 --- a/src/EFCore/Metadata/Conventions/OwnedTypesConvention.cs +++ b/src/EFCore/Metadata/Conventions/OwnedTypesConvention.cs @@ -6,6 +6,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// diff --git a/src/EFCore/Metadata/Conventions/PropertyAttributeConventionBase.cs b/src/EFCore/Metadata/Conventions/PropertyAttributeConventionBase.cs index d27d1488745..056cc7067a3 100644 --- a/src/EFCore/Metadata/Conventions/PropertyAttributeConventionBase.cs +++ b/src/EFCore/Metadata/Conventions/PropertyAttributeConventionBase.cs @@ -10,6 +10,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Internal; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// @@ -62,8 +64,8 @@ public virtual void ProcessPropertyAdded( /// Additional information associated with convention execution. public virtual void ProcessPropertyFieldChanged( IConventionPropertyBuilder propertyBuilder, - FieldInfo newFieldInfo, - FieldInfo oldFieldInfo, + FieldInfo? newFieldInfo, + FieldInfo? oldFieldInfo, IConventionContext context) { if (newFieldInfo != null diff --git a/src/EFCore/Metadata/Conventions/PropertyDiscoveryConvention.cs b/src/EFCore/Metadata/Conventions/PropertyDiscoveryConvention.cs index 673f525bd58..76daf11b263 100644 --- a/src/EFCore/Metadata/Conventions/PropertyDiscoveryConvention.cs +++ b/src/EFCore/Metadata/Conventions/PropertyDiscoveryConvention.cs @@ -7,6 +7,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata.Internal; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// @@ -49,8 +51,8 @@ public virtual void ProcessEntityTypeAdded( /// Additional information associated with convention execution. public virtual void ProcessEntityTypeBaseTypeChanged( IConventionEntityTypeBuilder entityTypeBuilder, - IConventionEntityType newBaseType, - IConventionEntityType oldBaseType, + IConventionEntityType? newBaseType, + IConventionEntityType? oldBaseType, IConventionContext context) { if ((newBaseType == null @@ -63,7 +65,7 @@ public virtual void ProcessEntityTypeBaseTypeChanged( private void Process(IConventionEntityTypeBuilder entityTypeBuilder) { - foreach (var propertyInfo in entityTypeBuilder.Metadata.GetRuntimeProperties().Values) + foreach (var propertyInfo in entityTypeBuilder.Metadata.GetRuntimeProperties()!.Values) { if (IsCandidatePrimitiveProperty(propertyInfo)) { diff --git a/src/EFCore/Metadata/Conventions/QueryFilterRewritingConvention.cs b/src/EFCore/Metadata/Conventions/QueryFilterRewritingConvention.cs index 795d6c7356c..970932ab64f 100644 --- a/src/EFCore/Metadata/Conventions/QueryFilterRewritingConvention.cs +++ b/src/EFCore/Metadata/Conventions/QueryFilterRewritingConvention.cs @@ -9,6 +9,8 @@ using Microsoft.EntityFrameworkCore.Query; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// @@ -59,7 +61,7 @@ public virtual void ProcessModelFinalizing( protected class DbSetAccessRewritingExpressionVisitor : ExpressionVisitor { private readonly Type _contextType; - private IModel _model; + private IModel? _model; /// /// Creates a new instance of . @@ -94,7 +96,7 @@ protected override Expression VisitMember(MemberExpression memberExpression) && memberExpression.Type.GetGenericTypeDefinition() == typeof(DbSet<>) && _model != null) { - return new QueryRootExpression(FindEntityType(memberExpression.Type)); + return new QueryRootExpression(FindEntityType(memberExpression.Type)!); } return base.VisitMember(memberExpression); @@ -112,14 +114,14 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp && methodCallExpression.Type.GetGenericTypeDefinition() == typeof(DbSet<>) && _model != null) { - return new QueryRootExpression(FindEntityType(methodCallExpression.Type)); + return new QueryRootExpression(FindEntityType(methodCallExpression.Type)!); } return base.VisitMethodCall(methodCallExpression); } - private IEntityType FindEntityType(Type dbSetType) - => _model.FindRuntimeEntityType(dbSetType.GetGenericArguments()[0]); + private IEntityType? FindEntityType(Type dbSetType) + => _model!.FindRuntimeEntityType(dbSetType.GetGenericArguments()[0]); } } } diff --git a/src/EFCore/Metadata/Conventions/RelationshipDiscoveryConvention.cs b/src/EFCore/Metadata/Conventions/RelationshipDiscoveryConvention.cs index 42d6812fbd7..e3cbaa922db 100644 --- a/src/EFCore/Metadata/Conventions/RelationshipDiscoveryConvention.cs +++ b/src/EFCore/Metadata/Conventions/RelationshipDiscoveryConvention.cs @@ -13,6 +13,9 @@ using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata.Internal; +using Microsoft.EntityFrameworkCore.Utilities; + +#nullable enable namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { @@ -85,7 +88,7 @@ private IReadOnlyList FindRelationshipCandidates(IConvent continue; } - IConventionEntityTypeBuilder candidateTargetEntityTypeBuilder = ((InternalEntityTypeBuilder)entityTypeBuilder) + IConventionEntityTypeBuilder? candidateTargetEntityTypeBuilder = ((InternalEntityTypeBuilder)entityTypeBuilder) .GetTargetEntityTypeBuilder(targetClrType, navigationPropertyInfo, ConfigurationSource.Convention); if (candidateTargetEntityTypeBuilder == null) @@ -99,12 +102,12 @@ private IReadOnlyList FindRelationshipCandidates(IConvent continue; } - if (entityType.Builder == null) + if (!entityType.IsInModel) { foreach (var relationshipCandidate in relationshipCandidates.Values) { var targetType = relationshipCandidate.TargetTypeBuilder.Metadata; - if (targetType.Builder != null + if (targetType.IsInModel && IsImplicitlyCreatedUnusedSharedType(targetType)) { targetType.Builder.ModelBuilder.HasNoEntityType(targetType); @@ -183,7 +186,7 @@ private IReadOnlyList FindRelationshipCandidates(IConvent var candidates = new List(); foreach (var relationshipCandidate in relationshipCandidates.Values) { - if (relationshipCandidate.TargetTypeBuilder.Metadata.Builder != null) + if (relationshipCandidate.TargetTypeBuilder.Metadata.IsInModel) { candidates.Add(relationshipCandidate); continue; @@ -197,7 +200,7 @@ private IReadOnlyList FindRelationshipCandidates(IConvent // The entity type might have been converted to a weak entity type var actualTargetEntityTypeBuilder = ((InternalEntityTypeBuilder)entityTypeBuilder).GetTargetEntityTypeBuilder( - relationshipCandidate.TargetTypeBuilder.Metadata.ClrType, + relationshipCandidate.TargetTypeBuilder.Metadata.ClrType!, relationshipCandidate.NavigationProperties.Single(), ConfigurationSource.Convention); @@ -262,7 +265,7 @@ private static IReadOnlyList RemoveIncompatibleWithExisti break; } - PropertyInfo compatibleInverse = null; + PropertyInfo? compatibleInverse = null; foreach (var inverseProperty in relationshipCandidate.InverseProperties) { if (IsCompatibleInverse( @@ -388,7 +391,7 @@ private static bool IsCompatibleInverse( } var otherEntityType = existingInverse.TargetEntityType; - if (!entityType.ClrType + if (!entityType.ClrType! .IsAssignableFrom(otherEntityType.ClrType)) { return false; @@ -571,13 +574,13 @@ private void CreateRelationships( { Dependencies.Logger.MultipleNavigationProperties( relationshipCandidate.NavigationProperties.Count == 0 - ? new[] { new Tuple(null, targetEntityType.ClrType) } + ? new[] { new Tuple(null, targetEntityType.ClrType) } : relationshipCandidate.NavigationProperties.Select( - n => new Tuple(n, entityType.ClrType)), + n => new Tuple(n, entityType.ClrType)), relationshipCandidate.InverseProperties.Count == 0 - ? new[] { new Tuple(null, targetEntityType.ClrType) } + ? new[] { new Tuple(null, targetEntityType.ClrType) } : relationshipCandidate.InverseProperties.Select( - n => new Tuple(n, targetEntityType.ClrType))); + n => new Tuple(n, targetEntityType.ClrType))); } foreach (var navigationProperty in relationshipCandidate.NavigationProperties.ToList()) @@ -606,7 +609,7 @@ private void CreateRelationships( foreach (var navigation in relationshipCandidate.NavigationProperties) { - if (targetEntityType.Builder == null + if (!targetEntityType.IsInModel && !targetEntityType.Model.IsOwned(targetEntityType.ClrType)) { continue; @@ -688,7 +691,7 @@ private void CreateRelationships( { foreach (var inverse in relationshipCandidate.InverseProperties) { - if (targetEntityType.Builder == null) + if (!targetEntityType.IsInModel) { continue; } @@ -727,7 +730,7 @@ private void RemoveNavigation( .HasNoRelationship(existingNavigation.ForeignKey) == null && existingNavigation.ForeignKey.Builder.HasNavigation( - (string)null, existingNavigation.IsOnDependent) + (string?)null, existingNavigation.IsOnDependent) == null) { // Navigations of higher configuration source are not ambiguous @@ -745,7 +748,7 @@ private void RemoveNavigation( // Navigations of higher configuration source are not ambiguous toRemoveFrom.Remove(navigationProperty); } - else if (inverse?.Builder != null) + else if (inverse?.IsInModel == true) { inverse.DeclaringEntityType.Builder.HasNoSkipNavigation(inverse); } @@ -762,14 +765,13 @@ public virtual void ProcessEntityTypeAdded( /// public virtual void ProcessEntityTypeBaseTypeChanged( IConventionEntityTypeBuilder entityTypeBuilder, - IConventionEntityType newBaseType, - IConventionEntityType oldBaseType, + IConventionEntityType? newBaseType, + IConventionEntityType? oldBaseType, IConventionContext context) { - var oldBaseTypeBuilder = oldBaseType?.Builder; - if (oldBaseTypeBuilder != null) + if (oldBaseType?.IsInModel == true) { - DiscoverRelationships(oldBaseTypeBuilder, context); + DiscoverRelationships(oldBaseType.Builder, context); } var entityType = entityTypeBuilder.Metadata; @@ -802,10 +804,9 @@ private void ApplyOnRelatedEntityTypes(IConventionEntityType entityType, IConven foreach (var relatedEntityType in relatedEntityTypes) { - var relatedEntityTypeBuilder = relatedEntityType.Builder; - if (relatedEntityTypeBuilder != null) + if (relatedEntityType.IsInModel) { - DiscoverRelationships(relatedEntityTypeBuilder, context); + DiscoverRelationships(relatedEntityType.Builder, context); } } } @@ -815,14 +816,14 @@ public virtual void ProcessNavigationRemoved( IConventionEntityTypeBuilder sourceEntityTypeBuilder, IConventionEntityTypeBuilder targetEntityTypeBuilder, string navigationName, - MemberInfo memberInfo, + MemberInfo? memberInfo, IConventionContext context) { - if ((targetEntityTypeBuilder.Metadata.Builder != null + if ((targetEntityTypeBuilder.Metadata.IsInModel || !sourceEntityTypeBuilder.ModelBuilder.IsIgnored(targetEntityTypeBuilder.Metadata.Name)) && IsCandidateNavigationProperty(sourceEntityTypeBuilder, navigationName, memberInfo)) { - Process(sourceEntityTypeBuilder.Metadata, navigationName, memberInfo, context); + Process(sourceEntityTypeBuilder.Metadata, navigationName, memberInfo!, context); } } @@ -847,9 +848,9 @@ private void Process( [ContractAnnotation("memberInfo:null => false")] private static bool IsCandidateNavigationProperty( - IConventionEntityTypeBuilder sourceEntityTypeBuilder, + IConventionEntityTypeBuilder? sourceEntityTypeBuilder, string navigationName, - MemberInfo memberInfo) + MemberInfo? memberInfo) => memberInfo != null && sourceEntityTypeBuilder?.IsIgnored(navigationName) == false && sourceEntityTypeBuilder.Metadata.FindProperty(navigationName) == null @@ -862,7 +863,7 @@ private static bool IsCandidateNavigationProperty( public virtual void ProcessEntityTypeIgnored( IConventionModelBuilder modelBuilder, string name, - Type type, + Type? type, IConventionContext context) { if (type == null) @@ -957,7 +958,7 @@ public virtual void ProcessNavigationAdded( } } - if (navigationBuilder.Metadata.Builder == null) + if (!navigationBuilder.Metadata.IsInModel) { context.StopProcessing(); } @@ -969,7 +970,7 @@ public virtual void ProcessForeignKeyOwnershipChanged( IConventionContext context) => DiscoverRelationships(relationshipBuilder.Metadata.DeclaringEntityType.Builder, context); - private Type FindCandidateNavigationPropertyType([NotNull] PropertyInfo propertyInfo) + private Type? FindCandidateNavigationPropertyType([NotNull] PropertyInfo propertyInfo) => Dependencies.MemberClassifier.FindCandidateNavigationPropertyType(propertyInfo); private ImmutableSortedDictionary GetNavigationCandidates(IConventionEntityType entityType) @@ -981,7 +982,7 @@ private ImmutableSortedDictionary GetNavigationCandidates(IC } var dictionaryBuilder = ImmutableSortedDictionary.CreateBuilder(MemberInfoNameComparer.Instance); - foreach (var propertyInfo in entityType.GetRuntimeProperties().Values.OrderBy(p => p.Name)) + foreach (var propertyInfo in entityType.GetRuntimeProperties()!.Values.OrderBy(p => p.Name)) { var targetType = FindCandidateNavigationPropertyType(propertyInfo); if (targetType != null) @@ -1006,7 +1007,7 @@ private static bool IsImplicitlyCreatedUnusedSharedType(IConventionEntityType en && !entityType.GetForeignKeys().Any() && !entityType.GetReferencingForeignKeys().Any(); - private static bool IsAmbiguous(IConventionEntityType entityType, MemberInfo navigationProperty) + private static bool IsAmbiguous(IConventionEntityType? entityType, MemberInfo navigationProperty) { while (entityType != null) { @@ -1022,7 +1023,7 @@ private static bool IsAmbiguous(IConventionEntityType entityType, MemberInfo nav return false; } - private static bool HasAmbiguousNavigationsTo(IConventionEntityType sourceEntityType, Type targetClrType) + private static bool HasAmbiguousNavigationsTo(IConventionEntityType? sourceEntityType, Type targetClrType) { while (sourceEntityType != null) { @@ -1040,7 +1041,7 @@ private static bool HasAmbiguousNavigationsTo(IConventionEntityType sourceEntity private static bool HasDeclaredAmbiguousNavigationsTo(IConventionEntityType sourceEntityType, Type targetClrType) => GetAmbiguousNavigations(sourceEntityType)?.ContainsValue(targetClrType) == true; - private static ImmutableSortedDictionary GetAmbiguousNavigations(IConventionEntityType entityType) + private static ImmutableSortedDictionary? GetAmbiguousNavigations(IConventionEntityType entityType) => entityType.FindAnnotation(CoreAnnotationNames.AmbiguousNavigations)?.Value as ImmutableSortedDictionary; @@ -1107,8 +1108,25 @@ private MemberInfoNameComparer() { } - public int Compare(MemberInfo x, MemberInfo y) - => StringComparer.Ordinal.Compare(x.Name, y.Name); + public int Compare(MemberInfo? x, MemberInfo? y) + { + if (ReferenceEquals(x, y)) + { + return 0; + } + + if (x is null) + { + return -1; + } + + if (y is null) + { + return 1; + } + + return StringComparer.Ordinal.Compare(x.Name, y.Name); + } } [DebuggerDisplay("{DebuggerDisplay(),nq}")] diff --git a/src/EFCore/Metadata/Conventions/RequiredNavigationAttributeConvention.cs b/src/EFCore/Metadata/Conventions/RequiredNavigationAttributeConvention.cs index 37c95f5fda7..8d05bfc21e3 100644 --- a/src/EFCore/Metadata/Conventions/RequiredNavigationAttributeConvention.cs +++ b/src/EFCore/Metadata/Conventions/RequiredNavigationAttributeConvention.cs @@ -9,6 +9,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// @@ -39,21 +41,21 @@ public override void ProcessNavigationAdded( /// public override void ProcessForeignKeyPrincipalEndChanged( IConventionForeignKeyBuilder relationshipBuilder, - IEnumerable dependentToPrincipalAttributes, - IEnumerable principalToDependentAttributes, + IEnumerable? dependentToPrincipalAttributes, + IEnumerable? principalToDependentAttributes, IConventionContext context) { var fk = relationshipBuilder.Metadata; if (dependentToPrincipalAttributes != null && dependentToPrincipalAttributes.Any()) { - ProcessNavigation(fk.DependentToPrincipal.Builder); + ProcessNavigation(fk.DependentToPrincipal!.Builder); } if (principalToDependentAttributes != null && principalToDependentAttributes.Any()) { - ProcessNavigation(fk.PrincipalToDependent.Builder); + ProcessNavigation(fk.PrincipalToDependent!.Builder); } context.StopProcessingIfChanged(relationshipBuilder.Metadata.Builder); diff --git a/src/EFCore/Metadata/Conventions/RequiredPropertyAttributeConvention.cs b/src/EFCore/Metadata/Conventions/RequiredPropertyAttributeConvention.cs index c736093b691..3d0f1135b2f 100644 --- a/src/EFCore/Metadata/Conventions/RequiredPropertyAttributeConvention.cs +++ b/src/EFCore/Metadata/Conventions/RequiredPropertyAttributeConvention.cs @@ -7,6 +7,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// diff --git a/src/EFCore/Metadata/Conventions/ServicePropertyDiscoveryConvention.cs b/src/EFCore/Metadata/Conventions/ServicePropertyDiscoveryConvention.cs index 6b7bb0c08ae..3d83f171aa5 100644 --- a/src/EFCore/Metadata/Conventions/ServicePropertyDiscoveryConvention.cs +++ b/src/EFCore/Metadata/Conventions/ServicePropertyDiscoveryConvention.cs @@ -13,6 +13,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Internal; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// @@ -57,8 +59,8 @@ public virtual void ProcessEntityTypeAdded( /// Additional information associated with convention execution. public virtual void ProcessEntityTypeBaseTypeChanged( IConventionEntityTypeBuilder entityTypeBuilder, - IConventionEntityType newBaseType, - IConventionEntityType oldBaseType, + IConventionEntityType? newBaseType, + IConventionEntityType? oldBaseType, IConventionContext context) { if (entityTypeBuilder.Metadata.BaseType == newBaseType) @@ -70,7 +72,7 @@ public virtual void ProcessEntityTypeBaseTypeChanged( private void Process(IConventionEntityTypeBuilder entityTypeBuilder) { var entityType = entityTypeBuilder.Metadata; - var candidates = entityType.GetRuntimeProperties().Values; + var candidates = entityType.GetRuntimeProperties()!.Values; foreach (var propertyInfo in candidates) { @@ -110,7 +112,7 @@ private void Process(IConventionEntityTypeBuilder entityTypeBuilder) } AddDuplicateServiceProperty(entityTypeBuilder, propertyInfo); - AddDuplicateServiceProperty(entityTypeBuilder, otherServicePropertySameType.GetIdentifyingMemberInfo()); + AddDuplicateServiceProperty(entityTypeBuilder, otherServicePropertySameType.GetIdentifyingMemberInfo()!); return; } @@ -151,7 +153,7 @@ public virtual void ProcessEntityTypeMemberIgnored( var otherMember = duplicateServiceProperties.First(); var otherName = otherMember.GetSimpleMemberName(); - var factory = Dependencies.ParameterBindingFactories.FindFactory(type, otherName); + var factory = Dependencies.ParameterBindingFactories.FindFactory(type, otherName)!; entityType.Builder.ServiceProperty(otherMember)?.HasParameterBinding( (ServiceParameterBinding)factory.Bind(entityType, type, otherName)); duplicateMap.Remove(type); @@ -212,13 +214,13 @@ private static void AddDuplicateServiceProperty(IConventionEntityTypeBuilder ent SetDuplicateServiceProperties(entityTypeBuilder, duplicateMap); } - private static Dictionary> GetDuplicateServiceProperties(IConventionEntityType entityType) + private static Dictionary>? GetDuplicateServiceProperties(IConventionEntityType entityType) => entityType.FindAnnotation(CoreAnnotationNames.DuplicateServiceProperties)?.Value as Dictionary>; private static void SetDuplicateServiceProperties( IConventionEntityTypeBuilder entityTypeBuilder, - Dictionary> duplicateServiceProperties) + Dictionary>? duplicateServiceProperties) => entityTypeBuilder.HasAnnotation(CoreAnnotationNames.DuplicateServiceProperties, duplicateServiceProperties); } } diff --git a/src/EFCore/Metadata/Conventions/StringLengthAttributeConvention.cs b/src/EFCore/Metadata/Conventions/StringLengthAttributeConvention.cs index 673c38174ab..3b35a6ee939 100644 --- a/src/EFCore/Metadata/Conventions/StringLengthAttributeConvention.cs +++ b/src/EFCore/Metadata/Conventions/StringLengthAttributeConvention.cs @@ -7,6 +7,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// diff --git a/src/EFCore/Metadata/Conventions/TimestampAttributeConvention.cs b/src/EFCore/Metadata/Conventions/TimestampAttributeConvention.cs index 5f723a54911..54a70b4c867 100644 --- a/src/EFCore/Metadata/Conventions/TimestampAttributeConvention.cs +++ b/src/EFCore/Metadata/Conventions/TimestampAttributeConvention.cs @@ -7,6 +7,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// diff --git a/src/EFCore/Metadata/Conventions/TypeMappingConvention.cs b/src/EFCore/Metadata/Conventions/TypeMappingConvention.cs index 72fe09679ce..b5a6c990c40 100644 --- a/src/EFCore/Metadata/Conventions/TypeMappingConvention.cs +++ b/src/EFCore/Metadata/Conventions/TypeMappingConvention.cs @@ -6,6 +6,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// diff --git a/src/EFCore/Metadata/Conventions/UnicodeAttributeConvention.cs b/src/EFCore/Metadata/Conventions/UnicodeAttributeConvention.cs index 80c34b9d849..6c66b97c63a 100644 --- a/src/EFCore/Metadata/Conventions/UnicodeAttributeConvention.cs +++ b/src/EFCore/Metadata/Conventions/UnicodeAttributeConvention.cs @@ -6,6 +6,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// diff --git a/src/EFCore/Metadata/Conventions/ValidatingConvention.cs b/src/EFCore/Metadata/Conventions/ValidatingConvention.cs index d0ee4c78a3b..2ab764b0735 100644 --- a/src/EFCore/Metadata/Conventions/ValidatingConvention.cs +++ b/src/EFCore/Metadata/Conventions/ValidatingConvention.cs @@ -4,6 +4,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// diff --git a/src/EFCore/Metadata/Conventions/ValueGenerationConvention.cs b/src/EFCore/Metadata/Conventions/ValueGenerationConvention.cs index db2b9b6382e..69e262f1fb2 100644 --- a/src/EFCore/Metadata/Conventions/ValueGenerationConvention.cs +++ b/src/EFCore/Metadata/Conventions/ValueGenerationConvention.cs @@ -8,6 +8,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { /// @@ -87,7 +89,7 @@ public virtual void ProcessForeignKeyPropertiesChanged( { OnForeignKeyRemoved(oldDependentProperties); - if (relationshipBuilder.Metadata.Builder != null + if (relationshipBuilder.Metadata.IsInModel && !foreignKey.IsBaseLinking()) { foreach (var property in foreignKey.Properties) @@ -105,7 +107,10 @@ private void OnForeignKeyRemoved(IReadOnlyList foreignKeyPr var pk = property.FindContainingPrimaryKey(); if (pk == null) { - property.Builder?.ValueGenerated(GetValueGenerated(property)); + if (property.IsInModel) + { + property.Builder.ValueGenerated(GetValueGenerated(property)); + } } else { @@ -126,19 +131,22 @@ private void OnForeignKeyRemoved(IReadOnlyList foreignKeyPr /// Additional information associated with convention execution. public virtual void ProcessEntityTypePrimaryKeyChanged( IConventionEntityTypeBuilder entityTypeBuilder, - IConventionKey newPrimaryKey, - IConventionKey previousPrimaryKey, + IConventionKey? newPrimaryKey, + IConventionKey? previousPrimaryKey, IConventionContext context) { if (previousPrimaryKey != null) { foreach (var property in previousPrimaryKey.Properties) { - property.Builder?.ValueGenerated(ValueGenerated.Never); + if (property.IsInModel) + { + property.Builder.ValueGenerated(ValueGenerated.Never); + } } } - if (newPrimaryKey?.Builder != null) + if (newPrimaryKey?.IsInModel == true) { foreach (var property in newPrimaryKey.Properties) { @@ -156,8 +164,8 @@ public virtual void ProcessEntityTypePrimaryKeyChanged( /// Additional information associated with convention execution. public virtual void ProcessEntityTypeBaseTypeChanged( IConventionEntityTypeBuilder entityTypeBuilder, - IConventionEntityType newBaseType, - IConventionEntityType oldBaseType, + IConventionEntityType? newBaseType, + IConventionEntityType? oldBaseType, IConventionContext context) { if (entityTypeBuilder.Metadata.BaseType != newBaseType) @@ -191,13 +199,11 @@ public virtual void ProcessEntityTypeBaseTypeChanged( ? ValueGenerated.OnAdd : (ValueGenerated?)null; - private static bool ShouldHaveGeneratedProperty(IKey key) - { - var onOwnedType = key?.DeclaringEntityType.IsOwned(); - return key != null - && (onOwnedType.Value && key.Properties.Count(p => !p.IsForeignKey()) == 1 - || !onOwnedType.Value && key.Properties.Count == 1); - } + private static bool ShouldHaveGeneratedProperty(IKey? key) + => key != null + && key.DeclaringEntityType.IsOwned() is var onOwnedType + && (onOwnedType && key.Properties.Count(p => !p.IsForeignKey()) == 1 + || !onOwnedType && key.Properties.Count == 1); /// /// Indicates whether the specified property can have the value generated by the store or by a non-temporary value generator diff --git a/src/EFCore/Metadata/IClrPropertyGetter.cs b/src/EFCore/Metadata/IClrPropertyGetter.cs index a825e4063f8..6c4bdd72e4b 100644 --- a/src/EFCore/Metadata/IClrPropertyGetter.cs +++ b/src/EFCore/Metadata/IClrPropertyGetter.cs @@ -18,7 +18,7 @@ public interface IClrPropertyGetter /// /// The entity instance. /// The property value. - object GetClrValue([NotNull] object entity); + object? GetClrValue([NotNull] object entity); /// /// Checks whether or not the property is set to the CLR default for its type. diff --git a/src/EFCore/Metadata/IConstructorBindingFactory.cs b/src/EFCore/Metadata/IConstructorBindingFactory.cs index 18edb00d9c3..d6a70ac3fd1 100644 --- a/src/EFCore/Metadata/IConstructorBindingFactory.cs +++ b/src/EFCore/Metadata/IConstructorBindingFactory.cs @@ -5,6 +5,7 @@ using System.Reflection; using JetBrains.Annotations; using Microsoft.Extensions.DependencyInjection; +using CA = System.Diagnostics.CodeAnalysis; #nullable enable @@ -35,8 +36,8 @@ public interface IConstructorBindingFactory bool TryBindConstructor( [NotNull] IConventionEntityType entityType, [NotNull] ConstructorInfo constructor, - [CanBeNull] out InstantiationBinding? binding, - [CanBeNull] out IEnumerable? unboundParameters); + [CanBeNull, CA.NotNullWhen(true)] out InstantiationBinding? binding, + [CanBeNull, CA.NotNullWhen(false)] out IEnumerable? unboundParameters); /// /// Attempts to create a for the given and @@ -50,7 +51,7 @@ bool TryBindConstructor( bool TryBindConstructor( [NotNull] IMutableEntityType entityType, [NotNull] ConstructorInfo constructor, - [CanBeNull] out InstantiationBinding? binding, - [CanBeNull] out IEnumerable? unboundParameters); + [CanBeNull, CA.NotNullWhen(true)] out InstantiationBinding? binding, + [CanBeNull, CA.NotNullWhen(false)] out IEnumerable? unboundParameters); } } diff --git a/src/EFCore/Metadata/IConventionAnnotatable.cs b/src/EFCore/Metadata/IConventionAnnotatable.cs index 8f62a86a894..7d9bf1853a0 100644 --- a/src/EFCore/Metadata/IConventionAnnotatable.cs +++ b/src/EFCore/Metadata/IConventionAnnotatable.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using System.Collections.Generic; using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Infrastructure; @@ -25,7 +26,13 @@ public interface IConventionAnnotatable : IAnnotatable /// /// Gets the builder that can be used to configure this object. /// - IConventionAnnotatableBuilder? Builder { get; } + /// If the object has been removed from the model. + IConventionAnnotatableBuilder Builder { get; } + + /// + /// Indicates whether this object is in a model, i.e. hasn't been removed from one. + /// + bool IsInModel { get; } /// /// Gets all annotations on the current object. diff --git a/src/EFCore/Metadata/IConventionEntityType.cs b/src/EFCore/Metadata/IConventionEntityType.cs index f61d67b9969..e9ec3de6160 100644 --- a/src/EFCore/Metadata/IConventionEntityType.cs +++ b/src/EFCore/Metadata/IConventionEntityType.cs @@ -37,7 +37,8 @@ public interface IConventionEntityType : IEntityType, IConventionTypeBase /// /// Gets the builder that can be used to configure this entity type. /// - new IConventionEntityTypeBuilder? Builder { get; } + /// If the entity type has been removed from the model. + new IConventionEntityTypeBuilder Builder { get; } /// /// Gets the base type of this entity type. Returns if this is not a derived type in an inheritance hierarchy. @@ -62,7 +63,7 @@ public interface IConventionEntityType : IEntityType, IConventionTypeBase /// The base entity type. /// Indicates whether the configuration was specified using a data annotation. /// The new base type. - IConventionEntityType? SetBaseType([CanBeNull] IConventionEntityType entityType, bool fromDataAnnotation = false); + IConventionEntityType? SetBaseType([CanBeNull] IConventionEntityType? entityType, bool fromDataAnnotation = false); /// /// Sets the base type of this entity type. Returns if this is not a derived type in an inheritance hierarchy. @@ -70,7 +71,7 @@ public interface IConventionEntityType : IEntityType, IConventionTypeBase /// The base entity type. /// Indicates whether the configuration was specified using a data annotation. [Obsolete("Use SetBaseType")] - void HasBaseType([CanBeNull] IConventionEntityType entityType, bool fromDataAnnotation = false) + void HasBaseType([CanBeNull] IConventionEntityType? entityType, bool fromDataAnnotation = false) => SetBaseType(entityType, fromDataAnnotation); /// diff --git a/src/EFCore/Metadata/IConventionForeignKey.cs b/src/EFCore/Metadata/IConventionForeignKey.cs index d6b5240c84d..fb6ca4257b2 100644 --- a/src/EFCore/Metadata/IConventionForeignKey.cs +++ b/src/EFCore/Metadata/IConventionForeignKey.cs @@ -27,7 +27,8 @@ public interface IConventionForeignKey : IForeignKey, IConventionAnnotatable /// /// Gets the builder that can be used to configure this foreign key. /// - new IConventionForeignKeyBuilder? Builder { get; } + /// If the foreign key has been removed from the model. + new IConventionForeignKeyBuilder Builder { get; } /// /// Gets the foreign key properties in the dependent entity. diff --git a/src/EFCore/Metadata/IConventionIndex.cs b/src/EFCore/Metadata/IConventionIndex.cs index 0bfe30d8bc2..a5babbab0d7 100644 --- a/src/EFCore/Metadata/IConventionIndex.cs +++ b/src/EFCore/Metadata/IConventionIndex.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using System.Collections.Generic; using Microsoft.EntityFrameworkCore.Metadata.Builders; @@ -22,7 +23,8 @@ public interface IConventionIndex : IIndex, IConventionAnnotatable /// /// Gets the builder that can be used to configure this index. /// - new IConventionIndexBuilder? Builder { get; } + /// If the index has been removed from the model. + new IConventionIndexBuilder Builder { get; } /// /// Gets the properties that this index is defined on. diff --git a/src/EFCore/Metadata/IConventionKey.cs b/src/EFCore/Metadata/IConventionKey.cs index 84762589389..bd99d40e537 100644 --- a/src/EFCore/Metadata/IConventionKey.cs +++ b/src/EFCore/Metadata/IConventionKey.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using System.Collections.Generic; using Microsoft.EntityFrameworkCore.Metadata.Builders; @@ -22,7 +23,8 @@ public interface IConventionKey : IConventionAnnotatable, IKey /// /// Gets the builder that can be used to configure this key. /// - new IConventionKeyBuilder? Builder { get; } + /// If the index has been removed from the model. + new IConventionKeyBuilder Builder { get; } /// /// Gets the properties that make up the key. diff --git a/src/EFCore/Metadata/IConventionNavigation.cs b/src/EFCore/Metadata/IConventionNavigation.cs index 8a1e657753d..d759ba0587c 100644 --- a/src/EFCore/Metadata/IConventionNavigation.cs +++ b/src/EFCore/Metadata/IConventionNavigation.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using System.Diagnostics; using System.Reflection; using JetBrains.Annotations; @@ -24,7 +25,8 @@ public interface IConventionNavigation : INavigation, IConventionNavigationBase /// /// Gets the builder that can be used to configure this navigation. /// - new IConventionNavigationBuilder? Builder { get; } + /// If the property has been removed from the model. + new IConventionNavigationBuilder Builder { get; } /// /// Gets the type that this navigation property belongs to. diff --git a/src/EFCore/Metadata/IConventionProperty.cs b/src/EFCore/Metadata/IConventionProperty.cs index b8dffb5af87..6ad6c5e3753 100644 --- a/src/EFCore/Metadata/IConventionProperty.cs +++ b/src/EFCore/Metadata/IConventionProperty.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using Microsoft.EntityFrameworkCore.Metadata.Builders; #nullable enable @@ -21,7 +22,8 @@ public interface IConventionProperty : IProperty, IConventionPropertyBase /// /// Gets the builder that can be used to configure this property. /// - new IConventionPropertyBuilder? Builder { get; } + /// If the property has been removed from the model. + new IConventionPropertyBuilder Builder { get; } /// /// Gets the type that this property belongs to. diff --git a/src/EFCore/Metadata/IConventionServiceProperty.cs b/src/EFCore/Metadata/IConventionServiceProperty.cs index d7276f59da8..18d839d004a 100644 --- a/src/EFCore/Metadata/IConventionServiceProperty.cs +++ b/src/EFCore/Metadata/IConventionServiceProperty.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Metadata.Builders; @@ -23,7 +24,8 @@ public interface IConventionServiceProperty : IServiceProperty, IConventionPrope /// /// Gets the builder that can be used to configure this service property. /// - new IConventionServicePropertyBuilder? Builder { get; } + /// If the service property has been removed from the model. + new IConventionServicePropertyBuilder Builder { get; } /// /// Gets the type that this property belongs to. diff --git a/src/EFCore/Metadata/IConventionSkipNavigation.cs b/src/EFCore/Metadata/IConventionSkipNavigation.cs index 6bc69004340..09166e8f67d 100644 --- a/src/EFCore/Metadata/IConventionSkipNavigation.cs +++ b/src/EFCore/Metadata/IConventionSkipNavigation.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using System.Diagnostics; using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Metadata.Builders; @@ -24,7 +25,8 @@ public interface IConventionSkipNavigation : ISkipNavigation, IConventionNavigat /// /// Gets the builder that can be used to configure this property. /// - new IConventionSkipNavigationBuilder? Builder { get; } + /// If the skip navigation has been removed from the model. + new IConventionSkipNavigationBuilder Builder { get; } /// /// Gets the type that this navigation property belongs to. @@ -38,6 +40,7 @@ public interface IConventionSkipNavigation : ISkipNavigation, IConventionNavigat /// /// Gets the entity type that this navigation property will hold an instance(s) of. /// + // TODO-NULLABLE: I can see conventions testing this for null, but in SkipNavigation that doesn't seem possible... new IConventionEntityType TargetEntityType { [DebuggerStepThrough] diff --git a/src/EFCore/Metadata/IConventionTypeBase.cs b/src/EFCore/Metadata/IConventionTypeBase.cs index 82157d24ffe..1aa7923328c 100644 --- a/src/EFCore/Metadata/IConventionTypeBase.cs +++ b/src/EFCore/Metadata/IConventionTypeBase.cs @@ -31,7 +31,7 @@ public interface IConventionTypeBase : ITypeBase, IConventionAnnotatable /// The name of the member to be ignored. /// Indicates whether the configuration was specified using a data annotation. /// The ignored member name. - string AddIgnored([NotNull] string memberName, bool fromDataAnnotation = false); + string? AddIgnored([NotNull] string memberName, bool fromDataAnnotation = false); /// /// Removes the ignored member name. diff --git a/src/EFCore/Metadata/IMutableProperty.cs b/src/EFCore/Metadata/IMutableProperty.cs index 30824f80cf3..b92295b75dd 100644 --- a/src/EFCore/Metadata/IMutableProperty.cs +++ b/src/EFCore/Metadata/IMutableProperty.cs @@ -1,6 +1,8 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata { /// diff --git a/src/EFCore/Metadata/IMutableTypeBase.cs b/src/EFCore/Metadata/IMutableTypeBase.cs index 26b0936338c..e1a422d3bbe 100644 --- a/src/EFCore/Metadata/IMutableTypeBase.cs +++ b/src/EFCore/Metadata/IMutableTypeBase.cs @@ -30,7 +30,7 @@ public interface IMutableTypeBase : ITypeBase, IMutableAnnotatable /// /// The name of the member to be ignored. /// The name of the ignored member. - string AddIgnored([NotNull] string memberName); + string? AddIgnored([NotNull] string memberName); /// /// Removes the ignored member name. diff --git a/src/EFCore/Metadata/IParameterBindingFactories.cs b/src/EFCore/Metadata/IParameterBindingFactories.cs index 96f4f7afec8..1564d35af64 100644 --- a/src/EFCore/Metadata/IParameterBindingFactories.cs +++ b/src/EFCore/Metadata/IParameterBindingFactories.cs @@ -28,7 +28,7 @@ public interface IParameterBindingFactories /// /// The parameter type. /// The parameter name. - /// The found factory, or null if none could be found. - IParameterBindingFactory FindFactory([NotNull] Type parameterType, [NotNull] string parameterName); + /// The found factory, or if none could be found. + IParameterBindingFactory? FindFactory([NotNull] Type parameterType, [NotNull] string parameterName); } } diff --git a/src/EFCore/Metadata/IPropertyParameterBindingFactory.cs b/src/EFCore/Metadata/IPropertyParameterBindingFactory.cs index a0041fc6765..8aa71017fe2 100644 --- a/src/EFCore/Metadata/IPropertyParameterBindingFactory.cs +++ b/src/EFCore/Metadata/IPropertyParameterBindingFactory.cs @@ -29,7 +29,7 @@ public interface IPropertyParameterBindingFactory /// The parameter name. /// The parameter type. /// The parameter binding, or if none was found. - ParameterBinding FindParameter( + ParameterBinding? FindParameter( [NotNull] IEntityType entityType, [NotNull] Type parameterType, [NotNull] string parameterName); diff --git a/src/EFCore/Metadata/Internal/ClrAccessorFactory.cs b/src/EFCore/Metadata/Internal/ClrAccessorFactory.cs index 6a10b835b07..74db0b3f5ff 100644 --- a/src/EFCore/Metadata/Internal/ClrAccessorFactory.cs +++ b/src/EFCore/Metadata/Internal/ClrAccessorFactory.cs @@ -6,6 +6,8 @@ using System.Reflection; using JetBrains.Annotations; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Internal { /// @@ -43,7 +45,7 @@ public virtual TAccessor Create([NotNull] MemberInfo memberInfo) /// 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. /// - protected virtual TAccessor Create([NotNull] MemberInfo memberInfo, [CanBeNull] IPropertyBase propertyBase) + protected virtual TAccessor Create([NotNull] MemberInfo memberInfo, [CanBeNull] IPropertyBase? propertyBase) { var boundMethod = propertyBase != null ? _genericCreate.MakeGenericMethod( @@ -51,14 +53,14 @@ protected virtual TAccessor Create([NotNull] MemberInfo memberInfo, [CanBeNull] propertyBase.ClrType, propertyBase.ClrType.UnwrapNullableType()) : _genericCreate.MakeGenericMethod( - memberInfo.DeclaringType, + memberInfo.DeclaringType!, memberInfo.GetMemberType(), memberInfo.GetMemberType().UnwrapNullableType()); try { return (TAccessor)boundMethod.Invoke( - this, new object[] { memberInfo, propertyBase }); + this, new object?[] { memberInfo, propertyBase })!; } catch (TargetInvocationException e) when (e.InnerException != null) { @@ -73,8 +75,8 @@ protected virtual TAccessor Create([NotNull] MemberInfo memberInfo, [CanBeNull] /// doing so can result in application failures when updating to a new Entity Framework Core release. /// protected abstract TAccessor CreateGeneric( - [CanBeNull] MemberInfo memberInfo, - [CanBeNull] IPropertyBase propertyBase) + [NotNull] MemberInfo memberInfo, + [CanBeNull] IPropertyBase? propertyBase) where TEntity : class; } } diff --git a/src/EFCore/Metadata/Internal/ClrCollectionAccessor.cs b/src/EFCore/Metadata/Internal/ClrCollectionAccessor.cs index 34f4e84b169..b5d36547b11 100644 --- a/src/EFCore/Metadata/Internal/ClrCollectionAccessor.cs +++ b/src/EFCore/Metadata/Internal/ClrCollectionAccessor.cs @@ -8,6 +8,8 @@ using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Infrastructure; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Internal { /// @@ -23,10 +25,10 @@ public class ClrICollectionAccessor : IClrCollec { private readonly string _propertyName; private readonly Func _getCollection; - private readonly Action _setCollection; - private readonly Action _setCollectionForMaterialization; - private readonly Func, TCollection> _createAndSetCollection; - private readonly Func _createCollection; + private readonly Action? _setCollection; + private readonly Action? _setCollectionForMaterialization; + private readonly Func, TCollection>? _createAndSetCollection; + private readonly Func? _createCollection; /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -46,10 +48,10 @@ public virtual Type CollectionType public ClrICollectionAccessor( [NotNull] string propertyName, [NotNull] Func getCollection, - [CanBeNull] Action setCollection, - [CanBeNull] Action setCollectionForMaterialization, - [CanBeNull] Func, TCollection> createAndSetCollection, - [CanBeNull] Func createCollection) + [CanBeNull] Action? setCollection, + [CanBeNull] Action? setCollectionForMaterialization, + [CanBeNull] Func, TCollection>? createAndSetCollection, + [CanBeNull] Func? createCollection) { _propertyName = propertyName; _getCollection = getCollection; @@ -134,7 +136,7 @@ private ICollection GetOrCreateCollection(object instance, bool forMat return collection; } - private ICollection GetCollection(object instance) + private ICollection? GetCollection(object instance) { var enumerable = _getCollection((TEntity)instance); var collection = enumerable as ICollection; @@ -205,7 +207,7 @@ public virtual bool Remove(object entity, object value) } } - private static bool Contains(ICollection collection, object value) + private static bool Contains(ICollection? collection, object value) { switch (collection) { diff --git a/src/EFCore/Metadata/Internal/ClrCollectionAccessorFactory.cs b/src/EFCore/Metadata/Internal/ClrCollectionAccessorFactory.cs index 7e9c340d77c..8ee499eb013 100644 --- a/src/EFCore/Metadata/Internal/ClrCollectionAccessorFactory.cs +++ b/src/EFCore/Metadata/Internal/ClrCollectionAccessorFactory.cs @@ -11,6 +11,8 @@ using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Internal; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Internal { /// @@ -22,25 +24,25 @@ namespace Microsoft.EntityFrameworkCore.Metadata.Internal public class ClrCollectionAccessorFactory { private static readonly MethodInfo _genericCreate - = typeof(ClrCollectionAccessorFactory).GetTypeInfo().GetDeclaredMethod(nameof(CreateGeneric)); + = typeof(ClrCollectionAccessorFactory).GetTypeInfo().GetDeclaredMethod(nameof(CreateGeneric))!; private static readonly MethodInfo _createAndSet - = typeof(ClrCollectionAccessorFactory).GetTypeInfo().GetDeclaredMethod(nameof(CreateAndSet)); + = typeof(ClrCollectionAccessorFactory).GetTypeInfo().GetDeclaredMethod(nameof(CreateAndSet))!; private static readonly MethodInfo _create - = typeof(ClrCollectionAccessorFactory).GetTypeInfo().GetDeclaredMethod(nameof(CreateCollection)); + = typeof(ClrCollectionAccessorFactory).GetTypeInfo().GetDeclaredMethod(nameof(CreateCollection))!; private static readonly MethodInfo _createAndSetHashSet - = typeof(ClrCollectionAccessorFactory).GetTypeInfo().GetDeclaredMethod(nameof(CreateAndSetHashSet)); + = typeof(ClrCollectionAccessorFactory).GetTypeInfo().GetDeclaredMethod(nameof(CreateAndSetHashSet))!; private static readonly MethodInfo _createHashSet - = typeof(ClrCollectionAccessorFactory).GetTypeInfo().GetDeclaredMethod(nameof(CreateHashSet)); + = typeof(ClrCollectionAccessorFactory).GetTypeInfo().GetDeclaredMethod(nameof(CreateHashSet))!; private static readonly MethodInfo _createAndSetObservableHashSet - = typeof(ClrCollectionAccessorFactory).GetTypeInfo().GetDeclaredMethod(nameof(CreateAndSetObservableHashSet)); + = typeof(ClrCollectionAccessorFactory).GetTypeInfo().GetDeclaredMethod(nameof(CreateAndSetObservableHashSet))!; private static readonly MethodInfo _createObservableHashSet - = typeof(ClrCollectionAccessorFactory).GetTypeInfo().GetDeclaredMethod(nameof(CreateObservableHashSet)); + = typeof(ClrCollectionAccessorFactory).GetTypeInfo().GetDeclaredMethod(nameof(CreateObservableHashSet))!; /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -48,10 +50,10 @@ private static readonly MethodInfo _createObservableHashSet /// 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. /// - public virtual IClrCollectionAccessor Create([NotNull] INavigationBase navigation) + public virtual IClrCollectionAccessor? Create([NotNull] INavigationBase navigation) => !navigation.IsCollection || navigation.IsShadowProperty() ? null : Create(navigation, navigation.TargetEntityType); - private IClrCollectionAccessor Create(IPropertyBase navigation, IEntityType targetType) + private IClrCollectionAccessor? Create(IPropertyBase navigation, IEntityType? targetType) { // ReSharper disable once SuspiciousTypeConversion.Global if (navigation is IClrCollectionAccessor accessor) @@ -88,22 +90,22 @@ private IClrCollectionAccessor Create(IPropertyBase navigation, IEntityType targ } var boundMethod = _genericCreate.MakeGenericMethod( - memberInfo.DeclaringType, propertyType, elementType); + memberInfo.DeclaringType!, propertyType, elementType); try { - return (IClrCollectionAccessor)boundMethod.Invoke( + return (IClrCollectionAccessor?)boundMethod.Invoke( null, new object[] { navigation }); } catch (TargetInvocationException invocationException) { - throw invocationException.InnerException; + throw invocationException.InnerException!; } MemberInfo GetMostDerivedMemberInfo() { - var propertyInfo = navigation.PropertyInfo; - var fieldInfo = navigation.FieldInfo; + var propertyInfo = navigation.PropertyInfo!; + var fieldInfo = navigation.FieldInfo!; return fieldInfo == null ? propertyInfo @@ -138,10 +140,10 @@ private static IClrCollectionAccessor CreateGeneric setterDelegate = null; - Action setterDelegateForMaterialization = null; - Func, TCollection> createAndSetDelegate = null; - Func createDelegate = null; + Action? setterDelegate = null; + Action? setterDelegateForMaterialization = null; + Func, TCollection>? createAndSetDelegate = null; + Func? createDelegate = null; if (memberInfoForWrite != null) { diff --git a/src/EFCore/Metadata/Internal/ClrPropertyGetter.cs b/src/EFCore/Metadata/Internal/ClrPropertyGetter.cs index 75d6565cb9a..e51598ff650 100644 --- a/src/EFCore/Metadata/Internal/ClrPropertyGetter.cs +++ b/src/EFCore/Metadata/Internal/ClrPropertyGetter.cs @@ -5,6 +5,8 @@ using System.Runtime.CompilerServices; using JetBrains.Annotations; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Internal { /// @@ -39,7 +41,7 @@ public ClrPropertyGetter([NotNull] Func getter, [NotNull] Func< /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public object GetClrValue(object entity) + public object? GetClrValue(object entity) => _getter((TEntity)entity); /// diff --git a/src/EFCore/Metadata/Internal/ClrPropertyGetterFactory.cs b/src/EFCore/Metadata/Internal/ClrPropertyGetterFactory.cs index 58c78e4cbbf..560dc2fd0a1 100644 --- a/src/EFCore/Metadata/Internal/ClrPropertyGetterFactory.cs +++ b/src/EFCore/Metadata/Internal/ClrPropertyGetterFactory.cs @@ -7,6 +7,8 @@ using System.Reflection; using Microsoft.EntityFrameworkCore.Internal; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Internal { /// @@ -34,12 +36,12 @@ public override IClrPropertyGetter Create(IPropertyBase property) /// protected override IClrPropertyGetter CreateGeneric( MemberInfo memberInfo, - IPropertyBase propertyBase) + IPropertyBase? propertyBase) { var entityParameter = Expression.Parameter(typeof(TEntity), "entity"); Expression readExpression; - if (memberInfo.DeclaringType.IsAssignableFrom(typeof(TEntity))) + if (memberInfo.DeclaringType!.IsAssignableFrom(typeof(TEntity))) { readExpression = PropertyBase.CreateMemberAccess(propertyBase, entityParameter, memberInfo); } diff --git a/src/EFCore/Metadata/Internal/ClrPropertyMaterializationSetterFactory.cs b/src/EFCore/Metadata/Internal/ClrPropertyMaterializationSetterFactory.cs index 9eab89c601b..f67568f21a5 100644 --- a/src/EFCore/Metadata/Internal/ClrPropertyMaterializationSetterFactory.cs +++ b/src/EFCore/Metadata/Internal/ClrPropertyMaterializationSetterFactory.cs @@ -1,6 +1,8 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Internal { /// diff --git a/src/EFCore/Metadata/Internal/ClrPropertySetter.cs b/src/EFCore/Metadata/Internal/ClrPropertySetter.cs index f23cf2ad46c..f67e02bf9ca 100644 --- a/src/EFCore/Metadata/Internal/ClrPropertySetter.cs +++ b/src/EFCore/Metadata/Internal/ClrPropertySetter.cs @@ -5,6 +5,8 @@ using System.Runtime.CompilerServices; using JetBrains.Annotations; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Internal { /// @@ -37,7 +39,7 @@ public ClrPropertySetter([NotNull] Action setter) /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void SetClrValue(object instance, object value) - => _setter((TEntity)instance, (TValue)value); + public void SetClrValue(object instance, object? value) + => _setter((TEntity)instance, (TValue?)value!); } } diff --git a/src/EFCore/Metadata/Internal/ClrPropertySetterFactory.cs b/src/EFCore/Metadata/Internal/ClrPropertySetterFactory.cs index e09ac49b7dc..7c18304593c 100644 --- a/src/EFCore/Metadata/Internal/ClrPropertySetterFactory.cs +++ b/src/EFCore/Metadata/Internal/ClrPropertySetterFactory.cs @@ -7,6 +7,8 @@ using System.Reflection; using Microsoft.EntityFrameworkCore.Infrastructure; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Internal { /// @@ -34,7 +36,7 @@ public override IClrPropertySetter Create(IPropertyBase property) /// protected override IClrPropertySetter CreateGeneric( MemberInfo memberInfo, - IPropertyBase propertyBase) + IPropertyBase? propertyBase) { var entityParameter = Expression.Parameter(typeof(TEntity), "entity"); var valueParameter = Expression.Parameter(typeof(TValue), "value"); @@ -44,7 +46,7 @@ protected override IClrPropertySetter CreateGeneric @@ -23,7 +25,7 @@ public class CollectionTypeFactory /// 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. /// - public virtual Type TryFindTypeToInstantiate( + public virtual Type? TryFindTypeToInstantiate( [NotNull] Type entityType, [NotNull] Type collectionType, bool requireFullNotifications) diff --git a/src/EFCore/Metadata/Internal/ConstructorBindingFactory.cs b/src/EFCore/Metadata/Internal/ConstructorBindingFactory.cs index 4c4143b88c3..a9b89856260 100644 --- a/src/EFCore/Metadata/Internal/ConstructorBindingFactory.cs +++ b/src/EFCore/Metadata/Internal/ConstructorBindingFactory.cs @@ -7,6 +7,9 @@ using System.Reflection; using JetBrains.Annotations; using Microsoft.Extensions.DependencyInjection; +using CA = System.Diagnostics.CodeAnalysis; + +#nullable enable namespace Microsoft.EntityFrameworkCore.Metadata.Internal { @@ -51,8 +54,8 @@ public ConstructorBindingFactory( public virtual bool TryBindConstructor( IMutableEntityType entityType, ConstructorInfo constructor, - out InstantiationBinding binding, - out IEnumerable unboundParameters) + [CA.NotNullWhen(true)] out InstantiationBinding? binding, + [CA.NotNullWhen(false)] out IEnumerable? unboundParameters) => TryBindConstructor( entityType, constructor, @@ -69,8 +72,8 @@ public virtual bool TryBindConstructor( public virtual bool TryBindConstructor( IConventionEntityType entityType, ConstructorInfo constructor, - out InstantiationBinding binding, - out IEnumerable unboundParameters) + [CA.NotNullWhen(true)] out InstantiationBinding? binding, + [CA.NotNullWhen(false)] out IEnumerable? unboundParameters) => TryBindConstructor( entityType, constructor, @@ -81,11 +84,11 @@ public virtual bool TryBindConstructor( private bool TryBindConstructor( IEntityType entityType, ConstructorInfo constructor, - Func bind, - out InstantiationBinding binding, - out IEnumerable unboundParameters) + Func bind, + [CA.NotNullWhen(true)] out InstantiationBinding? binding, + [CA.NotNullWhen(false)] out IEnumerable? unboundParameters) { - IEnumerable<(ParameterInfo Parameter, ParameterBinding Binding)> bindings + IEnumerable<(ParameterInfo Parameter, ParameterBinding? Binding)> bindings = constructor.GetParameters().Select( p => (p, string.IsNullOrEmpty(p.Name) ? null @@ -102,7 +105,7 @@ private bool TryBindConstructor( } unboundParameters = null; - binding = new ConstructorBinding(constructor, bindings.Select(b => b.Binding).ToList()); + binding = new ConstructorBinding(constructor, bindings.Select(b => b.Binding).ToList()!); return true; } diff --git a/src/EFCore/Metadata/Internal/ContextParameterBindingFactory.cs b/src/EFCore/Metadata/Internal/ContextParameterBindingFactory.cs index c3ebd9ec68f..1878edc1ffe 100644 --- a/src/EFCore/Metadata/Internal/ContextParameterBindingFactory.cs +++ b/src/EFCore/Metadata/Internal/ContextParameterBindingFactory.cs @@ -4,6 +4,8 @@ using System; using System.Linq; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Internal { /// diff --git a/src/EFCore/Metadata/Internal/EntityType.cs b/src/EFCore/Metadata/Internal/EntityType.cs index 82a6c99a557..95cac334c3a 100644 --- a/src/EFCore/Metadata/Internal/EntityType.cs +++ b/src/EFCore/Metadata/Internal/EntityType.cs @@ -60,6 +60,7 @@ private readonly SortedDictionary _serviceProperties private bool? _isKeyless; private EntityType? _baseType; private ChangeTrackingStrategy? _changeTrackingStrategy; + private InternalEntityTypeBuilder? _builder; private ConfigurationSource? _primaryKeyConfigurationSource; private ConfigurationSource? _isKeylessConfigurationSource; @@ -87,7 +88,7 @@ public EntityType([NotNull] string name, [NotNull] Model model, ConfigurationSou : base(name, Model.DefaultPropertyBagType, model, configurationSource) { _properties = new SortedDictionary(new PropertyNameComparer(this)); - Builder = new InternalEntityTypeBuilder(this, model.Builder); + _builder = new InternalEntityTypeBuilder(this, model.Builder); } /// @@ -112,7 +113,7 @@ public EntityType([NotNull] Type type, [NotNull] Model model, ConfigurationSourc } _properties = new SortedDictionary(new PropertyNameComparer(this)); - Builder = new InternalEntityTypeBuilder(this, model.Builder); + _builder = new InternalEntityTypeBuilder(this, model.Builder); } /// @@ -137,7 +138,7 @@ public EntityType([NotNull] string name, [NotNull] Type type, [NotNull] Model mo } _properties = new SortedDictionary(new PropertyNameComparer(this)); - Builder = new InternalEntityTypeBuilder(this, model.Builder); + _builder = new InternalEntityTypeBuilder(this, model.Builder); } /// @@ -146,14 +147,29 @@ public EntityType([NotNull] string name, [NotNull] Type type, [NotNull] Model mo /// 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. /// - public virtual InternalEntityTypeBuilder? Builder + public virtual InternalEntityTypeBuilder Builder { - get; - - [param: CanBeNull] - set; + [DebuggerStepThrough] get => _builder ?? throw new InvalidOperationException(CoreStrings.ObjectRemovedFromModel); } + /// + /// 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. + /// + public virtual bool IsInModel + => _builder is not null; + + /// + /// 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. + /// + public virtual void SetRemovedFromModel() + => _builder = null; + /// /// 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 @@ -247,7 +263,7 @@ public virtual void UpdateIsKeylessConfigurationSource(ConfigurationSource confi public virtual EntityType? SetBaseType([CanBeNull] EntityType? newBaseType, ConfigurationSource configurationSource) { EnsureReadonly(false); - Check.DebugAssert(Builder != null, "Builder is null"); + Check.DebugAssert(IsInModel, "The entity type has been removed from the model"); if (_baseType == newBaseType) { @@ -311,7 +327,7 @@ public virtual void UpdateIsKeylessConfigurationSource(ConfigurationSource confi UpdateBaseTypeConfigurationSource(configurationSource); newBaseType?.UpdateConfigurationSource(configurationSource); - return (EntityType)Model.ConventionDispatcher.OnEntityTypeBaseTypeChanged(Builder, newBaseType, originalBaseType); + return (EntityType?)Model.ConventionDispatcher.OnEntityTypeBaseTypeChanged(Builder, newBaseType, originalBaseType); } /// @@ -344,7 +360,7 @@ public virtual void OnTypeRemoved() } } - Builder = null; + _builder = null; _baseType?._directlyDerivedTypes.Remove(this); Model.ConventionDispatcher.OnEntityTypeRemoved(Model.Builder, this); @@ -466,7 +482,7 @@ public override string ToString() /// The annotation set. /// The old annotation. /// The annotation that was set. - protected override IConventionAnnotation OnAnnotationSet( + protected override IConventionAnnotation? OnAnnotationSet( string name, IConventionAnnotation? annotation, IConventionAnnotation? oldAnnotation) @@ -533,7 +549,7 @@ public virtual IEnumerable FindMembersInHierarchy([NotNull] string ConfigurationSource configurationSource) { EnsureReadonly(false); - Check.DebugAssert(Builder != null, "Builder is null"); + Check.DebugAssert(IsInModel, "The entity type has been removed from the model"); if (_baseType != null) { @@ -602,7 +618,7 @@ public virtual IEnumerable FindMembersInHierarchy([NotNull] string SetPrimaryKeyConfigurationSource(null); } - return (Key)Model.ConventionDispatcher.OnPrimaryKeyChanged(Builder, newKey, oldPrimaryKey); + return (Key?)Model.ConventionDispatcher.OnPrimaryKeyChanged(Builder, newKey, oldPrimaryKey); } /// @@ -718,7 +734,7 @@ private void UpdatePrimaryKeyConfigurationSource(ConfigurationSource configurati } if (FindProperty(property.Name) != property - || property.Builder == null) + || !property.IsInModel) { throw new InvalidOperationException(CoreStrings.KeyPropertiesWrongEntity(properties.Format(), this.DisplayName())); } @@ -831,7 +847,7 @@ public virtual IEnumerable GetDeclaredKeys() public virtual Key? RemoveKey([NotNull] Key key) { Check.NotNull(key, nameof(key)); - Check.DebugAssert(Builder != null, "Builder is null"); + Check.DebugAssert(IsInModel, "The entity type has been removed from the model"); EnsureReadonly(false); if (key.DeclaringEntityType != this) @@ -850,7 +866,7 @@ public virtual IEnumerable GetDeclaredKeys() var removed = _keys.Remove(key.Properties); Check.DebugAssert(removed, "removed is false"); - key.Builder = null; + key.SetRemovedFromModel(); foreach (var property in key.Properties) { @@ -864,7 +880,7 @@ public virtual IEnumerable GetDeclaredKeys() } } - return (Key)Model.ConventionDispatcher.OnKeyRemoved(Builder, key); + return (Key?)Model.ConventionDispatcher.OnKeyRemoved(Builder, key); } private void CheckKeyNotInUse(Key key) @@ -1279,7 +1295,7 @@ public virtual IEnumerable FindForeignKeysInHierarchy( public virtual ForeignKey? RemoveForeignKey([NotNull] ForeignKey foreignKey) { Check.NotNull(foreignKey, nameof(foreignKey)); - Check.DebugAssert(Builder != null, "Builder is null"); + Check.DebugAssert(IsInModel, "The entity type has been removed from the model"); EnsureReadonly(false); if (foreignKey.DeclaringEntityType != this) @@ -1316,11 +1332,11 @@ public virtual IEnumerable FindForeignKeysInHierarchy( OnForeignKeyUpdating(foreignKey); - foreignKey.Builder = null; + foreignKey.SetRemovedFromModel(); if (foreignKey.DependentToPrincipal != null) { - foreignKey.DependentToPrincipal.Builder = null; + foreignKey.DependentToPrincipal.SetRemovedFromModel(); Model.ConventionDispatcher.OnNavigationRemoved( Builder, foreignKey.PrincipalEntityType.Builder, @@ -1330,7 +1346,7 @@ public virtual IEnumerable FindForeignKeysInHierarchy( if (foreignKey.PrincipalToDependent != null) { - foreignKey.PrincipalToDependent.Builder = null; + foreignKey.PrincipalToDependent.SetRemovedFromModel(); Model.ConventionDispatcher.OnNavigationRemoved( foreignKey.PrincipalEntityType.Builder, Builder, @@ -1338,7 +1354,7 @@ public virtual IEnumerable FindForeignKeysInHierarchy( foreignKey.PrincipalToDependent.GetIdentifyingMemberInfo()); } - return (ForeignKey)Model.ConventionDispatcher.OnForeignKeyRemoved(Builder, foreignKey); + return (ForeignKey?)Model.ConventionDispatcher.OnForeignKeyRemoved(Builder, foreignKey); } /// @@ -1809,7 +1825,7 @@ public virtual IEnumerable FindSkipNavigationsInHierarchy([NotNu public virtual SkipNavigation? RemoveSkipNavigation([NotNull] SkipNavigation navigation) { Check.NotNull(navigation, nameof(navigation)); - Check.DebugAssert(Builder != null, "Builder is null"); + Check.DebugAssert(IsInModel, "The entity type has been removed from the model"); EnsureReadonly(false); if (navigation.DeclaringEntityType != this) @@ -1840,7 +1856,7 @@ public virtual IEnumerable FindSkipNavigationsInHierarchy([NotNu removed = navigation.TargetEntityType.DeclaredReferencingSkipNavigations!.Remove(navigation); Check.DebugAssert(removed, "removed is false"); - navigation.Builder = null; + navigation.SetRemovedFromModel(); return (SkipNavigation?)Model.ConventionDispatcher.OnSkipNavigationRemoved(Builder, navigation); } @@ -2002,7 +2018,7 @@ private void CheckIndexProperties(IReadOnlyList properties) } if (FindProperty(property.Name) != property - || property.Builder == null) + || !property.IsInModel) { throw new InvalidOperationException(CoreStrings.IndexPropertiesWrongEntity(properties.Format(), this.DisplayName())); } @@ -2191,7 +2207,7 @@ public virtual IEnumerable FindIndexesInHierarchy([NotNull] string name) public virtual Index? RemoveIndex([NotNull] Index index) { Check.NotNull(index, nameof(index)); - Check.DebugAssert(Builder != null, "Builder is null"); + Check.DebugAssert(IsInModel, "The entity type has been removed from the model"); EnsureReadonly(false); if (index.Name == null) @@ -2211,7 +2227,7 @@ public virtual IEnumerable FindIndexesInHierarchy([NotNull] string name) } } - index.Builder = null; + index.SetRemovedFromModel(); foreach (var property in index.Properties) { @@ -2318,7 +2334,7 @@ public virtual IEnumerable GetIndexes() { Check.NotNull(name, nameof(name)); Check.NotNull(propertyType, nameof(propertyType)); - Check.DebugAssert(Builder != null, "Builder is null"); + Check.DebugAssert(IsInModel, "The entity type has been removed from the model"); EnsureReadonly(false); var conflictingMember = FindMembersInHierarchy(name).FirstOrDefault(); @@ -2492,7 +2508,7 @@ public virtual IEnumerable FindPropertiesInHierarchy([NotNull] string public virtual Property? RemoveProperty([NotNull] Property property) { Check.NotNull(property, nameof(property)); - Check.DebugAssert(Builder != null, "Builder is null"); + Check.DebugAssert(IsInModel, "The entity type has been removed from the model"); EnsureReadonly(false); if (property.DeclaringEntityType != this) @@ -2509,7 +2525,7 @@ public virtual IEnumerable FindPropertiesInHierarchy([NotNull] string var removed = _properties.Remove(property.Name); Check.DebugAssert(removed, "removed is false"); - property.Builder = null; + property.SetRemovedFromModel(); return (Property?)Model.ConventionDispatcher.OnPropertyRemoved(Builder, property); } @@ -2801,7 +2817,7 @@ public virtual IEnumerable FindServicePropertiesInHierarchy([No public virtual ServiceProperty RemoveServiceProperty([NotNull] ServiceProperty property) { Check.NotNull(property, nameof(property)); - Check.DebugAssert(Builder != null, "Builder is null"); + Check.DebugAssert(IsInModel, "The entity type has been removed from the model"); EnsureReadonly(false); if (property.DeclaringEntityType != this) @@ -2816,7 +2832,7 @@ public virtual ServiceProperty RemoveServiceProperty([NotNull] ServiceProperty p var removed = _serviceProperties.Remove(property.Name); Check.DebugAssert(removed, "removed is false"); - property.Builder = null; + property.SetRemovedFromModel(); return property; } @@ -2866,7 +2882,7 @@ public virtual IEnumerable GetDeclaredServiceProperties() /// 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. /// - public override string OnTypeMemberIgnored(string name) + public override string? OnTypeMemberIgnored(string name) => Model.ConventionDispatcher.OnEntityTypeMemberIgnored(Builder, name); #endregion @@ -3245,7 +3261,7 @@ public virtual bool IsImplicitlyCreatedJoinEntityType /// 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. /// - IConventionEntityTypeBuilder? IConventionEntityType.Builder + IConventionEntityTypeBuilder IConventionEntityType.Builder { [DebuggerStepThrough] get => Builder; @@ -3257,7 +3273,7 @@ public virtual bool IsImplicitlyCreatedJoinEntityType /// 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. /// - IConventionAnnotatableBuilder? IConventionAnnotatable.Builder + IConventionAnnotatableBuilder IConventionAnnotatable.Builder { [DebuggerStepThrough] get => Builder; @@ -3353,9 +3369,9 @@ IConventionModel IConventionEntityType.Model /// 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. /// - IConventionEntityType? IConventionEntityType.SetBaseType(IConventionEntityType entityType, bool fromDataAnnotation) + IConventionEntityType? IConventionEntityType.SetBaseType(IConventionEntityType? entityType, bool fromDataAnnotation) => SetBaseType( - (EntityType)entityType, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); + (EntityType?)entityType, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to diff --git a/src/EFCore/Metadata/Internal/EntityTypeParameterBindingFactory.cs b/src/EFCore/Metadata/Internal/EntityTypeParameterBindingFactory.cs index 43c47c1b3a3..b0a5e464035 100644 --- a/src/EFCore/Metadata/Internal/EntityTypeParameterBindingFactory.cs +++ b/src/EFCore/Metadata/Internal/EntityTypeParameterBindingFactory.cs @@ -5,6 +5,8 @@ using System.Linq; using Microsoft.Extensions.DependencyInjection; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Internal { /// diff --git a/src/EFCore/Metadata/Internal/ForeignKey.cs b/src/EFCore/Metadata/Internal/ForeignKey.cs index 3e72a947db1..adc9da49e8f 100644 --- a/src/EFCore/Metadata/Internal/ForeignKey.cs +++ b/src/EFCore/Metadata/Internal/ForeignKey.cs @@ -31,6 +31,7 @@ public class ForeignKey : ConventionAnnotatable, IMutableForeignKey, IConvention private bool _isRequired; private bool? _isRequiredDependent; private bool? _isOwnership; + private InternalForeignKeyBuilder? _builder; private ConfigurationSource _configurationSource; private ConfigurationSource? _propertiesConfigurationSource; @@ -79,7 +80,7 @@ public ForeignKey( principalEntityType.DisplayName())); } - Builder = new InternalForeignKeyBuilder(this, dependentEntityType.Model.Builder); + _builder = new InternalForeignKeyBuilder(this, dependentEntityType.Model.Builder); } /// @@ -120,12 +121,9 @@ public ForeignKey( /// 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. /// - public virtual InternalForeignKeyBuilder? Builder + public virtual InternalForeignKeyBuilder Builder { - get; - - [param: CanBeNull] - set; + [DebuggerStepThrough] get => _builder ?? throw new InvalidOperationException(CoreStrings.ObjectRemovedFromModel); } /// @@ -134,7 +132,25 @@ public virtual InternalForeignKeyBuilder? Builder /// 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. /// - protected override bool IsReadonly => DeclaringEntityType.Model.ConventionDispatcher == null; + public virtual bool IsInModel + => _builder is not null; + + /// + /// 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. + /// + public virtual void SetRemovedFromModel() + => _builder = null; + + /// + /// 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. + /// + protected override bool IsReadonly => DeclaringEntityType.Model.IsModelReadonly; /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -184,11 +200,11 @@ public virtual void UpdateConfigurationSource(ConfigurationSource configurationS /// The annotation set. /// The old annotation. /// The annotation that was set. - protected override IConventionAnnotation OnAnnotationSet( + protected override IConventionAnnotation? OnAnnotationSet( string name, IConventionAnnotation? annotation, IConventionAnnotation? oldAnnotation) - => Builder!.ModelBuilder.Metadata.ConventionDispatcher.OnForeignKeyAnnotationChanged(Builder, name, annotation, oldAnnotation); + => Builder.ModelBuilder.Metadata.ConventionDispatcher.OnForeignKeyAnnotationChanged(Builder, name, annotation, oldAnnotation); /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -222,7 +238,7 @@ public virtual IReadOnlyList SetProperties( } return (IReadOnlyList)DeclaringEntityType.Model.ConventionDispatcher - .OnForeignKeyPropertiesChanged(Builder, oldProperties, oldPrincipalKey); + .OnForeignKeyPropertiesChanged(Builder, oldProperties, oldPrincipalKey)!; } /// @@ -444,7 +460,7 @@ public virtual void UpdatePrincipalToDependentConfigurationSource(ConfigurationS if (oldNavigation != null) { Check.DebugAssert(oldNavigation.Name != null, "oldNavigation.Name is null"); - oldNavigation.Builder = null; + oldNavigation.SetRemovedFromModel(); if (pointsToPrincipal) { DeclaringEntityType.RemoveNavigation(oldNavigation.Name); @@ -488,16 +504,16 @@ public virtual void UpdatePrincipalToDependentConfigurationSource(ConfigurationS if (pointsToPrincipal) { DeclaringEntityType.Model.ConventionDispatcher.OnNavigationRemoved( - DeclaringEntityType.Builder!, - PrincipalEntityType.Builder!, + DeclaringEntityType.Builder, + PrincipalEntityType.Builder, oldNavigation.Name, oldNavigation.GetIdentifyingMemberInfo()); } else { DeclaringEntityType.Model.ConventionDispatcher.OnNavigationRemoved( - PrincipalEntityType.Builder!, - DeclaringEntityType.Builder!, + PrincipalEntityType.Builder, + DeclaringEntityType.Builder, oldNavigation.Name, oldNavigation.GetIdentifyingMemberInfo()); } @@ -550,7 +566,7 @@ public virtual bool IsUnique { if (!Internal.Navigation.IsCompatible( PrincipalToDependent.Name, - PrincipalToDependent.GetIdentifyingMemberInfo(), + PrincipalToDependent.GetIdentifyingMemberInfo()!, PrincipalEntityType, DeclaringEntityType, !unique, @@ -769,7 +785,6 @@ public virtual void UpdateDeleteBehaviorConfigurationSource(ConfigurationSource /// 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. /// - [CA.MemberNotNullWhen(true, nameof(PrincipalToDependent))] public virtual bool IsOwnership { get => _isOwnership ?? DefaultIsOwnership; @@ -1126,7 +1141,7 @@ IReadOnlyList IConventionForeignKey.Properties /// 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. /// - IConventionForeignKeyBuilder? IConventionForeignKey.Builder + IConventionForeignKeyBuilder IConventionForeignKey.Builder { [DebuggerStepThrough] get => Builder; } @@ -1137,7 +1152,7 @@ IReadOnlyList IConventionForeignKey.Properties /// 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. /// - IConventionAnnotatableBuilder? IConventionAnnotatable.Builder + IConventionAnnotatableBuilder IConventionAnnotatable.Builder { [DebuggerStepThrough] get => Builder; } @@ -1241,7 +1256,7 @@ private void Validate( var actualProperty = declaringEntityType.FindProperty(property.Name); if (actualProperty?.DeclaringEntityType.IsAssignableFrom(property.DeclaringEntityType) != true - || property.Builder == null) + || !property.IsInModel) { throw new InvalidOperationException( CoreStrings.ForeignKeyPropertiesWrongEntity( diff --git a/src/EFCore/Metadata/Internal/IMemberClassifier.cs b/src/EFCore/Metadata/Internal/IMemberClassifier.cs index f15322eb21c..cafb905dfda 100644 --- a/src/EFCore/Metadata/Internal/IMemberClassifier.cs +++ b/src/EFCore/Metadata/Internal/IMemberClassifier.cs @@ -6,6 +6,8 @@ using JetBrains.Annotations; using Microsoft.Extensions.DependencyInjection; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Internal { /// @@ -29,6 +31,6 @@ public interface IMemberClassifier /// 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. /// - Type FindCandidateNavigationPropertyType([NotNull] MemberInfo memberInfo); + Type? FindCandidateNavigationPropertyType([NotNull] MemberInfo memberInfo); } } diff --git a/src/EFCore/Metadata/Internal/IReferenceRoot.cs b/src/EFCore/Metadata/Internal/IReferenceRoot.cs index 1fab0774807..001a59f6bc5 100644 --- a/src/EFCore/Metadata/Internal/IReferenceRoot.cs +++ b/src/EFCore/Metadata/Internal/IReferenceRoot.cs @@ -3,6 +3,8 @@ using JetBrains.Annotations; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Internal { /// diff --git a/src/EFCore/Metadata/Internal/Index.cs b/src/EFCore/Metadata/Internal/Index.cs index a83349d06a8..46bc0f02924 100644 --- a/src/EFCore/Metadata/Internal/Index.cs +++ b/src/EFCore/Metadata/Internal/Index.cs @@ -1,11 +1,13 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using System.Collections.Generic; using System.Diagnostics; using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.ChangeTracking; using Microsoft.EntityFrameworkCore.ChangeTracking.Internal; +using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Internal; using Microsoft.EntityFrameworkCore.Metadata.Builders; @@ -24,6 +26,7 @@ namespace Microsoft.EntityFrameworkCore.Metadata.Internal public class Index : ConventionAnnotatable, IMutableIndex, IConventionIndex { private bool? _isUnique; + private InternalIndexBuilder? _builder; private ConfigurationSource _configurationSource; private ConfigurationSource? _isUniqueConfigurationSource; @@ -50,7 +53,7 @@ public Index( DeclaringEntityType = declaringEntityType; _configurationSource = configurationSource; - Builder = new InternalIndexBuilder(this, declaringEntityType.Model.Builder); + _builder = new InternalIndexBuilder(this, declaringEntityType.Model.Builder); } /// @@ -101,12 +104,9 @@ public Index( /// 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. /// - public virtual InternalIndexBuilder? Builder + public virtual InternalIndexBuilder Builder { - [DebuggerStepThrough] get; - [DebuggerStepThrough] - [param: CanBeNull] - set; + [DebuggerStepThrough] get => _builder ?? throw new InvalidOperationException(CoreStrings.ObjectRemovedFromModel); } /// @@ -115,7 +115,25 @@ public virtual InternalIndexBuilder? Builder /// 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. /// - protected override bool IsReadonly => DeclaringEntityType.Model.ConventionDispatcher == null; + public virtual bool IsInModel + => _builder is not null; + + /// + /// 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. + /// + public virtual void SetRemovedFromModel() + => _builder = null; + + /// + /// 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. + /// + protected override bool IsReadonly => DeclaringEntityType.Model.IsModelReadonly; /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -197,11 +215,11 @@ private void UpdateIsUniqueConfigurationSource(ConfigurationSource configuration /// The annotation set. /// The old annotation. /// The annotation that was set. - protected override IConventionAnnotation OnAnnotationSet( + protected override IConventionAnnotation? OnAnnotationSet( string name, IConventionAnnotation? annotation, IConventionAnnotation? oldAnnotation) - => Builder!.ModelBuilder.Metadata.ConventionDispatcher.OnIndexAnnotationChanged(Builder, name, annotation, oldAnnotation); + => Builder.ModelBuilder.Metadata.ConventionDispatcher.OnIndexAnnotationChanged(Builder, name, annotation, oldAnnotation); /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -283,7 +301,7 @@ IMutableEntityType IMutableIndex.DeclaringEntityType /// 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. /// - IConventionIndexBuilder? IConventionIndex.Builder + IConventionIndexBuilder IConventionIndex.Builder { [DebuggerStepThrough] get => Builder; } @@ -294,7 +312,7 @@ IMutableEntityType IMutableIndex.DeclaringEntityType /// 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. /// - IConventionAnnotatableBuilder? IConventionAnnotatable.Builder + IConventionAnnotatableBuilder IConventionAnnotatable.Builder { [DebuggerStepThrough] get => Builder; } diff --git a/src/EFCore/Metadata/Internal/InternalEntityTypeBuilder.cs b/src/EFCore/Metadata/Internal/InternalEntityTypeBuilder.cs index 4d98940e73e..b6cacd9caa6 100644 --- a/src/EFCore/Metadata/Internal/InternalEntityTypeBuilder.cs +++ b/src/EFCore/Metadata/Internal/InternalEntityTypeBuilder.cs @@ -17,6 +17,8 @@ using Microsoft.EntityFrameworkCore.Utilities; using Microsoft.EntityFrameworkCore.ValueGeneration.Internal; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Internal { /// @@ -44,8 +46,8 @@ public InternalEntityTypeBuilder([NotNull] EntityType metadata, [NotNull] Intern /// 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. /// - public virtual InternalKeyBuilder PrimaryKey( - [CanBeNull] IReadOnlyList propertyNames, + public virtual InternalKeyBuilder? PrimaryKey( + [CanBeNull] IReadOnlyList? propertyNames, ConfigurationSource configurationSource) => PrimaryKey(GetOrCreateProperties(propertyNames, configurationSource, required: true), configurationSource); @@ -55,8 +57,8 @@ public virtual InternalKeyBuilder PrimaryKey( /// 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. /// - public virtual InternalKeyBuilder PrimaryKey( - [CanBeNull] IReadOnlyList clrMembers, + public virtual InternalKeyBuilder? PrimaryKey( + [CanBeNull] IReadOnlyList? clrMembers, ConfigurationSource configurationSource) => PrimaryKey(GetOrCreateProperties(clrMembers, configurationSource), configurationSource); @@ -66,8 +68,8 @@ public virtual InternalKeyBuilder PrimaryKey( /// 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. /// - public virtual InternalKeyBuilder PrimaryKey( - [CanBeNull] IReadOnlyList properties, + public virtual InternalKeyBuilder? PrimaryKey( + [CanBeNull] IReadOnlyList? properties, ConfigurationSource configurationSource) { if (!CanSetPrimaryKey(properties, configurationSource)) @@ -75,7 +77,7 @@ public virtual InternalKeyBuilder PrimaryKey( return null; } - InternalKeyBuilder keyBuilder = null; + InternalKeyBuilder? keyBuilder = null; if (properties == null) { Metadata.SetPrimaryKey(properties, configurationSource); @@ -87,7 +89,7 @@ public virtual InternalKeyBuilder PrimaryKey( && PropertyListComparer.Instance.Compare(previousPrimaryKey.Properties, properties) == 0) { previousPrimaryKey.UpdateConfigurationSource(configurationSource); - return Metadata.SetPrimaryKey(properties, configurationSource).Builder; + return Metadata.SetPrimaryKey(properties, configurationSource)!.Builder; } using (ModelBuilder.Metadata.DelayConventions()) @@ -117,7 +119,7 @@ public virtual InternalKeyBuilder PrimaryKey( } } - if (previousPrimaryKey?.Builder != null) + if (previousPrimaryKey?.IsInModel == true) { RemoveKeyIfUnused(previousPrimaryKey, configurationSource); } @@ -125,10 +127,10 @@ public virtual InternalKeyBuilder PrimaryKey( } // TODO: Use convention batch to get the updated builder, see #15898 - if (keyBuilder?.Metadata.Builder == null) + if (keyBuilder is null || !keyBuilder.Metadata.IsInModel) { properties = GetActualProperties(properties, null); - return properties == null ? null : Metadata.FindPrimaryKey(properties).Builder; + return properties == null ? null : Metadata.FindPrimaryKey(properties)!.Builder; } return keyBuilder; @@ -141,7 +143,7 @@ public virtual InternalKeyBuilder PrimaryKey( /// doing so can result in application failures when updating to a new Entity Framework Core release. /// public virtual bool CanSetPrimaryKey( - [CanBeNull] IReadOnlyList properties, + [CanBeNull] IReadOnlyList? properties, ConfigurationSource configurationSource) { var previousPrimaryKey = Metadata.FindPrimaryKey(); @@ -170,7 +172,7 @@ public virtual bool CanSetPrimaryKey( /// 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. /// - public virtual InternalKeyBuilder HasKey([NotNull] IReadOnlyList propertyNames, ConfigurationSource configurationSource) + public virtual InternalKeyBuilder? HasKey([NotNull] IReadOnlyList propertyNames, ConfigurationSource configurationSource) => HasKeyInternal(GetOrCreateProperties(propertyNames, configurationSource, required: true), configurationSource); /// @@ -179,7 +181,7 @@ public virtual InternalKeyBuilder HasKey([NotNull] IReadOnlyList propert /// 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. /// - public virtual InternalKeyBuilder HasKey([NotNull] IReadOnlyList clrMembers, ConfigurationSource configurationSource) + public virtual InternalKeyBuilder? HasKey([NotNull] IReadOnlyList clrMembers, ConfigurationSource configurationSource) => HasKeyInternal(GetOrCreateProperties(clrMembers, configurationSource), configurationSource); /// @@ -188,17 +190,17 @@ public virtual InternalKeyBuilder HasKey([NotNull] IReadOnlyList clr /// 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. /// - public virtual InternalKeyBuilder HasKey([NotNull] IReadOnlyList properties, ConfigurationSource? configurationSource) + public virtual InternalKeyBuilder? HasKey([NotNull] IReadOnlyList properties, ConfigurationSource? configurationSource) => HasKeyInternal(properties, configurationSource); - private InternalKeyBuilder HasKeyInternal(IReadOnlyList properties, ConfigurationSource? configurationSource) + private InternalKeyBuilder? HasKeyInternal(IReadOnlyList? properties, ConfigurationSource? configurationSource) { if (properties == null) { return null; } - var actualProperties = GetActualProperties(properties, configurationSource); + var actualProperties = GetActualProperties(properties, configurationSource)!; var key = Metadata.FindDeclaredKey(actualProperties); if (key == null) { @@ -243,7 +245,7 @@ private InternalKeyBuilder HasKeyInternal(IReadOnlyList properties, Co continue; } - foreignKey.Builder.HasForeignKey((IReadOnlyList)null, configurationSource.Value); + foreignKey.Builder.HasForeignKey((IReadOnlyList?)null, configurationSource.Value); } foreach (var actualProperty in actualProperties) @@ -251,10 +253,10 @@ private InternalKeyBuilder HasKeyInternal(IReadOnlyList properties, Co actualProperty.Builder.IsRequired(true, configurationSource.Value); } - key = Metadata.AddKey(actualProperties, configurationSource.Value); + key = Metadata.AddKey(actualProperties, configurationSource.Value)!; } - if (key.Builder == null) + if (!key.IsInModel) { key = Metadata.FindDeclaredKey(actualProperties); } @@ -265,7 +267,7 @@ private InternalKeyBuilder HasKeyInternal(IReadOnlyList properties, Co Metadata.SetIsKeyless(false, configurationSource.Value); } - return key?.Builder; + return key?.IsInModel == true ? key.Builder : null; } /// @@ -274,7 +276,7 @@ private InternalKeyBuilder HasKeyInternal(IReadOnlyList properties, Co /// 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. /// - public virtual InternalEntityTypeBuilder HasNoKey([NotNull] Key key, ConfigurationSource configurationSource) + public virtual InternalEntityTypeBuilder? HasNoKey([NotNull] Key key, ConfigurationSource configurationSource) { var currentConfigurationSource = key.GetConfigurationSource(); if (!configurationSource.Overrides(currentConfigurationSource)) @@ -301,7 +303,10 @@ public virtual InternalEntityTypeBuilder HasNoKey([NotNull] Key key, Configurati && !property.GetContainingForeignKeys().Any(fk => fk.IsRequired)) { // TODO: This should be handled by reference tracking, see #15898 - property.Builder?.IsRequired(null, configurationSource); + if (property.IsInModel) + { + property.Builder.IsRequired(null, configurationSource); + } } } } @@ -324,7 +329,7 @@ public virtual bool CanRemoveKey([NotNull] Key key, ConfigurationSource configur /// 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. /// - public static List<(InternalKeyBuilder, ConfigurationSource?)> DetachKeys([NotNull] IEnumerable keysToDetach) + public static List<(InternalKeyBuilder, ConfigurationSource?)>? DetachKeys([NotNull] IEnumerable keysToDetach) { var keysToDetachList = (keysToDetach as List) ?? keysToDetach.ToList(); if (keysToDetachList.Count == 0) @@ -369,7 +374,7 @@ private static (InternalKeyBuilder, ConfigurationSource?) DetachKey(Key keyToDet /// 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. /// - public virtual InternalEntityTypeBuilder HasNoKey(ConfigurationSource configurationSource) + public virtual InternalEntityTypeBuilder? HasNoKey(ConfigurationSource configurationSource) { if (Metadata.IsKeyless) { @@ -391,7 +396,7 @@ public virtual InternalEntityTypeBuilder HasNoKey(ConfigurationSource configurat foreach (var foreignKey in Metadata.GetForeignKeys()) { - foreignKey.HasPrincipalToDependent((string)null, configurationSource); + foreignKey.HasPrincipalToDependent((string?)null, configurationSource); } foreach (var key in Metadata.GetKeys().ToList()) @@ -427,8 +432,8 @@ public virtual bool CanRemoveKey(ConfigurationSource configurationSource) /// 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. /// - public virtual InternalPropertyBuilder Property( - [CanBeNull] Type propertyType, + public virtual InternalPropertyBuilder? Property( + [CanBeNull] Type? propertyType, [NotNull] string propertyName, ConfigurationSource? configurationSource) => Property(propertyType, propertyName, typeConfigurationSource: configurationSource, configurationSource: configurationSource); @@ -439,8 +444,8 @@ public virtual InternalPropertyBuilder Property( /// 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. /// - public virtual InternalPropertyBuilder Property( - [CanBeNull] Type propertyType, + public virtual InternalPropertyBuilder? Property( + [CanBeNull] Type? propertyType, [NotNull] string propertyName, ConfigurationSource? typeConfigurationSource, ConfigurationSource? configurationSource) @@ -455,7 +460,7 @@ public virtual InternalPropertyBuilder Property( /// 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. /// - public virtual InternalPropertyBuilder Property([NotNull] string propertyName, ConfigurationSource? configurationSource) + public virtual InternalPropertyBuilder? Property([NotNull] string propertyName, ConfigurationSource? configurationSource) => Property(propertyType: null, propertyName, memberInfo: null, typeConfigurationSource: null, configurationSource); /// @@ -464,7 +469,7 @@ public virtual InternalPropertyBuilder Property([NotNull] string propertyName, C /// 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. /// - public virtual InternalPropertyBuilder Property([NotNull] MemberInfo memberInfo, ConfigurationSource? configurationSource) + public virtual InternalPropertyBuilder? Property([NotNull] MemberInfo memberInfo, ConfigurationSource? configurationSource) => Property(memberInfo.GetMemberType(), memberInfo.GetSimpleMemberName(), memberInfo, configurationSource, configurationSource); /// @@ -473,8 +478,8 @@ public virtual InternalPropertyBuilder Property([NotNull] MemberInfo memberInfo, /// 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. /// - public virtual InternalPropertyBuilder IndexerProperty( - [CanBeNull] Type propertyType, + public virtual InternalPropertyBuilder? IndexerProperty( + [CanBeNull] Type? propertyType, [NotNull] string propertyName, ConfigurationSource? configurationSource) { @@ -488,15 +493,15 @@ public virtual InternalPropertyBuilder IndexerProperty( return Property(propertyType, propertyName, indexerPropertyInfo, configurationSource, configurationSource); } - private InternalPropertyBuilder Property( - [CanBeNull] Type propertyType, + private InternalPropertyBuilder? Property( + [CanBeNull] Type? propertyType, [NotNull] string propertyName, - [CanBeNull] MemberInfo memberInfo, + [CanBeNull] MemberInfo? memberInfo, ConfigurationSource? typeConfigurationSource, ConfigurationSource? configurationSource) { var entityType = Metadata; - List propertiesToDetach = null; + List? propertiesToDetach = null; var existingProperty = entityType.FindProperty(propertyName); if (existingProperty != null) { @@ -629,6 +634,8 @@ private InternalPropertyBuilder Property( } } + Check.DebugAssert(configurationSource is not null, "configurationSource is null"); + InternalPropertyBuilder builder; using (Metadata.Model.DelayConventions()) { @@ -659,7 +666,7 @@ private InternalPropertyBuilder Property( foreignKey.DeclaringEntityType.Builder.HasNoRelationship(foreignKey, ConfigurationSource.Convention); } else if (foreignKey.Builder.HasNavigation( - (string)null, + (string?)null, conflictingNavigation.IsOnDependent, configurationSource.Value) == null) @@ -676,7 +683,7 @@ private InternalPropertyBuilder Property( } var inverse = conflictingSkipNavigation.Inverse; - if (inverse?.Builder != null + if (inverse?.IsInModel == true && inverse.GetConfigurationSource() != ConfigurationSource.Explicit) { inverse.DeclaringEntityType.Builder.HasNoSkipNavigation(inverse, configurationSource.Value); @@ -688,17 +695,17 @@ private InternalPropertyBuilder Property( } builder = entityType.AddProperty( - propertyName, propertyType, memberInfo, typeConfigurationSource, configurationSource.Value).Builder; + propertyName, propertyType, memberInfo, typeConfigurationSource, configurationSource.Value)!.Builder; detachedProperties?.Attach(this); } - return builder.Metadata.Builder == null - ? Metadata.FindProperty(propertyName)?.Builder - : builder; + return builder.Metadata.IsInModel + ? builder + : Metadata.FindProperty(propertyName)?.Builder; } - private bool IsCompatible(MemberInfo newMemberInfo, Property existingProperty) + private bool IsCompatible(MemberInfo? newMemberInfo, Property existingProperty) { if (newMemberInfo == null) { @@ -717,12 +724,12 @@ private bool IsCompatible(MemberInfo newMemberInfo, Property existingProperty) } var declaringType = (IMutableEntityType)existingProperty.DeclaringType; - if (!newMemberInfo.DeclaringType.IsAssignableFrom(declaringType.ClrType)) + if (!newMemberInfo.DeclaringType!.IsAssignableFrom(declaringType.ClrType)) { return existingMemberInfo.IsOverridenBy(newMemberInfo); } - IMutableEntityType existingMemberDeclaringEntityType = null; + IMutableEntityType? existingMemberDeclaringEntityType = null; foreach (var baseType in declaringType.GetAllBaseTypes()) { if (newMemberInfo.DeclaringType == baseType.ClrType) @@ -787,7 +794,7 @@ private bool CanRemoveProperty( Check.DebugAssert(removed != null, "removed is null"); } - if (property.Builder != null) + if (property.IsInModel) { var removedProperty = Metadata.RemoveProperty(property.Name); Check.DebugAssert(removedProperty == property, "removedProperty != property"); @@ -818,18 +825,10 @@ public virtual IMutableNavigationBase Navigation([NotNull] MemberInfo memberInfo /// doing so can result in application failures when updating to a new Entity Framework Core release. /// public virtual IMutableNavigationBase Navigation([NotNull] string navigationName) - { - var existingNavigation = Metadata.FindNavigation(navigationName); - var existingSkipNavigation = Metadata.FindSkipNavigation(navigationName); - if (existingNavigation == null - && existingSkipNavigation == null) - { - throw new InvalidOperationException( + => (IMutableNavigationBase?)Metadata.FindNavigation(navigationName) + ?? Metadata.FindSkipNavigation(navigationName) + ?? throw new InvalidOperationException( CoreStrings.CanOnlyConfigureExistingNavigations(navigationName, Metadata.DisplayName())); - } - - return ((IMutableNavigationBase)existingNavigation) ?? existingSkipNavigation; - } /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -837,13 +836,13 @@ public virtual IMutableNavigationBase Navigation([NotNull] string navigationName /// 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. /// - public virtual InternalServicePropertyBuilder ServiceProperty( + public virtual InternalServicePropertyBuilder? ServiceProperty( [NotNull] MemberInfo memberInfo, ConfigurationSource? configurationSource) { var propertyName = memberInfo.GetSimpleMemberName(); - List propertiesToDetach = null; - InternalServicePropertyBuilder builder = null; + List? propertiesToDetach = null; + InternalServicePropertyBuilder? builder; var existingProperty = Metadata.FindServiceProperty(propertyName); if (existingProperty != null) { @@ -893,15 +892,17 @@ public virtual InternalServicePropertyBuilder ServiceProperty( } } + Check.DebugAssert(configurationSource is not null, "configurationSource is not null"); + using (ModelBuilder.Metadata.DelayConventions()) { - List detachedProperties = null; + List? detachedProperties = null; if (propertiesToDetach != null) { detachedProperties = new List(); foreach (var propertyToDetach in propertiesToDetach) { - detachedProperties.Add(DetachServiceProperty(propertyToDetach)); + detachedProperties.Add(DetachServiceProperty(propertyToDetach)!); } } @@ -930,7 +931,7 @@ public virtual InternalServicePropertyBuilder ServiceProperty( foreignKey.DeclaringEntityType.Builder.HasNoRelationship(foreignKey, ConfigurationSource.Convention); } else if (foreignKey.Builder.HasNavigation( - (string)null, + (string?)null, conflictingNavigation.IsOnDependent, configurationSource.Value) == null) @@ -947,7 +948,7 @@ public virtual InternalServicePropertyBuilder ServiceProperty( } var inverse = conflictingSkipNavigation.Inverse; - if (inverse?.Builder != null + if (inverse?.IsInModel == true && inverse.GetConfigurationSource() != ConfigurationSource.Explicit) { inverse.DeclaringEntityType.Builder.HasNoSkipNavigation(inverse, configurationSource.Value); @@ -969,9 +970,9 @@ public virtual InternalServicePropertyBuilder ServiceProperty( } } - return builder.Metadata.Builder == null - ? Metadata.FindServiceProperty(propertyName)?.Builder - : builder; + return builder.Metadata.IsInModel + ? builder + : Metadata.FindServiceProperty(propertyName)?.Builder; } /// @@ -1012,14 +1013,14 @@ private bool CanAddServiceProperty([NotNull] MemberInfo memberInfo, Configuratio return true; } - private static InternalServicePropertyBuilder DetachServiceProperty(ServiceProperty serviceProperty) + private static InternalServicePropertyBuilder? DetachServiceProperty(ServiceProperty? serviceProperty) { - var builder = serviceProperty?.Builder; - if (builder == null) + if (serviceProperty is null || !serviceProperty.IsInModel) { return null; } + var builder = serviceProperty.Builder; serviceProperty.DeclaringEntityType.RemoveServiceProperty(serviceProperty); return builder; } @@ -1070,7 +1071,7 @@ public virtual bool IsIgnored([NotNull] string name, ConfigurationSource? config /// 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. /// - public virtual InternalEntityTypeBuilder Ignore([NotNull] string name, ConfigurationSource configurationSource) + public virtual InternalEntityTypeBuilder? Ignore([NotNull] string name, ConfigurationSource configurationSource) { var ignoredConfigurationSource = Metadata.FindIgnoredConfigurationSource(name); if (ignoredConfigurationSource.HasValue) @@ -1099,7 +1100,7 @@ public virtual InternalEntityTypeBuilder Ignore([NotNull] string name, Configura if (foreignKey.GetConfigurationSource() != navigationConfigurationSource) { var removedNavigation = foreignKey.Builder.HasNavigation( - (MemberInfo)null, navigation.IsOnDependent, configurationSource); + (MemberInfo?)null, navigation.IsOnDependent, configurationSource); Check.DebugAssert(removedNavigation != null, "removedNavigation is null"); } else @@ -1126,7 +1127,7 @@ public virtual InternalEntityTypeBuilder Ignore([NotNull] string name, Configura if (skipNavigation != null) { var inverse = skipNavigation.Inverse; - if (inverse?.Builder != null + if (inverse?.IsInModel == true && inverse.GetConfigurationSource() != ConfigurationSource.Explicit) { inverse.DeclaringEntityType.Builder.HasNoSkipNavigation(inverse, configurationSource); @@ -1173,7 +1174,7 @@ public virtual InternalEntityTypeBuilder Ignore([NotNull] string name, Configura if (derivedNavigation.GetConfigurationSource() != ConfigurationSource.Explicit) { foreignKey.Builder.HasNavigation( - (MemberInfo)null, derivedNavigation.IsOnDependent, configurationSource); + (MemberInfo?)null, derivedNavigation.IsOnDependent, configurationSource); } } else if (foreignKey.GetConfigurationSource() != ConfigurationSource.Explicit) @@ -1197,7 +1198,7 @@ public virtual InternalEntityTypeBuilder Ignore([NotNull] string name, Configura if (skipNavigation != null) { var inverse = skipNavigation.Inverse; - if (inverse?.Builder != null + if (inverse?.IsInModel == true && inverse.GetConfigurationSource() != ConfigurationSource.Explicit) { inverse.DeclaringEntityType.Builder.HasNoSkipNavigation(inverse, configurationSource); @@ -1343,8 +1344,8 @@ private bool CanIgnore(string name, ConfigurationSource configurationSource, boo /// 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. /// - public virtual InternalEntityTypeBuilder HasQueryFilter( - [CanBeNull] LambdaExpression filter, + public virtual InternalEntityTypeBuilder? HasQueryFilter( + [CanBeNull] LambdaExpression? filter, ConfigurationSource configurationSource) { if (CanSetQueryFilter(filter, configurationSource)) @@ -1363,7 +1364,7 @@ public virtual InternalEntityTypeBuilder HasQueryFilter( /// 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. /// - public virtual bool CanSetQueryFilter([CanBeNull] LambdaExpression filter, ConfigurationSource configurationSource) + public virtual bool CanSetQueryFilter([CanBeNull] LambdaExpression? filter, ConfigurationSource configurationSource) => configurationSource.Overrides(Metadata.GetQueryFilterConfigurationSource()) || Metadata.GetQueryFilter() == filter; @@ -1374,8 +1375,8 @@ public virtual bool CanSetQueryFilter([CanBeNull] LambdaExpression filter, Confi /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [Obsolete] - public virtual InternalEntityTypeBuilder HasDefiningQuery( - [CanBeNull] LambdaExpression query, + public virtual InternalEntityTypeBuilder? HasDefiningQuery( + [CanBeNull] LambdaExpression? query, ConfigurationSource configurationSource) { if (CanSetDefiningQuery(query, configurationSource)) @@ -1395,7 +1396,7 @@ public virtual InternalEntityTypeBuilder HasDefiningQuery( /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [Obsolete] - public virtual bool CanSetDefiningQuery([CanBeNull] LambdaExpression query, ConfigurationSource configurationSource) + public virtual bool CanSetDefiningQuery([CanBeNull] LambdaExpression? query, ConfigurationSource configurationSource) => configurationSource.Overrides(Metadata.GetDefiningQueryConfigurationSource()) || Metadata.GetDefiningQuery() == query; @@ -1405,11 +1406,11 @@ public virtual bool CanSetDefiningQuery([CanBeNull] LambdaExpression query, Conf /// 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. /// - public virtual InternalEntityTypeBuilder HasBaseType([CanBeNull] Type baseEntityType, ConfigurationSource configurationSource) + public virtual InternalEntityTypeBuilder? HasBaseType([CanBeNull] Type? baseEntityType, ConfigurationSource configurationSource) { if (baseEntityType == null) { - return HasBaseType((EntityType)null, configurationSource); + return HasBaseType((EntityType?)null, configurationSource); } var baseType = ModelBuilder.Entity(baseEntityType, configurationSource); @@ -1424,11 +1425,11 @@ public virtual InternalEntityTypeBuilder HasBaseType([CanBeNull] Type baseEntity /// 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. /// - public virtual InternalEntityTypeBuilder HasBaseType([CanBeNull] string baseEntityTypeName, ConfigurationSource configurationSource) + public virtual InternalEntityTypeBuilder? HasBaseType([CanBeNull] string? baseEntityTypeName, ConfigurationSource configurationSource) { if (baseEntityTypeName == null) { - return HasBaseType((EntityType)null, configurationSource); + return HasBaseType((EntityType?)null, configurationSource); } var baseType = ModelBuilder.Entity(baseEntityTypeName, configurationSource); @@ -1443,8 +1444,8 @@ public virtual InternalEntityTypeBuilder HasBaseType([CanBeNull] string baseEnti /// 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. /// - public virtual InternalEntityTypeBuilder HasBaseType( - [CanBeNull] EntityType baseEntityType, + public virtual InternalEntityTypeBuilder? HasBaseType( + [CanBeNull] EntityType? baseEntityType, ConfigurationSource configurationSource) { if (Metadata.BaseType == baseEntityType) @@ -1460,11 +1461,11 @@ public virtual InternalEntityTypeBuilder HasBaseType( using (Metadata.Model.DelayConventions()) { - List detachedRelationships = null; - List detachedSkipNavigations = null; - PropertiesSnapshot detachedProperties = null; - List detachedServiceProperties = null; - IReadOnlyList<(InternalKeyBuilder, ConfigurationSource?)> detachedKeys = null; + List? detachedRelationships = null; + List? detachedSkipNavigations = null; + PropertiesSnapshot? detachedProperties = null; + List? detachedServiceProperties = null; + IReadOnlyList<(InternalKeyBuilder, ConfigurationSource?)>? detachedKeys = null; // We use at least DataAnnotation as ConfigurationSource while removing to allow us // to remove metadata object which were defined in derived type // while corresponding annotations were present on properties in base type. @@ -1536,7 +1537,7 @@ public virtual InternalEntityTypeBuilder HasBaseType( foreach (var foreignKeyUsingKeyProperties in foreignKeysUsingKeyProperties.ToList()) { - foreignKeyUsingKeyProperties.Builder.HasForeignKey((IReadOnlyList)null, configurationSourceForRemoval); + foreignKeyUsingKeyProperties.Builder.HasForeignKey((IReadOnlyList?)null, configurationSourceForRemoval); } var skipNavigationsToDetach = @@ -1556,7 +1557,7 @@ public virtual InternalEntityTypeBuilder HasBaseType( detachedSkipNavigations = new List(); foreach (var skipNavigation in skipNavigationsToDetach) { - detachedSkipNavigations.Add(DetachSkipNavigation(skipNavigation)); + detachedSkipNavigations.Add(DetachSkipNavigation(skipNavigation)!); } } @@ -1588,7 +1589,7 @@ public virtual InternalEntityTypeBuilder HasBaseType( detachedServiceProperties = new List(); foreach (var serviceProperty in servicePropertiesToDetach) { - detachedServiceProperties.Add(DetachServiceProperty(serviceProperty)); + detachedServiceProperties.Add(DetachServiceProperty(serviceProperty)!); } } @@ -1604,8 +1605,8 @@ public virtual InternalEntityTypeBuilder HasBaseType( baseEntityType.UpdateConfigurationSource(configurationSource); } - List detachedIndexes = null; - HashSet removedInheritedPropertiesToDuplicate = null; + List? detachedIndexes = null; + HashSet? removedInheritedPropertiesToDuplicate = null; if (Metadata.BaseType != null) { var removedInheritedProperties = new HashSet( @@ -1614,7 +1615,7 @@ public virtual InternalEntityTypeBuilder HasBaseType( if (removedInheritedProperties.Count != 0) { removedInheritedPropertiesToDuplicate = new HashSet(); - List relationshipsToBeDetached = null; + List? relationshipsToBeDetached = null; foreach (var foreignKey in Metadata.GetDerivedTypesInclusive() .SelectMany(t => t.GetDeclaredForeignKeys())) { @@ -1673,7 +1674,7 @@ public virtual InternalEntityTypeBuilder HasBaseType( } } - List indexesToBeDetached = null; + List? indexesToBeDetached = null; foreach (var index in Metadata.GetDerivedTypesInclusive().SelectMany(e => e.GetDeclaredIndexes())) { var shouldBeDetached = false; @@ -1716,7 +1717,10 @@ public virtual InternalEntityTypeBuilder HasBaseType( { foreach (var property in removedInheritedPropertiesToDuplicate) { - property.Builder?.Attach(this); + if (property.IsInModel) + { + property.Builder.Attach(this); + } } } @@ -1770,15 +1774,15 @@ public virtual InternalEntityTypeBuilder HasBaseType( return this; - List FindConflictingMembers( + List? FindConflictingMembers( IEnumerable derivedMembers, Dictionary baseMemberNames, Func compatibleWithBaseMember, Action removeMember) where T : PropertyBase { - List membersToBeDetached = null; - List membersToBeRemoved = null; + List? membersToBeDetached = null; + List? membersToBeRemoved = null; foreach (var member in derivedMembers) { ConfigurationSource? baseConfigurationSource = null; @@ -1834,7 +1838,8 @@ List FindConflictingMembers( /// 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. /// - public virtual bool CanSetBaseType([NotNull] EntityType baseEntityType, ConfigurationSource configurationSource) + // TODO-NULLABLE: Corrected annotation to nullable + public virtual bool CanSetBaseType([CanBeNull] EntityType? baseEntityType, ConfigurationSource configurationSource) { if (Metadata.BaseType == baseEntityType || configurationSource == ConfigurationSource.Explicit) @@ -1910,14 +1915,14 @@ public virtual bool CanSetBaseType([NotNull] EntityType baseEntityType, Configur /// 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. /// - public static PropertiesSnapshot DetachProperties([NotNull] IReadOnlyList propertiesToDetach) + public static PropertiesSnapshot? DetachProperties([NotNull] IReadOnlyList propertiesToDetach) { if (propertiesToDetach.Count == 0) { return null; } - List detachedRelationships = null; + List? detachedRelationships = null; foreach (var propertyToDetach in propertiesToDetach) { foreach (var relationship in propertyToDetach.GetContainingForeignKeys().ToList()) @@ -1955,16 +1960,15 @@ public static PropertiesSnapshot DetachProperties([NotNull] IReadOnlyList (s, s.GetForeignKeyConfigurationSource().Value)).ToList(); + .Select(s => (s, s.GetForeignKeyConfigurationSource()!.Value)).ToList(); var relationshipConfigurationSource = foreignKey.DeclaringEntityType.Builder .HasNoRelationship(foreignKey, foreignKey.GetConfigurationSource()); Check.DebugAssert(relationshipConfigurationSource != null, "relationshipConfigurationSource is null"); - EntityType.Snapshot ownedSnapshot = null; + EntityType.Snapshot? ownedSnapshot = null; var dependentEntityType = foreignKey.DeclaringEntityType; if (includeOwnedSharedType && foreignKey.IsOwnership @@ -2050,11 +2054,11 @@ public static RelationshipSnapshot DetachRelationship([NotNull] ForeignKey forei /// 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. /// - public virtual InternalEntityTypeBuilder HasNoRelationship( + public virtual InternalEntityTypeBuilder? HasNoRelationship( [NotNull] ForeignKey foreignKey, ConfigurationSource configurationSource) { - if (foreignKey.Builder == null) + if (!foreignKey.IsInModel) { return this; } @@ -2077,7 +2081,7 @@ public virtual InternalEntityTypeBuilder HasNoRelationship( } } - if (foreignKey.Builder == null) + if (!foreignKey.IsInModel) { return this; } @@ -2085,7 +2089,10 @@ public virtual InternalEntityTypeBuilder HasNoRelationship( Metadata.RemoveForeignKey(foreignKey); RemoveUnusedImplicitProperties(foreignKey.Properties); - foreignKey.PrincipalKey.DeclaringEntityType.Builder?.RemoveKeyIfUnused(foreignKey.PrincipalKey); + if (foreignKey.PrincipalKey.DeclaringEntityType.IsInModel) + { + foreignKey.PrincipalKey.DeclaringEntityType.Builder.RemoveKeyIfUnused(foreignKey.PrincipalKey); + } return this; } @@ -2096,14 +2103,14 @@ public virtual InternalEntityTypeBuilder HasNoRelationship( /// 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. /// - public static EntityType.Snapshot DetachAllMembers([NotNull] EntityType entityType) + public static EntityType.Snapshot? DetachAllMembers([NotNull] EntityType entityType) { - if (entityType.Builder == null) + if (!entityType.IsInModel) { return null; } - List detachedRelationships = null; + List? detachedRelationships = null; foreach (var relationshipToBeDetached in entityType.GetDeclaredForeignKeys().ToList()) { if (detachedRelationships == null) @@ -2119,7 +2126,7 @@ public static EntityType.Snapshot DetachAllMembers([NotNull] EntityType entityTy } } - List detachedSkipNavigations = null; + List? detachedSkipNavigations = null; foreach (var skipNavigationsToBeDetached in entityType.GetDeclaredSkipNavigations().ToList()) { if (detachedSkipNavigations == null) @@ -2127,10 +2134,10 @@ public static EntityType.Snapshot DetachAllMembers([NotNull] EntityType entityTy detachedSkipNavigations = new List(); } - detachedSkipNavigations.Add(DetachSkipNavigation(skipNavigationsToBeDetached)); + detachedSkipNavigations.Add(DetachSkipNavigation(skipNavigationsToBeDetached)!); } - List<(InternalKeyBuilder, ConfigurationSource?)> detachedKeys = null; + List<(InternalKeyBuilder, ConfigurationSource?)>? detachedKeys = null; foreach (var keyToDetach in entityType.GetDeclaredKeys().ToList()) { foreach (var relationshipToBeDetached in keyToDetach.GetReferencingForeignKeys().ToList()) @@ -2148,7 +2155,7 @@ public static EntityType.Snapshot DetachAllMembers([NotNull] EntityType entityTy } } - if (keyToDetach.Builder == null) + if (!keyToDetach.IsInModel) { continue; } @@ -2165,7 +2172,7 @@ public static EntityType.Snapshot DetachAllMembers([NotNull] EntityType entityTy } } - List detachedIndexes = null; + List? detachedIndexes = null; foreach (var index in entityType.GetDeclaredIndexes().ToList()) { if (detachedIndexes == null) @@ -2182,7 +2189,7 @@ public static EntityType.Snapshot DetachAllMembers([NotNull] EntityType entityTy var detachedProperties = DetachProperties(entityType.GetDeclaredProperties().ToList()); - List detachedServiceProperties = null; + List? detachedServiceProperties = null; foreach (var servicePropertiesToBeDetached in entityType.GetDeclaredServiceProperties().ToList()) { if (detachedServiceProperties == null) @@ -2190,7 +2197,7 @@ public static EntityType.Snapshot DetachAllMembers([NotNull] EntityType entityTy detachedServiceProperties = new List(); } - detachedServiceProperties.Add(DetachServiceProperty(servicePropertiesToBeDetached)); + detachedServiceProperties.Add(DetachServiceProperty(servicePropertiesToBeDetached)!); } return new EntityType.Snapshot( @@ -2225,8 +2232,7 @@ public virtual InternalEntityTypeBuilder RemoveUnusedImplicitProperties([NotN { foreach (var property in properties) { - if (property?.Builder != null - && property.IsImplicitlyCreated()) + if (property?.IsInModel == true && property.IsImplicitlyCreated()) { RemovePropertyIfUnused((Property)(object)property, ConfigurationSource.Convention); } @@ -2237,7 +2243,7 @@ public virtual InternalEntityTypeBuilder RemoveUnusedImplicitProperties([NotN private static void RemovePropertyIfUnused(Property property, ConfigurationSource configurationSource) { - if (property.Builder == null + if (!property.IsInModel || !property.DeclaringEntityType.Builder.CanRemoveProperty(property, configurationSource) || property.GetContainingIndexes().Any() || property.GetContainingForeignKeys().Any() @@ -2256,7 +2262,7 @@ private static void RemovePropertyIfUnused(Property property, ConfigurationSourc /// 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. /// - public virtual InternalIndexBuilder HasIndex([NotNull] IReadOnlyList propertyNames, ConfigurationSource configurationSource) + public virtual InternalIndexBuilder? HasIndex([NotNull] IReadOnlyList propertyNames, ConfigurationSource configurationSource) => HasIndex(GetOrCreateProperties(propertyNames, configurationSource), configurationSource); /// @@ -2265,7 +2271,7 @@ public virtual InternalIndexBuilder HasIndex([NotNull] IReadOnlyList pro /// 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. /// - public virtual InternalIndexBuilder HasIndex( + public virtual InternalIndexBuilder? HasIndex( [NotNull] IReadOnlyList propertyNames, [NotNull] string name, ConfigurationSource configurationSource) @@ -2277,7 +2283,7 @@ public virtual InternalIndexBuilder HasIndex( /// 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. /// - public virtual InternalIndexBuilder HasIndex( + public virtual InternalIndexBuilder? HasIndex( [NotNull] IReadOnlyList clrMembers, ConfigurationSource configurationSource) => HasIndex(GetOrCreateProperties(clrMembers, configurationSource), configurationSource); @@ -2288,7 +2294,7 @@ public virtual InternalIndexBuilder HasIndex( /// 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. /// - public virtual InternalIndexBuilder HasIndex( + public virtual InternalIndexBuilder? HasIndex( [NotNull] IReadOnlyList clrMembers, [NotNull] string name, ConfigurationSource configurationSource) @@ -2300,8 +2306,8 @@ public virtual InternalIndexBuilder HasIndex( /// 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. /// - public virtual InternalIndexBuilder HasIndex( - [CanBeNull] IReadOnlyList properties, + public virtual InternalIndexBuilder? HasIndex( + [CanBeNull] IReadOnlyList? properties, ConfigurationSource configurationSource) { if (properties == null) @@ -2309,7 +2315,7 @@ public virtual InternalIndexBuilder HasIndex( return null; } - List detachedIndexes = null; + List? detachedIndexes = null; var existingIndex = Metadata.FindIndex(properties); if (existingIndex == null) { @@ -2339,8 +2345,8 @@ public virtual InternalIndexBuilder HasIndex( /// 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. /// - public virtual InternalIndexBuilder HasIndex( - [CanBeNull] IReadOnlyList properties, + public virtual InternalIndexBuilder? HasIndex( + [CanBeNull] IReadOnlyList? properties, [NotNull] string name, ConfigurationSource configurationSource) { @@ -2351,7 +2357,7 @@ public virtual InternalIndexBuilder HasIndex( return null; } - List detachedIndexes = null; + List? detachedIndexes = null; var existingIndex = Metadata.FindIndex(name); if (existingIndex != null @@ -2385,10 +2391,10 @@ public virtual InternalIndexBuilder HasIndex( return indexBuilder; } - private InternalIndexBuilder HasIndex( - Index index, + private InternalIndexBuilder? HasIndex( + Index? index, IReadOnlyList properties, - string name, + string? name, ConfigurationSource configurationSource) { if (index == null) @@ -2416,7 +2422,7 @@ private InternalIndexBuilder HasIndex( /// 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. /// - public virtual InternalEntityTypeBuilder HasNoIndex([NotNull] Index index, ConfigurationSource configurationSource) + public virtual InternalEntityTypeBuilder? HasNoIndex([NotNull] Index index, ConfigurationSource configurationSource) { var currentConfigurationSource = index.GetConfigurationSource(); if (!configurationSource.Overrides(currentConfigurationSource)) @@ -2449,7 +2455,7 @@ public virtual bool CanRemoveIndex([NotNull] Index index, ConfigurationSource co /// 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. /// - public static List DetachIndexes([NotNull] IEnumerable indexesToDetach) + public static List? DetachIndexes([NotNull] IEnumerable indexesToDetach) { var indexesToDetachList = (indexesToDetach as List) ?? indexesToDetach.ToList(); if (indexesToDetachList.Count == 0) @@ -2482,7 +2488,7 @@ private static InternalIndexBuilder DetachIndex(Index indexToDetach) /// 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. /// - public virtual InternalForeignKeyBuilder HasRelationship( + public virtual InternalForeignKeyBuilder? HasRelationship( [NotNull] string principalEntityTypeName, [NotNull] IReadOnlyList propertyNames, ConfigurationSource configurationSource) @@ -2508,7 +2514,7 @@ public virtual InternalForeignKeyBuilder HasRelationship( /// 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. /// - public virtual InternalForeignKeyBuilder HasRelationship( + public virtual InternalForeignKeyBuilder? HasRelationship( [NotNull] string principalEntityTypeName, [NotNull] IReadOnlyList propertyNames, [NotNull] Key principalKey, @@ -2533,7 +2539,7 @@ public virtual InternalForeignKeyBuilder HasRelationship( /// 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. /// - public virtual InternalForeignKeyBuilder HasRelationship( + public virtual InternalForeignKeyBuilder? HasRelationship( [NotNull] Type principalClrType, [NotNull] IReadOnlyList clrMembers, ConfigurationSource configurationSource) @@ -2557,7 +2563,7 @@ public virtual InternalForeignKeyBuilder HasRelationship( /// 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. /// - public virtual InternalForeignKeyBuilder HasRelationship( + public virtual InternalForeignKeyBuilder? HasRelationship( [NotNull] Type principalClrType, [NotNull] IReadOnlyList clrMembers, [NotNull] Key principalKey, @@ -2582,7 +2588,7 @@ public virtual InternalForeignKeyBuilder HasRelationship( /// 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. /// - public virtual InternalForeignKeyBuilder HasRelationship( + public virtual InternalForeignKeyBuilder? HasRelationship( [NotNull] EntityType principalEntityType, [NotNull] IReadOnlyList dependentProperties, ConfigurationSource configurationSource) @@ -2598,10 +2604,10 @@ public virtual InternalForeignKeyBuilder HasRelationship( /// 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. /// - public virtual InternalForeignKeyBuilder HasRelationship( + public virtual InternalForeignKeyBuilder? HasRelationship( [NotNull] EntityType principalEntityType, [NotNull] IReadOnlyList dependentProperties, - [CanBeNull] Key principalKey, + [CanBeNull] Key? principalKey, ConfigurationSource configurationSource) => HasForeignKey( principalEntityType, @@ -2609,10 +2615,10 @@ public virtual InternalForeignKeyBuilder HasRelationship( principalKey, configurationSource); - private InternalForeignKeyBuilder HasForeignKey( + private InternalForeignKeyBuilder? HasForeignKey( EntityType principalEntityType, - IReadOnlyList dependentProperties, - Key principalKey, + IReadOnlyList? dependentProperties, + Key? principalKey, ConfigurationSource configurationSource) { if (dependentProperties == null) @@ -2620,11 +2626,11 @@ private InternalForeignKeyBuilder HasForeignKey( return null; } - var newRelationship = HasRelationshipInternal(principalEntityType, principalKey, configurationSource); + var newRelationship = HasRelationshipInternal(principalEntityType, principalKey, configurationSource)!; var relationship = newRelationship.HasForeignKey(dependentProperties, configurationSource); if (relationship == null - && newRelationship.Metadata.Builder != null) + && newRelationship.Metadata.IsInModel) { HasNoRelationship(newRelationship.Metadata, configurationSource); } @@ -2640,9 +2646,9 @@ private InternalForeignKeyBuilder HasForeignKey( /// 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. /// - public virtual InternalForeignKeyBuilder HasRelationship( + public virtual InternalForeignKeyBuilder? HasRelationship( [NotNull] EntityType targetEntityType, - [CanBeNull] string navigationName, + [CanBeNull] string? navigationName, ConfigurationSource configurationSource, bool? targetIsPrincipal = null) => HasRelationship( @@ -2658,9 +2664,9 @@ public virtual InternalForeignKeyBuilder HasRelationship( /// 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. /// - public virtual InternalForeignKeyBuilder HasRelationship( + public virtual InternalForeignKeyBuilder? HasRelationship( [NotNull] EntityType targetEntityType, - [CanBeNull] MemberInfo navigationMember, + [CanBeNull] MemberInfo? navigationMember, ConfigurationSource configurationSource, bool? targetIsPrincipal = null) => HasRelationship( @@ -2676,10 +2682,10 @@ public virtual InternalForeignKeyBuilder HasRelationship( /// 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. /// - public virtual InternalForeignKeyBuilder HasRelationship( + public virtual InternalForeignKeyBuilder? HasRelationship( [NotNull] EntityType targetEntityType, - [CanBeNull] string navigationName, - [CanBeNull] string inverseNavigationName, + [CanBeNull] string? navigationName, + [CanBeNull] string? inverseNavigationName, ConfigurationSource configurationSource, bool setTargetAsPrincipal = false) => HasRelationship( @@ -2695,10 +2701,10 @@ public virtual InternalForeignKeyBuilder HasRelationship( /// 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. /// - public virtual InternalForeignKeyBuilder HasRelationship( + public virtual InternalForeignKeyBuilder? HasRelationship( [NotNull] EntityType targetEntityType, - [CanBeNull] MemberInfo navigation, - [CanBeNull] MemberInfo inverseNavigation, + [CanBeNull] MemberInfo? navigation, + [CanBeNull] MemberInfo? inverseNavigation, ConfigurationSource configurationSource, bool setTargetAsPrincipal = false) => HasRelationship( @@ -2708,7 +2714,7 @@ public virtual InternalForeignKeyBuilder HasRelationship( setTargetAsPrincipal ? true : (bool?)null, configurationSource); - private InternalForeignKeyBuilder HasRelationship( + private InternalForeignKeyBuilder? HasRelationship( EntityType targetEntityType, MemberIdentity? navigationToTarget, MemberIdentity? inverseNavigation, @@ -2839,7 +2845,7 @@ private InternalForeignKeyBuilder HasRelationship( existingRelationship = existingRelationship.HasEntityTypes( existingRelationship.Metadata.PrincipalEntityType, existingRelationship.Metadata.DeclaringEntityType, - configurationSource); + configurationSource)!; if (required.HasValue) { @@ -2900,8 +2906,8 @@ private InternalForeignKeyBuilder HasRelationship( } } - InternalForeignKeyBuilder relationship; - InternalForeignKeyBuilder newRelationship = null; + InternalForeignKeyBuilder? relationship; + InternalForeignKeyBuilder? newRelationship = null; using (var batcher = Metadata.Model.DelayConventions()) { if (existingRelationship != null) @@ -2950,11 +2956,11 @@ private InternalForeignKeyBuilder HasRelationship( if (setTargetAsPrincipal == true) { relationship = relationship - .HasEntityTypes(targetEntityType.Builder.Metadata, Metadata, configurationSource); + .HasEntityTypes(targetEntityType.Builder.Metadata, Metadata, configurationSource)!; if (required.HasValue) { - relationship = relationship.IsRequired(required.Value, configurationSource); + relationship = relationship.IsRequired(required.Value, configurationSource)!; } } @@ -2967,7 +2973,7 @@ private InternalForeignKeyBuilder HasRelationship( pointsToPrincipal: true, configurationSource) : relationship.HasNavigation( - navigationToTarget.Value.Name, + navigationToTarget!.Value.Name, pointsToPrincipal: true, configurationSource); } @@ -3011,7 +3017,7 @@ private InternalForeignKeyBuilder HasRelationship( if (relationship == null) { - if (newRelationship?.Metadata.Builder != null) + if (newRelationship?.Metadata.IsInModel == true) { newRelationship.Metadata.DeclaringEntityType.Builder.HasNoRelationship(newRelationship.Metadata, configurationSource); } @@ -3028,11 +3034,11 @@ private InternalForeignKeyBuilder HasRelationship( /// 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. /// - public virtual InternalForeignKeyBuilder HasRelationship( + public virtual InternalForeignKeyBuilder? HasRelationship( [NotNull] EntityType principalEntityType, ConfigurationSource configurationSource, bool? required = null, - [NotNull] string propertyBaseName = null) + [CanBeNull] string? propertyBaseName = null) => HasRelationshipInternal(principalEntityType, principalKey: null, configurationSource, required, propertyBaseName); /// @@ -3041,23 +3047,23 @@ public virtual InternalForeignKeyBuilder HasRelationship( /// 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. /// - public virtual InternalForeignKeyBuilder HasRelationship( + public virtual InternalForeignKeyBuilder? HasRelationship( [NotNull] EntityType principalEntityType, [NotNull] Key principalKey, ConfigurationSource configurationSource, bool? required = null, - [NotNull] string propertyBaseName = null) + [CanBeNull] string? propertyBaseName = null) => HasRelationshipInternal(principalEntityType, principalKey, configurationSource, required, propertyBaseName); - private InternalForeignKeyBuilder HasRelationshipInternal( + private InternalForeignKeyBuilder? HasRelationshipInternal( EntityType targetEntityType, - Key principalKey, + Key? principalKey, ConfigurationSource configurationSource, bool? required = null, - string propertyBaseName = null) + string? propertyBaseName = null) { - InternalForeignKeyBuilder relationship; - InternalForeignKeyBuilder newRelationship; + InternalForeignKeyBuilder? relationship; + InternalForeignKeyBuilder? newRelationship; using (var batch = Metadata.Model.DelayConventions()) { relationship = CreateForeignKey( @@ -3066,7 +3072,7 @@ private InternalForeignKeyBuilder HasRelationshipInternal( principalKey, propertyBaseName, required, - configurationSource); + configurationSource)!; newRelationship = relationship; if (principalKey != null) @@ -3080,7 +3086,7 @@ private InternalForeignKeyBuilder HasRelationshipInternal( if (newRelationship == null) { - if (relationship?.Metadata.Builder != null) + if (relationship?.Metadata.IsInModel == true) { relationship.Metadata.DeclaringEntityType.Builder.HasNoRelationship(relationship.Metadata, configurationSource); } @@ -3097,7 +3103,7 @@ private InternalForeignKeyBuilder HasRelationshipInternal( /// 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. /// - public virtual InternalForeignKeyBuilder HasOwnership( + public virtual InternalForeignKeyBuilder? HasOwnership( [NotNull] string targetEntityTypeName, [NotNull] string navigationName, ConfigurationSource configurationSource) @@ -3111,7 +3117,7 @@ public virtual InternalForeignKeyBuilder HasOwnership( /// 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. /// - public virtual InternalForeignKeyBuilder HasOwnership( + public virtual InternalForeignKeyBuilder? HasOwnership( [NotNull] Type targetEntityType, [NotNull] string navigationName, ConfigurationSource configurationSource) @@ -3125,7 +3131,7 @@ public virtual InternalForeignKeyBuilder HasOwnership( /// 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. /// - public virtual InternalForeignKeyBuilder HasOwnership( + public virtual InternalForeignKeyBuilder? HasOwnership( [NotNull] Type targetEntityType, [NotNull] MemberInfo navigationMember, ConfigurationSource configurationSource) @@ -3139,7 +3145,7 @@ public virtual InternalForeignKeyBuilder HasOwnership( /// 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. /// - public virtual InternalForeignKeyBuilder HasOwnership( + public virtual InternalForeignKeyBuilder? HasOwnership( [NotNull] Type targetEntityType, MemberIdentity navigation, ConfigurationSource configurationSource) @@ -3152,7 +3158,7 @@ public virtual InternalForeignKeyBuilder HasOwnership( /// 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. /// - public virtual InternalForeignKeyBuilder HasOwnership( + public virtual InternalForeignKeyBuilder? HasOwnership( in TypeIdentity typeIdentity, MemberIdentity navigation, ConfigurationSource configurationSource) @@ -3164,10 +3170,10 @@ public virtual InternalForeignKeyBuilder HasOwnership( /// 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. /// - public virtual InternalForeignKeyBuilder HasOwnership( + public virtual InternalForeignKeyBuilder? HasOwnership( [NotNull] Type targetEntityType, [NotNull] string navigationPropertyName, - [CanBeNull] string inversePropertyName, + [CanBeNull] string? inversePropertyName, ConfigurationSource configurationSource) => HasOwnership( new TypeIdentity(targetEntityType, Metadata.Model), @@ -3181,10 +3187,10 @@ public virtual InternalForeignKeyBuilder HasOwnership( /// 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. /// - public virtual InternalForeignKeyBuilder HasOwnership( + public virtual InternalForeignKeyBuilder? HasOwnership( [NotNull] Type targetEntityType, [NotNull] MemberInfo navigationMember, - [CanBeNull] MemberInfo inverseMember, + [CanBeNull] MemberInfo? inverseMember, ConfigurationSource configurationSource) => HasOwnership( new TypeIdentity(targetEntityType, Metadata.Model), @@ -3192,21 +3198,25 @@ public virtual InternalForeignKeyBuilder HasOwnership( MemberIdentity.Create(inverseMember), configurationSource); - private InternalForeignKeyBuilder HasOwnership( + private InternalForeignKeyBuilder? HasOwnership( in TypeIdentity targetEntityType, in MemberIdentity navigation, in MemberIdentity? inverse, ConfigurationSource configurationSource) { - InternalEntityTypeBuilder ownedEntityTypeBuilder; - InternalForeignKeyBuilder relationship; + InternalEntityTypeBuilder? ownedEntityTypeBuilder; + InternalForeignKeyBuilder? relationship; using (var batch = Metadata.Model.DelayConventions()) { var ownership = Metadata.FindOwnership(); ownedEntityTypeBuilder = GetTargetEntityTypeBuilder(targetEntityType, navigation, configurationSource, targetShouldBeOwned: true); - var principalBuilder = Metadata.Builder - ?? ownership?.PrincipalEntityType.FindNavigation(ownership.PrincipalToDependent.Name)?.TargetEntityType.Builder; + var principalBuilder = Metadata.IsInModel + ? Metadata.Builder + : ownership?.PrincipalEntityType.FindNavigation(ownership.PrincipalToDependent!.Name)?.TargetEntityType is EntityType target + && target.IsInModel + ? target.Builder + : null; if (ownedEntityTypeBuilder == null || principalBuilder == null) @@ -3222,13 +3232,13 @@ private InternalForeignKeyBuilder HasOwnership( inverseNavigation: navigation, setTargetAsPrincipal: true, configurationSource, - required: true); - relationship = batch.Run(relationship.IsOwnership(true, configurationSource)); + required: true)!; + relationship = batch.Run(relationship.IsOwnership(true, configurationSource)!); } - if (relationship?.Metadata.Builder == null) + if (relationship is null || !relationship.Metadata.IsInModel) { - if (ownedEntityTypeBuilder.Metadata.Builder != null + if (ownedEntityTypeBuilder.Metadata.IsInModel && ownedEntityTypeBuilder.Metadata.HasSharedClrType) { ModelBuilder.HasNoEntityType(ownedEntityTypeBuilder.Metadata, configurationSource); @@ -3246,7 +3256,7 @@ private InternalForeignKeyBuilder HasOwnership( /// 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. /// - public virtual bool RemoveNonOwnershipRelationships([NotNull] ForeignKey ownership, ConfigurationSource configurationSource) + public virtual bool RemoveNonOwnershipRelationships([CanBeNull] ForeignKey? ownership, ConfigurationSource configurationSource) { var incompatibleRelationships = Metadata.GetDerivedTypesInclusive() .SelectMany(t => t.GetDeclaredForeignKeys()) @@ -3271,7 +3281,7 @@ public virtual bool RemoveNonOwnershipRelationships([NotNull] ForeignKey ownersh { // foreignKey.Builder can be null below if calling HasNoRelationship() below // affects the other foreign key(s) in incompatibleRelationships - if (foreignKey.Builder != null) + if (foreignKey.IsInModel) { foreignKey.DeclaringEntityType.Builder.HasNoRelationship(foreignKey, configurationSource); } @@ -3280,7 +3290,7 @@ public virtual bool RemoveNonOwnershipRelationships([NotNull] ForeignKey ownersh return true; } - private bool Contains(IForeignKey inheritedFk, IForeignKey derivedFk) + private bool Contains(IForeignKey? inheritedFk, IForeignKey derivedFk) => inheritedFk != null && inheritedFk.PrincipalEntityType.IsAssignableFrom(derivedFk.PrincipalEntityType) && PropertyListComparer.Instance.Equals(inheritedFk.Properties, derivedFk.Properties); @@ -3291,7 +3301,7 @@ private bool Contains(IForeignKey inheritedFk, IForeignKey derivedFk) /// 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. /// - public virtual InternalEntityTypeBuilder GetTargetEntityTypeBuilder( + public virtual InternalEntityTypeBuilder? GetTargetEntityTypeBuilder( [NotNull] Type targetClrType, [NotNull] MemberInfo navigationInfo, ConfigurationSource? configurationSource) @@ -3304,13 +3314,13 @@ public virtual InternalEntityTypeBuilder GetTargetEntityTypeBuilder( /// 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. /// - public virtual InternalEntityTypeBuilder GetTargetEntityTypeBuilder( + public virtual InternalEntityTypeBuilder? GetTargetEntityTypeBuilder( TypeIdentity targetEntityType, MemberIdentity navigation, ConfigurationSource? configurationSource, bool? targetShouldBeOwned = null) { - var existingNavigation = Metadata.FindNavigation(navigation.Name); + var existingNavigation = Metadata.FindNavigation(navigation.Name!); if (existingNavigation != null) { var existingTargetType = existingNavigation.TargetEntityType; @@ -3326,8 +3336,8 @@ public virtual InternalEntityTypeBuilder GetTargetEntityTypeBuilder( return existingTargetType.HasSharedClrType ? ModelBuilder.SharedTypeEntity( - existingTargetType.Name, existingTargetType.ClrType, configurationSource.Value, targetShouldBeOwned) - : ModelBuilder.Entity(existingTargetType.ClrType, configurationSource.Value, targetShouldBeOwned); + existingTargetType.Name, existingTargetType.ClrType, configurationSource!.Value, targetShouldBeOwned) + : ModelBuilder.Entity(existingTargetType.ClrType, configurationSource!.Value, targetShouldBeOwned); } if (configurationSource == null @@ -3340,11 +3350,11 @@ public virtual InternalEntityTypeBuilder GetTargetEntityTypeBuilder( if (navigation.MemberInfo == null) { - if (Metadata.GetRuntimeProperties().TryGetValue(navigation.Name, out var propertyInfo)) + if (Metadata.GetRuntimeProperties()!.TryGetValue(navigation.Name!, out var propertyInfo)) { navigation = new MemberIdentity(propertyInfo); } - else if (Metadata.GetRuntimeFields().TryGetValue(navigation.Name, out var fieldInfo)) + else if (Metadata.GetRuntimeFields()!.TryGetValue(navigation.Name!, out var fieldInfo)) { navigation = new MemberIdentity(fieldInfo); } @@ -3397,7 +3407,7 @@ public virtual InternalEntityTypeBuilder GetTargetEntityTypeBuilder( var targetTypeName = targetEntityType.IsNamed && (targetEntityType.Type != null || targetShouldBeOwned != true) ? targetEntityType.Name : Metadata.Model.IsShared(targetType) - ? Metadata.GetOwnedName(targetEntityType.IsNamed ? targetEntityType.Name : targetType.ShortDisplayName(), navigation.Name) + ? Metadata.GetOwnedName(targetEntityType.IsNamed ? targetEntityType.Name : targetType.ShortDisplayName(), navigation.Name!) : Metadata.Model.GetDisplayName(targetType); var shouldBeOwned = targetShouldBeOwned ?? Metadata.Model.IsOwned(targetType); @@ -3436,7 +3446,7 @@ public virtual InternalEntityTypeBuilder GetTargetEntityTypeBuilder( targetEntityTypeBuilder = null; if (!targetEntityType.IsNamed) { - targetTypeName = Metadata.GetOwnedName(targetType.ShortDisplayName(), navigation.Name); + targetTypeName = Metadata.GetOwnedName(targetType.ShortDisplayName(), navigation.Name!); } } } @@ -3486,11 +3496,11 @@ public virtual InternalEntityTypeBuilder GetTargetEntityTypeBuilder( /// 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. /// - public virtual InternalForeignKeyBuilder CreateForeignKey( + public virtual InternalForeignKeyBuilder? CreateForeignKey( [NotNull] InternalEntityTypeBuilder principalEntityTypeBuilder, - [CanBeNull] IReadOnlyList dependentProperties, - [CanBeNull] Key principalKey, - [CanBeNull] string propertyBaseName, + [CanBeNull] IReadOnlyList? dependentProperties, + [CanBeNull] Key? principalKey, + [CanBeNull] string? propertyBaseName, bool? required, ConfigurationSource configurationSource) { @@ -3505,7 +3515,8 @@ public virtual InternalForeignKeyBuilder CreateForeignKey( foreignKey.SetIsRequired(required.Value, configurationSource); } - return (InternalForeignKeyBuilder)batch.Run(foreignKey)?.Builder; + // TODO-NULLABLE: can foreignKey be null from SetOrAddForeignKey above? + return (InternalForeignKeyBuilder?)batch.Run(foreignKey!)?.Builder; } /// @@ -3514,28 +3525,29 @@ public virtual InternalForeignKeyBuilder CreateForeignKey( /// 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. /// - public virtual InternalForeignKeyBuilder UpdateForeignKey( + public virtual InternalForeignKeyBuilder? UpdateForeignKey( [NotNull] ForeignKey foreignKey, - [CanBeNull] IReadOnlyList dependentProperties, - [CanBeNull] Key principalKey, - [CanBeNull] string propertyBaseName, + [CanBeNull] IReadOnlyList? dependentProperties, + [CanBeNull] Key? principalKey, + [CanBeNull] string? propertyBaseName, bool? isRequired, ConfigurationSource? configurationSource) { using var batch = ModelBuilder.Metadata.DelayConventions(); - foreignKey = SetOrAddForeignKey( + var updatedForeignKey = SetOrAddForeignKey( foreignKey, foreignKey.PrincipalEntityType.Builder, dependentProperties, principalKey, propertyBaseName, isRequired, configurationSource); - return (InternalForeignKeyBuilder)batch.Run(foreignKey)?.Builder; + // TODO-NULLABLE: can updatedForeignKey be null from SetOrAddForeignKey above? + return (InternalForeignKeyBuilder?)batch.Run(updatedForeignKey!)?.Builder; } - private ForeignKey SetOrAddForeignKey( - ForeignKey foreignKey, + private ForeignKey? SetOrAddForeignKey( + ForeignKey? foreignKey, InternalEntityTypeBuilder principalEntityTypeBuilder, - IReadOnlyList dependentProperties, - Key principalKey, - string propertyBaseName, + IReadOnlyList? dependentProperties, + Key? principalKey, + string? propertyBaseName, bool? isRequired, ConfigurationSource? configurationSource) { @@ -3580,14 +3592,14 @@ private ForeignKey SetOrAddForeignKey( if (dependentProperties != null) { - dependentProperties = GetActualProperties(dependentProperties, ConfigurationSource.Convention); + dependentProperties = GetActualProperties(dependentProperties, ConfigurationSource.Convention)!; if (principalKey == null) { var principalKeyProperties = principalBaseEntityTypeBuilder.TryCreateUniqueProperties( dependentProperties.Count, null, dependentProperties.Select(p => p.ClrType), Enumerable.Repeat("", dependentProperties.Count), isRequired: true, baseName: "TempId").Item2; - principalKey = principalBaseEntityTypeBuilder.HasKeyInternal(principalKeyProperties, ConfigurationSource.Convention) + principalKey = principalBaseEntityTypeBuilder.HasKeyInternal(principalKeyProperties, ConfigurationSource.Convention)! .Metadata; } else @@ -3618,7 +3630,7 @@ private ForeignKey SetOrAddForeignKey( { var oldProperties = foreignKey.Properties; var oldKey = foreignKey.PrincipalKey; - var temporaryProperties = CreateUniqueProperties(null, principalKey.Properties, isRequired ?? false, "TempFk"); + var temporaryProperties = CreateUniqueProperties(null, principalKey.Properties, isRequired ?? false, "TempFk")!; foreignKey.SetProperties(temporaryProperties, principalKey, configurationSource); foreignKey.DeclaringEntityType.Builder.RemoveUnusedImplicitProperties(oldProperties); @@ -3633,13 +3645,13 @@ private ForeignKey SetOrAddForeignKey( var baseName = string.IsNullOrEmpty(propertyBaseName) ? principalType.ShortName() : propertyBaseName; - dependentProperties = CreateUniqueProperties(null, principalKey.Properties, isRequired ?? false, baseName); + dependentProperties = CreateUniqueProperties(null, principalKey.Properties, isRequired ?? false, baseName)!; } if (foreignKey == null) { return Metadata.AddForeignKey( - dependentProperties, principalKey, principalType, componentConfigurationSource: null, configurationSource.Value); + dependentProperties, principalKey, principalType, componentConfigurationSource: null, configurationSource!.Value); } var oldFKProperties = foreignKey.Properties; @@ -3665,7 +3677,7 @@ private ForeignKey SetOrAddForeignKey( /// 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. /// - public virtual InternalSkipNavigationBuilder HasSkipNavigation( + public virtual InternalSkipNavigationBuilder? HasSkipNavigation( MemberIdentity navigation, [NotNull] EntityType targetEntityType, MemberIdentity inverseNavigation, @@ -3697,16 +3709,16 @@ public virtual InternalSkipNavigationBuilder HasSkipNavigation( /// 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. /// - public virtual InternalSkipNavigationBuilder HasSkipNavigation( + public virtual InternalSkipNavigationBuilder? HasSkipNavigation( MemberIdentity navigationProperty, [NotNull] EntityType targetEntityType, ConfigurationSource? configurationSource, bool? collection = null, bool? onDependent = null) { - List navigationsToDetach = null; - List<(InternalSkipNavigationBuilder Navigation, InternalSkipNavigationBuilder Inverse)> detachedNavigations = null; - var navigationName = navigationProperty.Name; + List? navigationsToDetach = null; + List<(InternalSkipNavigationBuilder Navigation, InternalSkipNavigationBuilder Inverse)>? detachedNavigations = null; + var navigationName = navigationProperty.Name!; var memberInfo = navigationProperty.MemberInfo; var existingNavigation = Metadata.FindSkipNavigation(navigationName); if (existingNavigation != null) @@ -3814,7 +3826,7 @@ public virtual InternalSkipNavigationBuilder HasSkipNavigation( conflictingForeignKey, ConfigurationSource.Convention); } else if (conflictingForeignKey.Builder.HasNavigation( - (string)null, + (string?)null, conflictingNavigation.IsOnDependent, configurationSource.Value) == null) @@ -3829,13 +3841,13 @@ public virtual InternalSkipNavigationBuilder HasSkipNavigation( foreach (var navigationToDetach in navigationsToDetach) { var inverse = navigationToDetach.Inverse; - detachedNavigations.Add((DetachSkipNavigation(navigationToDetach), DetachSkipNavigation(inverse))); + detachedNavigations.Add((DetachSkipNavigation(navigationToDetach)!, DetachSkipNavigation(inverse)!)); } } builder = Metadata.AddSkipNavigation( navigationName, navigationProperty.MemberInfo, - targetEntityType, collection ?? true, onDependent ?? false, configurationSource.Value).Builder; + targetEntityType, collection ?? true, onDependent ?? false, configurationSource.Value)!.Builder; if (detachedNavigations != null) { @@ -3846,9 +3858,9 @@ public virtual InternalSkipNavigationBuilder HasSkipNavigation( } } - return builder.Metadata.Builder == null - ? Metadata.FindSkipNavigation(navigationName)?.Builder - : builder; + return builder.Metadata.IsInModel + ? builder + : Metadata.FindSkipNavigation(navigationName)?.Builder; } /// @@ -3857,7 +3869,7 @@ public virtual InternalSkipNavigationBuilder HasSkipNavigation( /// 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. /// - public virtual InternalEntityTypeBuilder HasNoSkipNavigation( + public virtual InternalEntityTypeBuilder? HasNoSkipNavigation( [NotNull] SkipNavigation skipNavigation, ConfigurationSource configurationSource) { @@ -3886,14 +3898,14 @@ public virtual InternalEntityTypeBuilder HasNoSkipNavigation( public virtual bool CanRemoveSkipNavigation([NotNull] SkipNavigation skipNavigation, ConfigurationSource configurationSource) => configurationSource.Overrides(skipNavigation.GetConfigurationSource()); - private static InternalSkipNavigationBuilder DetachSkipNavigation(SkipNavigation skipNavigationToDetach) + private static InternalSkipNavigationBuilder? DetachSkipNavigation(SkipNavigation? skipNavigationToDetach) { - var builder = skipNavigationToDetach?.Builder; - if (builder == null) + if (skipNavigationToDetach is null || !skipNavigationToDetach.IsInModel) { return null; } + var builder = skipNavigationToDetach.Builder; skipNavigationToDetach.DeclaringEntityType.Builder.HasNoSkipNavigation(skipNavigationToDetach, ConfigurationSource.Explicit); return builder; } @@ -3923,7 +3935,7 @@ public virtual bool ShouldReuniquifyTemporaryProperties([NotNull] ForeignKey for /// 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. /// - public virtual InternalPropertyBuilder CreateUniqueProperty( + public virtual InternalPropertyBuilder? CreateUniqueProperty( [NotNull] Type propertyType, [NotNull] string propertyName, bool required) @@ -3948,10 +3960,10 @@ public virtual IReadOnlyList CreateUniqueProperties( propertyTypes, propertyNames, isRequired, - "").Item2; + "").Item2!; - private IReadOnlyList CreateUniqueProperties( - IReadOnlyList currentProperties, + private IReadOnlyList? CreateUniqueProperties( + IReadOnlyList? currentProperties, IReadOnlyList principalProperties, bool isRequired, string baseName) @@ -3963,9 +3975,9 @@ private IReadOnlyList CreateUniqueProperties( isRequired, baseName).Item2; - private (bool, IReadOnlyList) TryCreateUniqueProperties( + private (bool, IReadOnlyList?) TryCreateUniqueProperties( int propertyCount, - IReadOnlyList currentProperties, + IReadOnlyList? currentProperties, IEnumerable principalPropertyTypes, IEnumerable principalPropertyNames, bool isRequired, @@ -4004,14 +4016,14 @@ private IReadOnlyList CreateUniqueProperties( { var propertyBuilder = Property( clrType, propertyName, typeConfigurationSource: null, - configurationSource: ConfigurationSource.Convention); + configurationSource: ConfigurationSource.Convention)!; if (clrType.IsNullableType()) { propertyBuilder.IsRequired(isRequired, ConfigurationSource.Convention); } - newProperties[i] = propertyBuilder.Metadata; + newProperties![i] = propertyBuilder.Metadata; } else { @@ -4046,10 +4058,10 @@ private IReadOnlyList CreateUniqueProperties( /// 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. /// - public virtual IReadOnlyList GetOrCreateProperties( - [CanBeNull] IReadOnlyList propertyNames, + public virtual IReadOnlyList? GetOrCreateProperties( + [CanBeNull] IReadOnlyList? propertyNames, ConfigurationSource? configurationSource, - [CanBeNull] IReadOnlyList referencedProperties = null, + [CanBeNull] IReadOnlyList? referencedProperties = null, bool required = false, bool useDefaultType = false) { @@ -4107,12 +4119,12 @@ public virtual IReadOnlyList GetOrCreateProperties( property = property.DeclaringEntityType.Builder.Property( property.ClrType.MakeNullable(false), property.Name, - configurationSource.Value) + configurationSource.Value)! .Metadata; } else { - property = property.DeclaringEntityType.Builder.Property(property.Name, configurationSource.Value).Metadata; + property = property.DeclaringEntityType.Builder.Property(property.Name, configurationSource.Value)!.Metadata; } } @@ -4128,8 +4140,8 @@ public virtual IReadOnlyList GetOrCreateProperties( /// 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. /// - public virtual IReadOnlyList GetOrCreateProperties( - [CanBeNull] IEnumerable clrMembers, + public virtual IReadOnlyList? GetOrCreateProperties( + [CanBeNull] IEnumerable? clrMembers, ConfigurationSource? configurationSource) { if (clrMembers == null) @@ -4158,8 +4170,8 @@ public virtual IReadOnlyList GetOrCreateProperties( /// 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. /// - public virtual IReadOnlyList GetActualProperties( - [CanBeNull] IReadOnlyList properties, + public virtual IReadOnlyList? GetActualProperties( + [CanBeNull] IReadOnlyList? properties, ConfigurationSource? configurationSource) { if (properties == null) @@ -4172,7 +4184,7 @@ public virtual IReadOnlyList GetActualProperties( { var property = properties[i]; var typeConfigurationSource = property.GetTypeConfigurationSource(); - var builder = property.Builder != null && property.DeclaringEntityType.IsAssignableFrom(Metadata) + var builder = property.IsInModel && property.DeclaringEntityType.IsAssignableFrom(Metadata) ? property.Builder : Property( typeConfigurationSource.Overrides(ConfigurationSource.DataAnnotation) ? property.ClrType : null, @@ -4197,7 +4209,7 @@ public virtual IReadOnlyList GetActualProperties( /// 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. /// - public virtual InternalEntityTypeBuilder HasChangeTrackingStrategy( + public virtual InternalEntityTypeBuilder? HasChangeTrackingStrategy( ChangeTrackingStrategy? changeTrackingStrategy, ConfigurationSource configurationSource) { @@ -4229,7 +4241,7 @@ public virtual bool CanSetChangeTrackingStrategy( /// 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. /// - public virtual InternalEntityTypeBuilder UsePropertyAccessMode( + public virtual InternalEntityTypeBuilder? UsePropertyAccessMode( PropertyAccessMode? propertyAccessMode, ConfigurationSource configurationSource) { @@ -4259,7 +4271,7 @@ public virtual bool CanSetPropertyAccessMode(PropertyAccessMode? propertyAccessM /// 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. /// - public virtual DiscriminatorBuilder HasDiscriminator(ConfigurationSource configurationSource) + public virtual DiscriminatorBuilder? HasDiscriminator(ConfigurationSource configurationSource) => DiscriminatorBuilder( GetOrCreateDiscriminatorProperty(type: null, name: null, ConfigurationSource.Convention), configurationSource); @@ -4270,9 +4282,9 @@ public virtual DiscriminatorBuilder HasDiscriminator(ConfigurationSource configu /// 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. /// - public virtual DiscriminatorBuilder HasDiscriminator( - [CanBeNull] string name, - [CanBeNull] Type type, + public virtual DiscriminatorBuilder? HasDiscriminator( + [CanBeNull] string? name, + [CanBeNull] Type? type, ConfigurationSource configurationSource) { Check.DebugAssert(name != null || type != null, $"Either {nameof(name)} or {nameof(type)} should be non-null"); @@ -4290,7 +4302,7 @@ public virtual DiscriminatorBuilder HasDiscriminator( /// 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. /// - public virtual DiscriminatorBuilder HasDiscriminator([NotNull] MemberInfo memberInfo, ConfigurationSource configurationSource) + public virtual DiscriminatorBuilder? HasDiscriminator([NotNull] MemberInfo memberInfo, ConfigurationSource configurationSource) => CanSetDiscriminator( Check.NotNull(memberInfo, nameof(memberInfo)).GetSimpleMemberName(), memberInfo.GetMemberType(), configurationSource) ? DiscriminatorBuilder( @@ -4303,7 +4315,7 @@ public virtual DiscriminatorBuilder HasDiscriminator([NotNull] MemberInfo member private static readonly Type _defaultDiscriminatorType = typeof(string); - private InternalPropertyBuilder GetOrCreateDiscriminatorProperty(Type type, string name, ConfigurationSource configurationSource) + private InternalPropertyBuilder? GetOrCreateDiscriminatorProperty(Type? type, string? name, ConfigurationSource configurationSource) { var discriminatorProperty = ((IEntityType)Metadata).GetDiscriminatorProperty(); if ((name != null && discriminatorProperty?.Name != name) @@ -4320,8 +4332,8 @@ private InternalPropertyBuilder GetOrCreateDiscriminatorProperty(Type type, stri ?.AfterSave(PropertySaveBehavior.Throw, ConfigurationSource.Convention); } - private DiscriminatorBuilder DiscriminatorBuilder( - [CanBeNull] InternalPropertyBuilder discriminatorPropertyBuilder, + private DiscriminatorBuilder? DiscriminatorBuilder( + [CanBeNull] InternalPropertyBuilder? discriminatorPropertyBuilder, ConfigurationSource configurationSource) { if (discriminatorPropertyBuilder == null) @@ -4333,7 +4345,7 @@ private DiscriminatorBuilder DiscriminatorBuilder( var discriminatorProperty = discriminatorPropertyBuilder.Metadata; // Make sure the property is on the root type discriminatorPropertyBuilder = rootTypeBuilder.Property( - discriminatorProperty.ClrType, discriminatorProperty.Name, null, ConfigurationSource.Convention); + discriminatorProperty.ClrType, discriminatorProperty.Name, null, ConfigurationSource.Convention)!; RemoveUnusedDiscriminatorProperty(discriminatorProperty, configurationSource); @@ -4350,7 +4362,7 @@ private DiscriminatorBuilder DiscriminatorBuilder( /// 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. /// - public virtual InternalEntityTypeBuilder HasNoDiscriminator(ConfigurationSource configurationSource) + public virtual InternalEntityTypeBuilder? HasNoDiscriminator(ConfigurationSource configurationSource) { if (Metadata[CoreAnnotationNames.DiscriminatorProperty] != null && !configurationSource.Overrides(Metadata.GetDiscriminatorPropertyConfigurationSource())) @@ -4377,19 +4389,19 @@ public virtual InternalEntityTypeBuilder HasNoDiscriminator(ConfigurationSource return this; } - private void RemoveUnusedDiscriminatorProperty(Property newDiscriminatorProperty, ConfigurationSource configurationSource) + private void RemoveUnusedDiscriminatorProperty(Property? newDiscriminatorProperty, ConfigurationSource configurationSource) { var oldDiscriminatorProperty = ((IEntityType)Metadata).GetDiscriminatorProperty() as Property; - if (oldDiscriminatorProperty?.Builder != null + if (oldDiscriminatorProperty?.IsInModel == true && oldDiscriminatorProperty != newDiscriminatorProperty) { oldDiscriminatorProperty.DeclaringEntityType.Builder.RemoveUnusedImplicitProperties( new[] { oldDiscriminatorProperty }); - if (oldDiscriminatorProperty.Builder != null) + if (oldDiscriminatorProperty.IsInModel) { oldDiscriminatorProperty.Builder.IsRequired(null, configurationSource); - oldDiscriminatorProperty.Builder.HasValueGenerator((Type)null, configurationSource); + oldDiscriminatorProperty.Builder.HasValueGenerator((Type?)null, configurationSource); } } } @@ -4400,15 +4412,15 @@ private void RemoveUnusedDiscriminatorProperty(Property newDiscriminatorProperty /// 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. /// - public virtual bool CanSetDiscriminator([CanBeNull] string name, [CanBeNull] Type type, ConfigurationSource configurationSource) + public virtual bool CanSetDiscriminator([CanBeNull] string? name, [CanBeNull] Type? type, ConfigurationSource configurationSource) => name == null && type == null ? CanRemoveDiscriminator(configurationSource) : CanSetDiscriminator(((IEntityType)Metadata).GetDiscriminatorProperty(), name, type, configurationSource); private bool CanSetDiscriminator( - IProperty discriminatorProperty, - string name, - Type discriminatorType, + IProperty? discriminatorProperty, + string? name, + Type? discriminatorType, ConfigurationSource configurationSource) => ((name == null && discriminatorType == null) || ((name == null || discriminatorProperty?.Name == name) @@ -4475,9 +4487,9 @@ IConventionEntityType IConventionEntityTypeBuilder.Metadata /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [DebuggerStepThrough] - IConventionEntityTypeBuilder IConventionEntityTypeBuilder.HasBaseType(IConventionEntityType baseEntityType, bool fromDataAnnotation) + IConventionEntityTypeBuilder? IConventionEntityTypeBuilder.HasBaseType(IConventionEntityType? baseEntityType, bool fromDataAnnotation) => HasBaseType( - (EntityType)baseEntityType, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); + (EntityType?)baseEntityType, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -4486,9 +4498,9 @@ IConventionEntityTypeBuilder IConventionEntityTypeBuilder.HasBaseType(IConventio /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [DebuggerStepThrough] - bool IConventionEntityTypeBuilder.CanSetBaseType(IConventionEntityType baseEntityType, bool fromDataAnnotation) + bool IConventionEntityTypeBuilder.CanSetBaseType(IConventionEntityType? baseEntityType, bool fromDataAnnotation) => CanSetBaseType( - (EntityType)baseEntityType, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); + (EntityType?)baseEntityType, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -4497,7 +4509,7 @@ bool IConventionEntityTypeBuilder.CanSetBaseType(IConventionEntityType baseEntit /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [DebuggerStepThrough] - IConventionPropertyBuilder IConventionEntityTypeBuilder.Property( + IConventionPropertyBuilder? IConventionEntityTypeBuilder.Property( Type propertyType, string propertyName, bool setTypeConfigurationSource, @@ -4515,7 +4527,7 @@ IConventionPropertyBuilder IConventionEntityTypeBuilder.Property( /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [DebuggerStepThrough] - IConventionPropertyBuilder IConventionEntityTypeBuilder.Property(MemberInfo memberInfo, bool fromDataAnnotation) + IConventionPropertyBuilder? IConventionEntityTypeBuilder.Property(MemberInfo memberInfo, bool fromDataAnnotation) => Property(memberInfo, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// @@ -4525,8 +4537,8 @@ IConventionPropertyBuilder IConventionEntityTypeBuilder.Property(MemberInfo memb /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [DebuggerStepThrough] - IReadOnlyList IConventionEntityTypeBuilder.GetOrCreateProperties( - IReadOnlyList propertyNames, + IReadOnlyList? IConventionEntityTypeBuilder.GetOrCreateProperties( + IReadOnlyList? propertyNames, bool fromDataAnnotation) => GetOrCreateProperties( propertyNames, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); @@ -4538,8 +4550,8 @@ IReadOnlyList IConventionEntityTypeBuilder.GetOrCreatePrope /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [DebuggerStepThrough] - IReadOnlyList IConventionEntityTypeBuilder.GetOrCreateProperties( - IEnumerable memberInfos, + IReadOnlyList? IConventionEntityTypeBuilder.GetOrCreateProperties( + IEnumerable? memberInfos, bool fromDataAnnotation) => GetOrCreateProperties(memberInfos, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); @@ -4561,7 +4573,7 @@ IConventionEntityTypeBuilder IConventionEntityTypeBuilder.RemoveUnusedImplicitPr /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [DebuggerStepThrough] - IConventionServicePropertyBuilder IConventionEntityTypeBuilder.ServiceProperty(MemberInfo memberInfo, bool fromDataAnnotation) + IConventionServicePropertyBuilder? IConventionEntityTypeBuilder.ServiceProperty(MemberInfo memberInfo, bool fromDataAnnotation) => ServiceProperty(memberInfo, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// @@ -4580,7 +4592,7 @@ bool IConventionEntityTypeBuilder.IsIgnored(string name, bool fromDataAnnotation /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [DebuggerStepThrough] - IConventionEntityTypeBuilder IConventionEntityTypeBuilder.Ignore(string name, bool fromDataAnnotation) + IConventionEntityTypeBuilder? IConventionEntityTypeBuilder.Ignore(string name, bool fromDataAnnotation) => Ignore(name, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// @@ -4600,8 +4612,8 @@ bool IConventionEntityTypeBuilder.CanIgnore(string name, bool fromDataAnnotation /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [DebuggerStepThrough] - IConventionKeyBuilder IConventionEntityTypeBuilder.PrimaryKey( - IReadOnlyList properties, + IConventionKeyBuilder? IConventionEntityTypeBuilder.PrimaryKey( + IReadOnlyList? properties, bool fromDataAnnotation) => PrimaryKey( properties as IReadOnlyList ?? properties?.Cast().ToList(), @@ -4614,7 +4626,7 @@ IConventionKeyBuilder IConventionEntityTypeBuilder.PrimaryKey( /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [DebuggerStepThrough] - bool IConventionEntityTypeBuilder.CanSetPrimaryKey(IReadOnlyList properties, bool fromDataAnnotation) + bool IConventionEntityTypeBuilder.CanSetPrimaryKey(IReadOnlyList? properties, bool fromDataAnnotation) => CanSetPrimaryKey( properties as IReadOnlyList ?? properties?.Cast().ToList(), fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); @@ -4626,7 +4638,7 @@ bool IConventionEntityTypeBuilder.CanSetPrimaryKey(IReadOnlyList [DebuggerStepThrough] - IConventionKeyBuilder IConventionEntityTypeBuilder.HasKey(IReadOnlyList properties, bool fromDataAnnotation) + IConventionKeyBuilder? IConventionEntityTypeBuilder.HasKey(IReadOnlyList properties, bool fromDataAnnotation) => HasKey( properties as IReadOnlyList ?? properties.Cast().ToList(), fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); @@ -4638,7 +4650,7 @@ IConventionKeyBuilder IConventionEntityTypeBuilder.HasKey(IReadOnlyList [DebuggerStepThrough] - IConventionEntityTypeBuilder IConventionEntityTypeBuilder.HasNoKey(bool fromDataAnnotation) + IConventionEntityTypeBuilder? IConventionEntityTypeBuilder.HasNoKey(bool fromDataAnnotation) => HasNoKey(fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// @@ -4648,7 +4660,7 @@ IConventionEntityTypeBuilder IConventionEntityTypeBuilder.HasNoKey(bool fromData /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [DebuggerStepThrough] - IConventionEntityTypeBuilder IConventionEntityTypeBuilder.HasNoKey( + IConventionEntityTypeBuilder? IConventionEntityTypeBuilder.HasNoKey( IReadOnlyList properties, bool fromDataAnnotation) { @@ -4667,7 +4679,7 @@ IConventionEntityTypeBuilder IConventionEntityTypeBuilder.HasNoKey( /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [DebuggerStepThrough] - bool IConventionEntityTypeBuilder.CanRemoveKey([NotNull] IConventionKey key, bool fromDataAnnotation) + bool IConventionEntityTypeBuilder.CanRemoveKey(IConventionKey key, bool fromDataAnnotation) => CanRemoveKey((Key)key, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// @@ -4677,7 +4689,7 @@ bool IConventionEntityTypeBuilder.CanRemoveKey([NotNull] IConventionKey key, boo /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [DebuggerStepThrough] - IConventionEntityTypeBuilder IConventionEntityTypeBuilder.HasNoKey(IConventionKey key, bool fromDataAnnotation) + IConventionEntityTypeBuilder? IConventionEntityTypeBuilder.HasNoKey(IConventionKey key, bool fromDataAnnotation) => HasNoKey((Key)key, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// @@ -4697,7 +4709,7 @@ bool IConventionEntityTypeBuilder.CanRemoveKey(bool fromDataAnnotation) /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [DebuggerStepThrough] - IConventionIndexBuilder IConventionEntityTypeBuilder.HasIndex( + IConventionIndexBuilder? IConventionEntityTypeBuilder.HasIndex( IReadOnlyList propertyNames, bool fromDataAnnotation) => HasIndex( @@ -4711,7 +4723,7 @@ IConventionIndexBuilder IConventionEntityTypeBuilder.HasIndex( /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [DebuggerStepThrough] - IConventionIndexBuilder IConventionEntityTypeBuilder.HasIndex( + IConventionIndexBuilder? IConventionEntityTypeBuilder.HasIndex( IReadOnlyList propertyNames, string name, bool fromDataAnnotation) @@ -4727,7 +4739,7 @@ IConventionIndexBuilder IConventionEntityTypeBuilder.HasIndex( /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [DebuggerStepThrough] - IConventionIndexBuilder IConventionEntityTypeBuilder.HasIndex( + IConventionIndexBuilder? IConventionEntityTypeBuilder.HasIndex( IReadOnlyList properties, bool fromDataAnnotation) => HasIndex( @@ -4740,7 +4752,7 @@ IConventionIndexBuilder IConventionEntityTypeBuilder.HasIndex( /// 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. /// - IConventionIndexBuilder IConventionEntityTypeBuilder.HasIndex( + IConventionIndexBuilder? IConventionEntityTypeBuilder.HasIndex( IReadOnlyList properties, string name, bool fromDataAnnotation) @@ -4756,7 +4768,7 @@ IConventionIndexBuilder IConventionEntityTypeBuilder.HasIndex( /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [DebuggerStepThrough] - IConventionEntityTypeBuilder IConventionEntityTypeBuilder.HasNoIndex( + IConventionEntityTypeBuilder? IConventionEntityTypeBuilder.HasNoIndex( IReadOnlyList properties, bool fromDataAnnotation) { @@ -4775,7 +4787,7 @@ IConventionEntityTypeBuilder IConventionEntityTypeBuilder.HasNoIndex( /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [DebuggerStepThrough] - IConventionEntityTypeBuilder IConventionEntityTypeBuilder.HasNoIndex(IConventionIndex index, bool fromDataAnnotation) + IConventionEntityTypeBuilder? IConventionEntityTypeBuilder.HasNoIndex(IConventionIndex index, bool fromDataAnnotation) => HasNoIndex((Index)index, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// @@ -4785,7 +4797,7 @@ IConventionEntityTypeBuilder IConventionEntityTypeBuilder.HasNoIndex(IConvention /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [DebuggerStepThrough] - bool IConventionEntityTypeBuilder.CanRemoveIndex([NotNull] IConventionIndex index, bool fromDataAnnotation) + bool IConventionEntityTypeBuilder.CanRemoveIndex(IConventionIndex index, bool fromDataAnnotation) => CanRemoveIndex((Index)index, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// @@ -4795,7 +4807,7 @@ bool IConventionEntityTypeBuilder.CanRemoveIndex([NotNull] IConventionIndex inde /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [DebuggerStepThrough] - IConventionForeignKeyBuilder IConventionEntityTypeBuilder.HasRelationship( + IConventionForeignKeyBuilder? IConventionEntityTypeBuilder.HasRelationship( IConventionEntityType targetEntityType, bool fromDataAnnotation) => HasRelationship( @@ -4808,7 +4820,7 @@ IConventionForeignKeyBuilder IConventionEntityTypeBuilder.HasRelationship( /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [DebuggerStepThrough] - IConventionForeignKeyBuilder IConventionEntityTypeBuilder.HasRelationship( + IConventionForeignKeyBuilder? IConventionEntityTypeBuilder.HasRelationship( IConventionEntityType principalEntityType, IReadOnlyList dependentProperties, bool fromDataAnnotation) @@ -4824,7 +4836,7 @@ IConventionForeignKeyBuilder IConventionEntityTypeBuilder.HasRelationship( /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [DebuggerStepThrough] - IConventionForeignKeyBuilder IConventionEntityTypeBuilder.HasRelationship( + IConventionForeignKeyBuilder? IConventionEntityTypeBuilder.HasRelationship( IConventionEntityType principalEntityType, IConventionKey principalKey, bool fromDataAnnotation) @@ -4840,7 +4852,7 @@ IConventionForeignKeyBuilder IConventionEntityTypeBuilder.HasRelationship( /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [DebuggerStepThrough] - IConventionForeignKeyBuilder IConventionEntityTypeBuilder.HasRelationship( + IConventionForeignKeyBuilder? IConventionEntityTypeBuilder.HasRelationship( IConventionEntityType principalEntityType, IReadOnlyList dependentProperties, IConventionKey principalKey, @@ -4858,7 +4870,7 @@ IConventionForeignKeyBuilder IConventionEntityTypeBuilder.HasRelationship( /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [DebuggerStepThrough] - IConventionForeignKeyBuilder IConventionEntityTypeBuilder.HasRelationship( + IConventionForeignKeyBuilder? IConventionEntityTypeBuilder.HasRelationship( IConventionEntityType targetEntityType, string navigationName, bool setTargetAsPrincipal, @@ -4876,7 +4888,7 @@ IConventionForeignKeyBuilder IConventionEntityTypeBuilder.HasRelationship( /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [DebuggerStepThrough] - IConventionForeignKeyBuilder IConventionEntityTypeBuilder.HasRelationship( + IConventionForeignKeyBuilder? IConventionEntityTypeBuilder.HasRelationship( IConventionEntityType targetEntityType, MemberInfo navigation, bool setTargetAsPrincipal, @@ -4894,10 +4906,10 @@ IConventionForeignKeyBuilder IConventionEntityTypeBuilder.HasRelationship( /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [DebuggerStepThrough] - IConventionForeignKeyBuilder IConventionEntityTypeBuilder.HasRelationship( + IConventionForeignKeyBuilder? IConventionEntityTypeBuilder.HasRelationship( IConventionEntityType targetEntityType, string navigationName, - string inverseNavigationName, + string? inverseNavigationName, bool setTargetAsPrincipal, bool fromDataAnnotation) => HasRelationship( @@ -4913,10 +4925,10 @@ IConventionForeignKeyBuilder IConventionEntityTypeBuilder.HasRelationship( /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [DebuggerStepThrough] - IConventionForeignKeyBuilder IConventionEntityTypeBuilder.HasRelationship( + IConventionForeignKeyBuilder? IConventionEntityTypeBuilder.HasRelationship( IConventionEntityType targetEntityType, MemberInfo navigation, - MemberInfo inverseNavigation, + MemberInfo? inverseNavigation, bool setTargetAsPrincipal, bool fromDataAnnotation) => HasRelationship( @@ -4927,7 +4939,7 @@ IConventionForeignKeyBuilder IConventionEntityTypeBuilder.HasRelationship( /// [DebuggerStepThrough] - IConventionSkipNavigationBuilder IConventionEntityTypeBuilder.HasSkipNavigation( + IConventionSkipNavigationBuilder? IConventionEntityTypeBuilder.HasSkipNavigation( MemberInfo navigation, IConventionEntityType targetEntityType, MemberInfo inverseNavigation, @@ -4949,7 +4961,7 @@ IConventionSkipNavigationBuilder IConventionEntityTypeBuilder.HasSkipNavigation( /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [DebuggerStepThrough] - IConventionForeignKeyBuilder IConventionEntityTypeBuilder.HasOwnership( + IConventionForeignKeyBuilder? IConventionEntityTypeBuilder.HasOwnership( Type targetEntityType, string navigationName, bool fromDataAnnotation) @@ -4964,7 +4976,7 @@ IConventionForeignKeyBuilder IConventionEntityTypeBuilder.HasOwnership( /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [DebuggerStepThrough] - IConventionForeignKeyBuilder IConventionEntityTypeBuilder.HasOwnership( + IConventionForeignKeyBuilder? IConventionEntityTypeBuilder.HasOwnership( Type targetEntityType, MemberInfo navigation, bool fromDataAnnotation) @@ -4979,10 +4991,10 @@ IConventionForeignKeyBuilder IConventionEntityTypeBuilder.HasOwnership( /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [DebuggerStepThrough] - IConventionForeignKeyBuilder IConventionEntityTypeBuilder.HasOwnership( + IConventionForeignKeyBuilder? IConventionEntityTypeBuilder.HasOwnership( Type targetEntityType, string navigationName, - string inversePropertyName, + string? inversePropertyName, bool fromDataAnnotation) => HasOwnership( targetEntityType, navigationName, inversePropertyName, @@ -4995,10 +5007,10 @@ IConventionForeignKeyBuilder IConventionEntityTypeBuilder.HasOwnership( /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [DebuggerStepThrough] - IConventionForeignKeyBuilder IConventionEntityTypeBuilder.HasOwnership( + IConventionForeignKeyBuilder? IConventionEntityTypeBuilder.HasOwnership( Type targetEntityType, MemberInfo navigation, - MemberInfo inverseProperty, + MemberInfo? inverseProperty, bool fromDataAnnotation) => HasOwnership( targetEntityType, navigation, inverseProperty, @@ -5011,7 +5023,7 @@ IConventionForeignKeyBuilder IConventionEntityTypeBuilder.HasOwnership( /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [DebuggerStepThrough] - IConventionEntityTypeBuilder IConventionEntityTypeBuilder.HasNoRelationship( + IConventionEntityTypeBuilder? IConventionEntityTypeBuilder.HasNoRelationship( IReadOnlyList properties, IConventionKey principalKey, IConventionEntityType principalEntityType, @@ -5034,7 +5046,7 @@ IConventionEntityTypeBuilder IConventionEntityTypeBuilder.HasNoRelationship( /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [DebuggerStepThrough] - IConventionEntityTypeBuilder IConventionEntityTypeBuilder.HasNoRelationship( + IConventionEntityTypeBuilder? IConventionEntityTypeBuilder.HasNoRelationship( IConventionForeignKey foreignKey, bool fromDataAnnotation) => HasNoRelationship( @@ -5048,7 +5060,7 @@ IConventionEntityTypeBuilder IConventionEntityTypeBuilder.HasNoRelationship( /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [DebuggerStepThrough] - bool IConventionEntityTypeBuilder.CanRemoveRelationship([NotNull] IConventionForeignKey foreignKey, bool fromDataAnnotation) + bool IConventionEntityTypeBuilder.CanRemoveRelationship(IConventionForeignKey foreignKey, bool fromDataAnnotation) => CanRemoveForeignKey( (ForeignKey)foreignKey, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); @@ -5079,7 +5091,7 @@ bool IConventionEntityTypeBuilder.CanHaveSkipNavigation(string skipNavigationNam /// [DebuggerStepThrough] - IConventionSkipNavigationBuilder IConventionEntityTypeBuilder.HasSkipNavigation( + IConventionSkipNavigationBuilder? IConventionEntityTypeBuilder.HasSkipNavigation( MemberInfo navigation, IConventionEntityType targetEntityType, bool? collection, @@ -5094,7 +5106,7 @@ IConventionSkipNavigationBuilder IConventionEntityTypeBuilder.HasSkipNavigation( /// [DebuggerStepThrough] - IConventionSkipNavigationBuilder IConventionEntityTypeBuilder.HasSkipNavigation( + IConventionSkipNavigationBuilder? IConventionEntityTypeBuilder.HasSkipNavigation( string navigationName, IConventionEntityType targetEntityType, bool? collection, @@ -5109,7 +5121,7 @@ IConventionSkipNavigationBuilder IConventionEntityTypeBuilder.HasSkipNavigation( /// [DebuggerStepThrough] - IConventionEntityTypeBuilder IConventionEntityTypeBuilder.HasNoSkipNavigation( + IConventionEntityTypeBuilder? IConventionEntityTypeBuilder.HasNoSkipNavigation( ISkipNavigation skipNavigation, bool fromDataAnnotation) => HasNoSkipNavigation( @@ -5130,7 +5142,7 @@ bool IConventionEntityTypeBuilder.CanRemoveSkipNavigation(ISkipNavigation skipNa /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [DebuggerStepThrough] - IConventionEntityTypeBuilder IConventionEntityTypeBuilder.HasQueryFilter(LambdaExpression filter, bool fromDataAnnotation) + IConventionEntityTypeBuilder? IConventionEntityTypeBuilder.HasQueryFilter(LambdaExpression? filter, bool fromDataAnnotation) => HasQueryFilter(filter, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// @@ -5140,7 +5152,7 @@ IConventionEntityTypeBuilder IConventionEntityTypeBuilder.HasQueryFilter(LambdaE /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [DebuggerStepThrough] - bool IConventionEntityTypeBuilder.CanSetQueryFilter(LambdaExpression filter, bool fromDataAnnotation) + bool IConventionEntityTypeBuilder.CanSetQueryFilter(LambdaExpression? filter, bool fromDataAnnotation) => CanSetQueryFilter(filter, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// @@ -5151,7 +5163,7 @@ bool IConventionEntityTypeBuilder.CanSetQueryFilter(LambdaExpression filter, boo /// [DebuggerStepThrough] [Obsolete] - IConventionEntityTypeBuilder IConventionEntityTypeBuilder.HasDefiningQuery(LambdaExpression query, bool fromDataAnnotation) + IConventionEntityTypeBuilder? IConventionEntityTypeBuilder.HasDefiningQuery(LambdaExpression? query, bool fromDataAnnotation) => HasDefiningQuery(query, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// @@ -5162,7 +5174,7 @@ IConventionEntityTypeBuilder IConventionEntityTypeBuilder.HasDefiningQuery(Lambd /// [DebuggerStepThrough] [Obsolete] - bool IConventionEntityTypeBuilder.CanSetDefiningQuery(LambdaExpression query, bool fromDataAnnotation) + bool IConventionEntityTypeBuilder.CanSetDefiningQuery(LambdaExpression? query, bool fromDataAnnotation) => CanSetDefiningQuery(query, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// @@ -5172,7 +5184,7 @@ bool IConventionEntityTypeBuilder.CanSetDefiningQuery(LambdaExpression query, bo /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [DebuggerStepThrough] - IConventionEntityTypeBuilder IConventionEntityTypeBuilder.HasChangeTrackingStrategy( + IConventionEntityTypeBuilder? IConventionEntityTypeBuilder.HasChangeTrackingStrategy( ChangeTrackingStrategy? changeTrackingStrategy, bool fromDataAnnotation) => HasChangeTrackingStrategy( @@ -5198,7 +5210,7 @@ bool IConventionEntityTypeBuilder.CanSetChangeTrackingStrategy( /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [DebuggerStepThrough] - IConventionEntityTypeBuilder IConventionEntityTypeBuilder.UsePropertyAccessMode( + IConventionEntityTypeBuilder? IConventionEntityTypeBuilder.UsePropertyAccessMode( PropertyAccessMode? propertyAccessMode, bool fromDataAnnotation) => UsePropertyAccessMode( @@ -5222,7 +5234,7 @@ bool IConventionEntityTypeBuilder.CanSetPropertyAccessMode(PropertyAccessMode? p /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [DebuggerStepThrough] - IConventionDiscriminatorBuilder IConventionEntityTypeBuilder.HasDiscriminator(bool fromDataAnnotation) + IConventionDiscriminatorBuilder? IConventionEntityTypeBuilder.HasDiscriminator(bool fromDataAnnotation) => HasDiscriminator( fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); @@ -5233,7 +5245,7 @@ IConventionDiscriminatorBuilder IConventionEntityTypeBuilder.HasDiscriminator(bo /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [DebuggerStepThrough] - IConventionDiscriminatorBuilder IConventionEntityTypeBuilder.HasDiscriminator(Type type, bool fromDataAnnotation) + IConventionDiscriminatorBuilder? IConventionEntityTypeBuilder.HasDiscriminator(Type type, bool fromDataAnnotation) => HasDiscriminator( name: null, Check.NotNull(type, nameof(type)), fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); @@ -5245,7 +5257,7 @@ IConventionDiscriminatorBuilder IConventionEntityTypeBuilder.HasDiscriminator(Ty /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [DebuggerStepThrough] - IConventionDiscriminatorBuilder IConventionEntityTypeBuilder.HasDiscriminator(string name, bool fromDataAnnotation) + IConventionDiscriminatorBuilder? IConventionEntityTypeBuilder.HasDiscriminator(string name, bool fromDataAnnotation) => HasDiscriminator( Check.NotEmpty(name, nameof(name)), type: null, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); @@ -5257,7 +5269,7 @@ IConventionDiscriminatorBuilder IConventionEntityTypeBuilder.HasDiscriminator(st /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [DebuggerStepThrough] - IConventionDiscriminatorBuilder IConventionEntityTypeBuilder.HasDiscriminator(string name, Type type, bool fromDataAnnotation) + IConventionDiscriminatorBuilder? IConventionEntityTypeBuilder.HasDiscriminator(string name, Type type, bool fromDataAnnotation) => HasDiscriminator( Check.NotEmpty(name, nameof(name)), Check.NotNull(type, nameof(type)), fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); @@ -5269,7 +5281,7 @@ IConventionDiscriminatorBuilder IConventionEntityTypeBuilder.HasDiscriminator(st /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [DebuggerStepThrough] - IConventionDiscriminatorBuilder IConventionEntityTypeBuilder.HasDiscriminator(MemberInfo memberInfo, bool fromDataAnnotation) + IConventionDiscriminatorBuilder? IConventionEntityTypeBuilder.HasDiscriminator(MemberInfo memberInfo, bool fromDataAnnotation) => HasDiscriminator( memberInfo, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); @@ -5280,7 +5292,7 @@ IConventionDiscriminatorBuilder IConventionEntityTypeBuilder.HasDiscriminator(Me /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [DebuggerStepThrough] - IConventionEntityTypeBuilder IConventionEntityTypeBuilder.HasNoDiscriminator(bool fromDataAnnotation) + IConventionEntityTypeBuilder? IConventionEntityTypeBuilder.HasNoDiscriminator(bool fromDataAnnotation) => HasNoDiscriminator(fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// @@ -5326,7 +5338,7 @@ bool IConventionEntityTypeBuilder.CanSetDiscriminator(string name, Type type, bo /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [DebuggerStepThrough] - bool IConventionEntityTypeBuilder.CanSetDiscriminator([NotNull] MemberInfo memberInfo, bool fromDataAnnotation) + bool IConventionEntityTypeBuilder.CanSetDiscriminator(MemberInfo memberInfo, bool fromDataAnnotation) => CanSetDiscriminator( Check.NotNull(memberInfo, nameof(memberInfo)).GetSimpleMemberName(), memberInfo.GetMemberType(), fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); @@ -5343,7 +5355,7 @@ bool IConventionEntityTypeBuilder.CanRemoveDiscriminator(bool fromDataAnnotation /// [DebuggerStepThrough] - IConventionPropertyBuilder IConventionEntityTypeBuilder.CreateUniqueProperty( + IConventionPropertyBuilder? IConventionEntityTypeBuilder.CreateUniqueProperty( Type propertyType, string basePropertyName, bool required) diff --git a/src/EFCore/Metadata/Internal/InternalForeignKeyBuilder.cs b/src/EFCore/Metadata/Internal/InternalForeignKeyBuilder.cs index 65aa3fb94f5..b4635cb3953 100644 --- a/src/EFCore/Metadata/Internal/InternalForeignKeyBuilder.cs +++ b/src/EFCore/Metadata/Internal/InternalForeignKeyBuilder.cs @@ -14,6 +14,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Internal { /// @@ -43,8 +45,8 @@ public InternalForeignKeyBuilder( /// 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. /// - public virtual InternalForeignKeyBuilder HasNavigation( - [CanBeNull] string name, + public virtual InternalForeignKeyBuilder? HasNavigation( + [CanBeNull] string? name, bool pointsToPrincipal, ConfigurationSource configurationSource) => pointsToPrincipal @@ -63,8 +65,8 @@ public virtual InternalForeignKeyBuilder HasNavigation( /// 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. /// - public virtual InternalForeignKeyBuilder HasNavigation( - [CanBeNull] MemberInfo property, + public virtual InternalForeignKeyBuilder? HasNavigation( + [CanBeNull] MemberInfo? property, bool pointsToPrincipal, ConfigurationSource configurationSource) => pointsToPrincipal @@ -83,9 +85,9 @@ public virtual InternalForeignKeyBuilder HasNavigation( /// 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. /// - public virtual InternalForeignKeyBuilder HasNavigations( - [CanBeNull] string navigationToPrincipalName, - [CanBeNull] string navigationToDependentName, + public virtual InternalForeignKeyBuilder? HasNavigations( + [CanBeNull] string? navigationToPrincipalName, + [CanBeNull] string? navigationToDependentName, ConfigurationSource configurationSource) => HasNavigations( MemberIdentity.Create(navigationToPrincipalName), @@ -98,9 +100,9 @@ public virtual InternalForeignKeyBuilder HasNavigations( /// 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. /// - public virtual InternalForeignKeyBuilder HasNavigations( - [CanBeNull] MemberInfo navigationToPrincipal, - [CanBeNull] MemberInfo navigationToDependent, + public virtual InternalForeignKeyBuilder? HasNavigations( + [CanBeNull] MemberInfo? navigationToPrincipal, + [CanBeNull] MemberInfo? navigationToDependent, ConfigurationSource configurationSource) => HasNavigations( MemberIdentity.Create(navigationToPrincipal), @@ -113,7 +115,7 @@ public virtual InternalForeignKeyBuilder HasNavigations( /// 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. /// - public virtual InternalForeignKeyBuilder HasNavigations( + public virtual InternalForeignKeyBuilder? HasNavigations( MemberIdentity? navigationToPrincipal, MemberIdentity? navigationToDependent, ConfigurationSource configurationSource) @@ -130,9 +132,9 @@ public virtual InternalForeignKeyBuilder HasNavigations( /// 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. /// - public virtual InternalForeignKeyBuilder HasNavigations( - [CanBeNull] string navigationToPrincipalName, - [CanBeNull] string navigationToDependentName, + public virtual InternalForeignKeyBuilder? HasNavigations( + [CanBeNull] string? navigationToPrincipalName, + [CanBeNull] string? navigationToDependentName, [NotNull] EntityType principalEntityType, [NotNull] EntityType dependentEntityType, ConfigurationSource configurationSource) @@ -149,9 +151,9 @@ public virtual InternalForeignKeyBuilder HasNavigations( /// 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. /// - public virtual InternalForeignKeyBuilder HasNavigations( - [CanBeNull] MemberInfo navigationToPrincipal, - [CanBeNull] MemberInfo navigationToDependent, + public virtual InternalForeignKeyBuilder? HasNavigations( + [CanBeNull] MemberInfo? navigationToPrincipal, + [CanBeNull] MemberInfo? navigationToDependent, [NotNull] EntityType principalEntityType, [NotNull] EntityType dependentEntityType, ConfigurationSource configurationSource) @@ -162,7 +164,7 @@ public virtual InternalForeignKeyBuilder HasNavigations( dependentEntityType, configurationSource); - private InternalForeignKeyBuilder HasNavigations( + private InternalForeignKeyBuilder? HasNavigations( MemberIdentity? navigationToPrincipal, MemberIdentity? navigationToDependent, EntityType principalEntityType, @@ -201,7 +203,7 @@ private InternalForeignKeyBuilder HasNavigations( var shouldThrow = configurationSource == ConfigurationSource.Explicit; if (navigationToPrincipalName != null - && navigationToPrincipal.Value.MemberInfo == null + && navigationToPrincipal!.Value.MemberInfo == null && dependentEntityType.ClrType != Model.DefaultPropertyBagType) { var navigationProperty = FindCompatibleClrMember( @@ -213,7 +215,7 @@ private InternalForeignKeyBuilder HasNavigations( } if (navigationToDependentName != null - && navigationToDependent.Value.MemberInfo == null + && navigationToDependent!.Value.MemberInfo == null && principalEntityType.ClrType != Model.DefaultPropertyBagType) { var navigationProperty = FindCompatibleClrMember( @@ -253,8 +255,8 @@ private InternalForeignKeyBuilder HasNavigations( } } - IReadOnlyList dependentProperties = null; - IReadOnlyList principalProperties = null; + IReadOnlyList? dependentProperties = null; + IReadOnlyList? principalProperties = null; if (shouldInvert == true) { Check.DebugAssert( @@ -313,7 +315,7 @@ private InternalForeignKeyBuilder HasNavigations( } var inverse = conflictingSkipNavigation.Inverse; - if (inverse?.Builder != null + if (inverse?.IsInModel == true && inverse.GetConfigurationSource() != ConfigurationSource.Explicit) { inverse.DeclaringEntityType.Builder.HasNoSkipNavigation(conflictingSkipNavigation, configurationSource); @@ -350,7 +352,7 @@ private InternalForeignKeyBuilder HasNavigations( } var inverse = conflictingSkipNavigation.Inverse; - if (inverse?.Builder != null + if (inverse?.IsInModel == true && inverse.GetConfigurationSource() != ConfigurationSource.Explicit) { inverse.DeclaringEntityType.Builder.HasNoSkipNavigation(inverse, configurationSource); @@ -361,7 +363,7 @@ private InternalForeignKeyBuilder HasNavigations( } } - InternalForeignKeyBuilder builder; + InternalForeignKeyBuilder? builder; if (shouldInvert == true || conflictingNavigationsFound || changeRelatedTypes) @@ -384,7 +386,7 @@ private InternalForeignKeyBuilder HasNavigations( return null; } - Check.DebugAssert(builder.Metadata.Builder != null, "builder.Metadata.Builder is null"); + Check.DebugAssert(builder.Metadata.IsInModel, "builder.Metadata isn't in the model"); } else { @@ -397,7 +399,7 @@ private InternalForeignKeyBuilder HasNavigations( { if (navigationToDependent != null) { - Metadata.HasPrincipalToDependent((string)null, configurationSource); + Metadata.HasPrincipalToDependent((string?)null, configurationSource); } var navigationProperty = navigationToPrincipal.Value.MemberInfo; @@ -466,7 +468,7 @@ private InternalForeignKeyBuilder HasNavigations( : builder; } - private static MemberInfo FindCompatibleClrMember( + private static MemberInfo? FindCompatibleClrMember( string navigationName, EntityType sourceType, EntityType targetType, @@ -485,7 +487,7 @@ private static MemberInfo FindCompatibleClrMember( /// doing so can result in application failures when updating to a new Entity Framework Core release. /// public virtual bool CanSetNavigation( - [CanBeNull] MemberInfo property, + [CanBeNull] MemberInfo? property, bool pointsToPrincipal, ConfigurationSource? configurationSource) => CanSetNavigation( @@ -504,7 +506,7 @@ public virtual bool CanSetNavigation( /// doing so can result in application failures when updating to a new Entity Framework Core release. /// public virtual bool CanSetNavigation( - [CanBeNull] string name, + [CanBeNull] string? name, bool pointsToPrincipal, ConfigurationSource? configurationSource) => CanSetNavigation( @@ -551,8 +553,8 @@ private bool CanSetNavigation( /// doing so can result in application failures when updating to a new Entity Framework Core release. /// public virtual bool CanSetNavigations( - [CanBeNull] MemberInfo navigationToPrincipal, - [CanBeNull] MemberInfo navigationToDependent, + [CanBeNull] MemberInfo? navigationToPrincipal, + [CanBeNull] MemberInfo? navigationToDependent, ConfigurationSource? configurationSource) => CanSetNavigations( MemberIdentity.Create(navigationToPrincipal), @@ -571,8 +573,8 @@ public virtual bool CanSetNavigations( /// doing so can result in application failures when updating to a new Entity Framework Core release. /// public virtual bool CanSetNavigations( - [CanBeNull] string navigationToPrincipalName, - [CanBeNull] string navigationToDependentName, + [CanBeNull] string? navigationToPrincipalName, + [CanBeNull] string? navigationToDependentName, ConfigurationSource? configurationSource) => CanSetNavigations( MemberIdentity.Create(navigationToPrincipalName), @@ -800,7 +802,7 @@ private bool CanSetNavigations( null, Metadata.GetPrincipalEndConfigurationSource(), configurationSource, - out var _, + out _, out var conflictingRelationshipsFound, out var resolvableRelationships); @@ -933,7 +935,7 @@ private static bool IsCompatible( /// 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. /// - public virtual InternalForeignKeyBuilder IsRequired(bool? required, ConfigurationSource configurationSource) + public virtual InternalForeignKeyBuilder? IsRequired(bool? required, ConfigurationSource configurationSource) { if (!CanSetIsRequired(required, configurationSource)) { @@ -968,7 +970,7 @@ public virtual bool CanSetIsRequired(bool? required, ConfigurationSource? config /// 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. /// - public virtual InternalForeignKeyBuilder IsRequiredDependent(bool? required, ConfigurationSource configurationSource) + public virtual InternalForeignKeyBuilder? IsRequiredDependent(bool? required, ConfigurationSource configurationSource) { if (!CanSetIsRequiredDependent(required, configurationSource)) { @@ -1006,7 +1008,7 @@ public virtual bool CanSetIsRequiredDependent(bool? required, ConfigurationSourc => Metadata.IsRequiredDependent == required || ((required != true || Metadata.IsUnique - || configurationSource.Value.Overrides(Metadata.GetIsUniqueConfigurationSource())) + || configurationSource!.Value.Overrides(Metadata.GetIsUniqueConfigurationSource())) && configurationSource.Overrides(Metadata.GetIsRequiredDependentConfigurationSource())); /// @@ -1015,7 +1017,7 @@ public virtual bool CanSetIsRequiredDependent(bool? required, ConfigurationSourc /// 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. /// - public virtual InternalForeignKeyBuilder IsOwnership(bool? ownership, ConfigurationSource configurationSource) + public virtual InternalForeignKeyBuilder? IsOwnership(bool? ownership, ConfigurationSource configurationSource) { if (Metadata.IsOwnership == ownership) { @@ -1059,14 +1061,14 @@ public virtual InternalForeignKeyBuilder IsOwnership(bool? ownership, Configurat return null; } - if (otherOwnership?.Builder != null) + if (otherOwnership?.IsInModel == true) { otherOwnership.DeclaringEntityType.Builder.HasNoRelationship(otherOwnership, configurationSource); } foreach (var invertedOwnership in invertedOwnerships) { - if (invertedOwnership.Builder != null) + if (invertedOwnership.IsInModel) { invertedOwnership.DeclaringEntityType.Builder.HasNoRelationship(invertedOwnership, configurationSource); } @@ -1106,14 +1108,14 @@ public virtual InternalForeignKeyBuilder IsOwnership(bool? ownership, Configurat return null; } - var name = Metadata.PrincipalEntityType.GetOwnedName(declaringType.ShortName(), Metadata.PrincipalToDependent.Name); + var name = Metadata.PrincipalEntityType.GetOwnedName(declaringType.ShortName(), Metadata.PrincipalToDependent!.Name); var newEntityType = ModelBuilder.SharedTypeEntity( name, declaringType.ClrType, declaringType.GetConfigurationSource(), - shouldBeOwned: true).Metadata; + shouldBeOwned: true)!.Metadata; - newRelationshipBuilder = newRelationshipBuilder.Attach(newEntityType.Builder); + newRelationshipBuilder = newRelationshipBuilder.Attach(newEntityType.Builder)!; ModelBuilder.Metadata.ConventionDispatcher.Tracker.Update( Metadata, newRelationshipBuilder.Metadata); @@ -1132,7 +1134,7 @@ public virtual InternalForeignKeyBuilder IsOwnership(bool? ownership, Configurat invertedOwnership.DeclaringEntityType.Builder.HasNoRelationship(invertedOwnership, configurationSource); } - newRelationshipBuilder.Metadata.DeclaringEntityType.Builder.HasBaseType((Type)null, configurationSource); + newRelationshipBuilder.Metadata.DeclaringEntityType.Builder.HasBaseType((Type?)null, configurationSource); if (!newRelationshipBuilder.Metadata.DeclaringEntityType.Builder .RemoveNonOwnershipRelationships(newRelationshipBuilder.Metadata, configurationSource)) @@ -1164,7 +1166,7 @@ public virtual bool CanSetIsOwnership(bool? ownership, ConfigurationSource? conf /// 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. /// - public virtual InternalForeignKeyBuilder MakeDeclaringTypeShared(ConfigurationSource? configurationSource) + public virtual InternalForeignKeyBuilder? MakeDeclaringTypeShared(ConfigurationSource? configurationSource) { if (Metadata.DeclaringEntityType.HasSharedClrType) { @@ -1184,16 +1186,16 @@ public virtual InternalForeignKeyBuilder MakeDeclaringTypeShared(ConfigurationSo name, Metadata.DeclaringEntityType.ClrType, configurationSource.Value, - shouldBeOwned: true).Metadata; + shouldBeOwned: true)!.Metadata; var newOwnership = newEntityType.GetForeignKeys().SingleOrDefault(fk => fk.IsOwnership); if (newOwnership == null) { - Check.DebugAssert(Metadata.Builder != null, "Metadata.Builder is null"); + Check.DebugAssert(Metadata.IsInModel, "Metadata isn't in the model"); return Metadata.Builder; } - Check.DebugAssert(Metadata.Builder == null, "Metadata.Builder is not null"); + Check.DebugAssert(!Metadata.IsInModel, "Metadata is in the model"); ModelBuilder.Metadata.ConventionDispatcher.Tracker.Update(Metadata, newOwnership); return newOwnership.Builder; } @@ -1204,7 +1206,7 @@ public virtual InternalForeignKeyBuilder MakeDeclaringTypeShared(ConfigurationSo /// 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. /// - public virtual InternalForeignKeyBuilder OnDelete(DeleteBehavior? deleteBehavior, ConfigurationSource configurationSource) + public virtual InternalForeignKeyBuilder? OnDelete(DeleteBehavior? deleteBehavior, ConfigurationSource configurationSource) { if (!CanSetDeleteBehavior(deleteBehavior, configurationSource)) { @@ -1231,7 +1233,7 @@ public virtual bool CanSetDeleteBehavior(DeleteBehavior? deleteBehavior, Configu /// 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. /// - public virtual InternalForeignKeyBuilder IsUnique(bool? unique, ConfigurationSource configurationSource) + public virtual InternalForeignKeyBuilder? IsUnique(bool? unique, ConfigurationSource configurationSource) { if (Metadata.IsUnique == unique) { @@ -1246,12 +1248,12 @@ public virtual InternalForeignKeyBuilder IsUnique(bool? unique, ConfigurationSou } if (resetToDependent - && Metadata.PrincipalToDependent.GetConfigurationSource() == ConfigurationSource.Explicit) + && Metadata.PrincipalToDependent!.GetConfigurationSource() == ConfigurationSource.Explicit) { throw new InvalidOperationException( CoreStrings.UnableToSetIsUnique( - unique.Value, - Metadata.PrincipalToDependent.PropertyInfo.Name, + unique, + Metadata.PrincipalToDependent.PropertyInfo!.Name, Metadata.PrincipalEntityType.DisplayName())); } @@ -1310,7 +1312,7 @@ private bool CanSetIsUnique(bool? unique, ConfigurationSource? configurationSour if (Metadata.PrincipalToDependent?.IsShadowProperty() == false && !Navigation.IsCompatible( Metadata.PrincipalToDependent.Name, - Metadata.PrincipalToDependent.GetIdentifyingMemberInfo(), + Metadata.PrincipalToDependent.GetIdentifyingMemberInfo()!, Metadata.PrincipalEntityType, Metadata.DeclaringEntityType, !unique, @@ -1334,7 +1336,7 @@ private bool CanSetIsUnique(bool? unique, ConfigurationSource? configurationSour /// 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. /// - public virtual InternalForeignKeyBuilder DependentEntityType( + public virtual InternalForeignKeyBuilder? DependentEntityType( [NotNull] InternalEntityTypeBuilder dependentEntityTypeBuilder, ConfigurationSource configurationSource) => DependentEntityType(dependentEntityTypeBuilder.Metadata, configurationSource); @@ -1345,11 +1347,11 @@ public virtual InternalForeignKeyBuilder DependentEntityType( /// 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. /// - public virtual InternalForeignKeyBuilder DependentEntityType( + public virtual InternalForeignKeyBuilder? DependentEntityType( [NotNull] Type dependentType, ConfigurationSource configurationSource) => DependentEntityType( - ModelBuilder.Entity(dependentType, configurationSource).Metadata, + ModelBuilder.Entity(dependentType, configurationSource)!.Metadata, configurationSource); /// @@ -1358,10 +1360,10 @@ public virtual InternalForeignKeyBuilder DependentEntityType( /// 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. /// - public virtual InternalForeignKeyBuilder DependentEntityType( + public virtual InternalForeignKeyBuilder? DependentEntityType( [NotNull] string dependentTypeName, ConfigurationSource configurationSource) - => DependentEntityType(ModelBuilder.Entity(dependentTypeName, configurationSource).Metadata, configurationSource); + => DependentEntityType(ModelBuilder.Entity(dependentTypeName, configurationSource)!.Metadata, configurationSource); /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -1369,7 +1371,7 @@ public virtual InternalForeignKeyBuilder DependentEntityType( /// 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. /// - public virtual InternalForeignKeyBuilder DependentEntityType( + public virtual InternalForeignKeyBuilder? DependentEntityType( [NotNull] EntityType dependentEntityType, ConfigurationSource configurationSource) { @@ -1383,7 +1385,7 @@ public virtual InternalForeignKeyBuilder DependentEntityType( Metadata.UpdatePrincipalEndConfigurationSource(configurationSource); builder = - (InternalForeignKeyBuilder)ModelBuilder.Metadata.ConventionDispatcher.OnForeignKeyPrincipalEndChanged(builder); + (InternalForeignKeyBuilder?)ModelBuilder.Metadata.ConventionDispatcher.OnForeignKeyPrincipalEndChanged(builder); } return builder; @@ -1402,7 +1404,7 @@ public virtual InternalForeignKeyBuilder DependentEntityType( /// 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. /// - public virtual InternalForeignKeyBuilder PrincipalEntityType( + public virtual InternalForeignKeyBuilder? PrincipalEntityType( [NotNull] InternalEntityTypeBuilder principalEntityTypeBuilder, ConfigurationSource configurationSource) => PrincipalEntityType(principalEntityTypeBuilder.Metadata, configurationSource); @@ -1413,11 +1415,11 @@ public virtual InternalForeignKeyBuilder PrincipalEntityType( /// 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. /// - public virtual InternalForeignKeyBuilder PrincipalEntityType( + public virtual InternalForeignKeyBuilder? PrincipalEntityType( [NotNull] Type principalType, ConfigurationSource configurationSource) => PrincipalEntityType( - ModelBuilder.Entity(principalType, configurationSource).Metadata, + ModelBuilder.Entity(principalType, configurationSource)!.Metadata, configurationSource); /// @@ -1426,11 +1428,11 @@ public virtual InternalForeignKeyBuilder PrincipalEntityType( /// 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. /// - public virtual InternalForeignKeyBuilder PrincipalEntityType( + public virtual InternalForeignKeyBuilder? PrincipalEntityType( [NotNull] string principalTypeName, ConfigurationSource configurationSource) => PrincipalEntityType( - ModelBuilder.Entity(principalTypeName, configurationSource).Metadata, + ModelBuilder.Entity(principalTypeName, configurationSource)!.Metadata, configurationSource); /// @@ -1439,7 +1441,7 @@ public virtual InternalForeignKeyBuilder PrincipalEntityType( /// 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. /// - public virtual InternalForeignKeyBuilder PrincipalEntityType( + public virtual InternalForeignKeyBuilder? PrincipalEntityType( [NotNull] EntityType principalEntityType, ConfigurationSource configurationSource) { @@ -1453,7 +1455,7 @@ public virtual InternalForeignKeyBuilder PrincipalEntityType( Metadata.UpdatePrincipalEndConfigurationSource(configurationSource); builder = - (InternalForeignKeyBuilder)ModelBuilder.Metadata.ConventionDispatcher.OnForeignKeyPrincipalEndChanged(builder); + (InternalForeignKeyBuilder?)ModelBuilder.Metadata.ConventionDispatcher.OnForeignKeyPrincipalEndChanged(builder); } return builder; @@ -1471,13 +1473,13 @@ public virtual InternalForeignKeyBuilder PrincipalEntityType( /// 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. /// - public virtual InternalForeignKeyBuilder HasEntityTypes( + public virtual InternalForeignKeyBuilder? HasEntityTypes( [NotNull] EntityType principalEntityType, [NotNull] EntityType dependentEntityType, ConfigurationSource configurationSource) => HasEntityTypes(principalEntityType, dependentEntityType, configurationSource, configurationSource); - private InternalForeignKeyBuilder HasEntityTypes( + private InternalForeignKeyBuilder? HasEntityTypes( [NotNull] EntityType principalEntityType, [NotNull] EntityType dependentEntityType, ConfigurationSource? principalEndConfigurationSource, @@ -1499,7 +1501,7 @@ private InternalForeignKeyBuilder HasEntityTypes( principalEntityType.UpdateConfigurationSource(configurationSource); dependentEntityType.UpdateConfigurationSource(configurationSource); - return (InternalForeignKeyBuilder)ModelBuilder.Metadata.ConventionDispatcher.OnForeignKeyPrincipalEndChanged(this); + return (InternalForeignKeyBuilder?)ModelBuilder.Metadata.ConventionDispatcher.OnForeignKeyPrincipalEndChanged(this); } if (!CanSetRelatedTypes( @@ -1534,13 +1536,13 @@ private InternalForeignKeyBuilder HasEntityTypes( configurationSource.Overrides(Metadata.GetPrincipalKeyConfigurationSource()), "configurationSource does not override Metadata.GetPrincipalKeyConfigurationSource"); - principalEntityType = principalEntityType.LeastDerivedType(Metadata.DeclaringEntityType); - dependentEntityType = dependentEntityType.LeastDerivedType(Metadata.PrincipalEntityType); + principalEntityType = principalEntityType.LeastDerivedType(Metadata.DeclaringEntityType)!; + dependentEntityType = dependentEntityType.LeastDerivedType(Metadata.PrincipalEntityType)!; } else { - principalEntityType = principalEntityType.LeastDerivedType(Metadata.PrincipalEntityType); - dependentEntityType = dependentEntityType.LeastDerivedType(Metadata.DeclaringEntityType); + principalEntityType = principalEntityType.LeastDerivedType(Metadata.PrincipalEntityType)!; + dependentEntityType = dependentEntityType.LeastDerivedType(Metadata.DeclaringEntityType)!; dependentProperties = shouldResetDependentProperties ? dependentProperties @@ -1601,7 +1603,7 @@ public virtual bool CanSetEntityTypes( /// doing so can result in application failures when updating to a new Entity Framework Core release. /// public virtual bool CanInvert( - [CanBeNull] IReadOnlyList newForeignKeyProperties, + [CanBeNull] IReadOnlyList? newForeignKeyProperties, ConfigurationSource? configurationSource) => configurationSource.Overrides(Metadata.GetPrincipalEndConfigurationSource()) && ((newForeignKeyProperties == null) @@ -1613,7 +1615,7 @@ public virtual bool CanInvert( /// 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. /// - public virtual InternalForeignKeyBuilder ReuniquifyImplicitProperties(bool force) + public virtual InternalForeignKeyBuilder? ReuniquifyImplicitProperties(bool force) { if (!force && (Metadata.GetPropertiesConfigurationSource() != null @@ -1635,7 +1637,7 @@ public virtual InternalForeignKeyBuilder ReuniquifyImplicitProperties(bool force .Where(k => ConfigurationSource.Convention.Overrides(k.GetConfigurationSource()))) .Distinct().ToList(); - List detachedRelationships = null; + List? detachedRelationships = null; foreach (var key in keysToDetach) { foreach (var referencingForeignKey in key.GetReferencingForeignKeys().ToList()) @@ -1654,7 +1656,7 @@ public virtual InternalForeignKeyBuilder ReuniquifyImplicitProperties(bool force var detachedIndexes = InternalEntityTypeBuilder.DetachIndexes( temporaryProperties.SelectMany(p => p.GetContainingIndexes()).Distinct()); - relationshipBuilder = relationshipBuilder.HasForeignKey((IReadOnlyList)null, ConfigurationSource.Convention); + relationshipBuilder = relationshipBuilder.HasForeignKey((IReadOnlyList?)null, ConfigurationSource.Convention)!; if (detachedIndexes != null) { @@ -1689,8 +1691,8 @@ public virtual InternalForeignKeyBuilder ReuniquifyImplicitProperties(bool force /// 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. /// - public virtual InternalForeignKeyBuilder HasForeignKey( - [CanBeNull] IReadOnlyList properties, + public virtual InternalForeignKeyBuilder? HasForeignKey( + [CanBeNull] IReadOnlyList? properties, ConfigurationSource configurationSource) => HasForeignKey(properties, Metadata.DeclaringEntityType, configurationSource); @@ -1700,8 +1702,8 @@ public virtual InternalForeignKeyBuilder HasForeignKey( /// 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. /// - public virtual InternalForeignKeyBuilder HasForeignKey( - [CanBeNull] IReadOnlyList propertyNames, + public virtual InternalForeignKeyBuilder? HasForeignKey( + [CanBeNull] IReadOnlyList? propertyNames, ConfigurationSource configurationSource) => HasForeignKey(propertyNames, Metadata.DeclaringEntityType, configurationSource); @@ -1711,8 +1713,8 @@ public virtual InternalForeignKeyBuilder HasForeignKey( /// 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. /// - public virtual InternalForeignKeyBuilder HasForeignKey( - [CanBeNull] IReadOnlyList properties, + public virtual InternalForeignKeyBuilder? HasForeignKey( + [CanBeNull] IReadOnlyList? properties, [NotNull] EntityType dependentEntityType, ConfigurationSource configurationSource) { @@ -1728,7 +1730,7 @@ public virtual InternalForeignKeyBuilder HasForeignKey( return null; } - return (InternalForeignKeyBuilder)batch.Run(relationship.Metadata)?.Builder; + return (InternalForeignKeyBuilder?)batch.Run(relationship.Metadata)?.Builder; } } @@ -1738,8 +1740,8 @@ public virtual InternalForeignKeyBuilder HasForeignKey( /// 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. /// - public virtual InternalForeignKeyBuilder HasForeignKey( - [CanBeNull] IReadOnlyList propertyNames, + public virtual InternalForeignKeyBuilder? HasForeignKey( + [CanBeNull] IReadOnlyList? propertyNames, [NotNull] EntityType dependentEntityType, ConfigurationSource configurationSource) { @@ -1761,7 +1763,7 @@ public virtual InternalForeignKeyBuilder HasForeignKey( return null; } - return (InternalForeignKeyBuilder)batch.Run(relationship.Metadata)?.Builder; + return (InternalForeignKeyBuilder?)batch.Run(relationship.Metadata)?.Builder; } } @@ -1771,8 +1773,8 @@ public virtual InternalForeignKeyBuilder HasForeignKey( /// 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. /// - public virtual InternalForeignKeyBuilder HasForeignKey( - [CanBeNull] IReadOnlyList properties, + public virtual InternalForeignKeyBuilder? HasForeignKey( + [CanBeNull] IReadOnlyList? properties, ConfigurationSource configurationSource) => HasForeignKey(properties, Metadata.DeclaringEntityType, configurationSource); @@ -1782,8 +1784,8 @@ public virtual InternalForeignKeyBuilder HasForeignKey( /// 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. /// - public virtual InternalForeignKeyBuilder HasForeignKey( - [CanBeNull] IReadOnlyList properties, + public virtual InternalForeignKeyBuilder? HasForeignKey( + [CanBeNull] IReadOnlyList? properties, [NotNull] EntityType dependentEntityType, ConfigurationSource configurationSource) { @@ -1796,7 +1798,7 @@ public virtual InternalForeignKeyBuilder HasForeignKey( dependentProperties: Array.Empty()); } - properties = dependentEntityType.Builder.GetActualProperties(properties, configurationSource); + properties = dependentEntityType.Builder.GetActualProperties(properties, configurationSource)!; if (Metadata.Properties.SequenceEqual(properties)) { Metadata.UpdateConfigurationSource(configurationSource); @@ -1809,7 +1811,7 @@ public virtual InternalForeignKeyBuilder HasForeignKey( Metadata.UpdatePrincipalEndConfigurationSource(configurationSource); builder = - (InternalForeignKeyBuilder)ModelBuilder.Metadata.ConventionDispatcher.OnForeignKeyPrincipalEndChanged(builder); + (InternalForeignKeyBuilder?)ModelBuilder.Metadata.ConventionDispatcher.OnForeignKeyPrincipalEndChanged(builder); } return builder; @@ -1836,10 +1838,10 @@ public virtual InternalForeignKeyBuilder HasForeignKey( /// 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. /// - public virtual bool CanSetForeignKey([CanBeNull] IReadOnlyList propertyNames, ConfigurationSource? configurationSource) + public virtual bool CanSetForeignKey([CanBeNull] IReadOnlyList? propertyNames, ConfigurationSource? configurationSource) { - var properties = Metadata.DeclaringEntityType.FindProperties(propertyNames); - if (properties != null) + if (propertyNames is not null + && Metadata.DeclaringEntityType.FindProperties(propertyNames) is IReadOnlyList properties) { return CanSetForeignKey( properties, @@ -1857,7 +1859,7 @@ public virtual bool CanSetForeignKey([CanBeNull] IReadOnlyList propertyN /// 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. /// - public virtual bool CanSetForeignKey([CanBeNull] IReadOnlyList properties, ConfigurationSource? configurationSource) + public virtual bool CanSetForeignKey([CanBeNull] IReadOnlyList? properties, ConfigurationSource? configurationSource) => CanSetForeignKey( properties, dependentEntityType: null, @@ -1865,8 +1867,8 @@ public virtual bool CanSetForeignKey([CanBeNull] IReadOnlyList propert out _); private bool CanSetForeignKey( - IReadOnlyList properties, - EntityType dependentEntityType, + IReadOnlyList? properties, + EntityType? dependentEntityType, ConfigurationSource? configurationSource, bool overrideSameSource = true) => CanSetForeignKey( @@ -1877,8 +1879,8 @@ private bool CanSetForeignKey( overrideSameSource); private bool CanSetForeignKey( - IReadOnlyList properties, - EntityType dependentEntityType, + IReadOnlyList? properties, + EntityType? dependentEntityType, ConfigurationSource? configurationSource, out bool resetPrincipalKey, bool overrideSameSource = true) @@ -1897,8 +1899,8 @@ private bool CanSetForeignKey( } private bool CanSetForeignKey( - IReadOnlyList properties, - EntityType dependentEntityType, + IReadOnlyList? properties, + EntityType? dependentEntityType, IReadOnlyList principalKeyProperties, EntityType principalEntityType, ConfigurationSource? configurationSource, @@ -1960,7 +1962,7 @@ private bool CanSetForeignKey( /// 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. /// - public virtual InternalForeignKeyBuilder HasPrincipalKey( + public virtual InternalForeignKeyBuilder? HasPrincipalKey( [NotNull] IReadOnlyList members, ConfigurationSource configurationSource) { @@ -1975,7 +1977,7 @@ public virtual InternalForeignKeyBuilder HasPrincipalKey( return null; } - return (InternalForeignKeyBuilder)batch.Run(relationship.Metadata)?.Builder; + return (InternalForeignKeyBuilder?)batch.Run(relationship.Metadata)?.Builder; } } @@ -1985,8 +1987,8 @@ public virtual InternalForeignKeyBuilder HasPrincipalKey( /// 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. /// - public virtual InternalForeignKeyBuilder HasPrincipalKey( - [NotNull] IReadOnlyList propertyNames, + public virtual InternalForeignKeyBuilder? HasPrincipalKey( + [CanBeNull] IReadOnlyList? propertyNames, ConfigurationSource configurationSource) { using (var batch = Metadata.DeclaringEntityType.Model.DelayConventions()) @@ -2000,7 +2002,7 @@ public virtual InternalForeignKeyBuilder HasPrincipalKey( return null; } - return (InternalForeignKeyBuilder)batch.Run(relationship.Metadata)?.Builder; + return (InternalForeignKeyBuilder?)batch.Run(relationship.Metadata)?.Builder; } } @@ -2010,8 +2012,8 @@ public virtual InternalForeignKeyBuilder HasPrincipalKey( /// 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. /// - public virtual InternalForeignKeyBuilder HasPrincipalKey( - [CanBeNull] IReadOnlyList properties, + public virtual InternalForeignKeyBuilder? HasPrincipalKey( + [CanBeNull] IReadOnlyList? properties, ConfigurationSource configurationSource) { if (properties == null) @@ -2023,7 +2025,7 @@ public virtual InternalForeignKeyBuilder HasPrincipalKey( principalProperties: Array.Empty()); } - properties = Metadata.PrincipalEntityType.Builder.GetActualProperties(properties, configurationSource); + properties = Metadata.PrincipalEntityType.Builder.GetActualProperties(properties, configurationSource)!; if (Metadata.PrincipalKey.Properties.SequenceEqual(properties)) { @@ -2037,7 +2039,7 @@ public virtual InternalForeignKeyBuilder HasPrincipalKey( Metadata.UpdatePrincipalEndConfigurationSource(configurationSource); builder = - (InternalForeignKeyBuilder)ModelBuilder.Metadata.ConventionDispatcher.OnForeignKeyPrincipalEndChanged(builder); + (InternalForeignKeyBuilder?)ModelBuilder.Metadata.ConventionDispatcher.OnForeignKeyPrincipalEndChanged(builder); } return builder; @@ -2063,10 +2065,10 @@ public virtual InternalForeignKeyBuilder HasPrincipalKey( /// 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. /// - public virtual bool CanSetPrincipalKey([CanBeNull] IReadOnlyList propertyNames, ConfigurationSource? configurationSource) + public virtual bool CanSetPrincipalKey([CanBeNull] IReadOnlyList? propertyNames, ConfigurationSource? configurationSource) { - var properties = Metadata.PrincipalEntityType.FindProperties(propertyNames); - if (properties != null) + if (propertyNames is not null + && Metadata.PrincipalEntityType.FindProperties(propertyNames) is IReadOnlyList properties) { return CanSetPrincipalKey( properties, @@ -2084,7 +2086,7 @@ public virtual bool CanSetPrincipalKey([CanBeNull] IReadOnlyList propert /// 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. /// - public virtual bool CanSetPrincipalKey([CanBeNull] IReadOnlyList properties, ConfigurationSource? configurationSource) + public virtual bool CanSetPrincipalKey([CanBeNull] IReadOnlyList? properties, ConfigurationSource? configurationSource) => CanSetPrincipalKey( properties, configurationSource, @@ -2092,15 +2094,15 @@ public virtual bool CanSetPrincipalKey([CanBeNull] IReadOnlyList prope out _); private bool CanSetPrincipalKey( - IReadOnlyList properties, + IReadOnlyList? properties, ConfigurationSource? configurationSource, out bool resetDependent, - out IReadOnlyList oldNameDependentProperties) + out IReadOnlyList? oldNameDependentProperties) { resetDependent = false; oldNameDependentProperties = null; - if (Metadata.PrincipalKey.Properties.SequenceEqual(properties)) + if (properties is not null && Metadata.PrincipalKey.Properties.SequenceEqual(properties)) { return true; } @@ -2122,7 +2124,7 @@ private bool CanSetPrincipalKey( Metadata.DeclaringEntityType, shouldThrow: false)) { - if (!configurationSource.Value.Overrides(Metadata.GetPropertiesConfigurationSource())) + if (!configurationSource?.Overrides(Metadata.GetPropertiesConfigurationSource()) == true) { return false; } @@ -2141,15 +2143,15 @@ private bool CanSetPrincipalKey( return true; } - private InternalForeignKeyBuilder ReplaceForeignKey( + private InternalForeignKeyBuilder? ReplaceForeignKey( ConfigurationSource configurationSource, - InternalEntityTypeBuilder principalEntityTypeBuilder = null, - InternalEntityTypeBuilder dependentEntityTypeBuilder = null, + InternalEntityTypeBuilder? principalEntityTypeBuilder = null, + InternalEntityTypeBuilder? dependentEntityTypeBuilder = null, MemberIdentity? navigationToPrincipal = null, MemberIdentity? navigationToDependent = null, - IReadOnlyList dependentProperties = null, - IReadOnlyList oldNameDependentProperties = null, - IReadOnlyList principalProperties = null, + IReadOnlyList? dependentProperties = null, + IReadOnlyList? oldNameDependentProperties = null, + IReadOnlyList? principalProperties = null, bool? isUnique = null, bool? isRequired = null, bool? isRequiredDependent = null, @@ -2281,14 +2283,14 @@ private InternalForeignKeyBuilder ReplaceForeignKey( configurationSource); } - private InternalForeignKeyBuilder ReplaceForeignKey( + private InternalForeignKeyBuilder? ReplaceForeignKey( [NotNull] InternalEntityTypeBuilder principalEntityTypeBuilder, [NotNull] InternalEntityTypeBuilder dependentEntityTypeBuilder, MemberIdentity? navigationToPrincipal, MemberIdentity? navigationToDependent, - [CanBeNull] IReadOnlyList dependentProperties, - [CanBeNull] IReadOnlyList oldNameDependentProperties, - [CanBeNull] IReadOnlyList principalProperties, + [CanBeNull] IReadOnlyList? dependentProperties, + [CanBeNull] IReadOnlyList? oldNameDependentProperties, + [CanBeNull] IReadOnlyList? principalProperties, bool? isUnique, bool? isRequired, bool? isRequiredDependent, @@ -2332,16 +2334,16 @@ private InternalForeignKeyBuilder ReplaceForeignKey( Check.DebugAssert( removeCurrent - || Metadata.Builder == null + || !Metadata.IsInModel || (Metadata.PrincipalEntityType.IsAssignableFrom(principalEntityTypeBuilder.Metadata) && Metadata.DeclaringEntityType.IsAssignableFrom(dependentEntityTypeBuilder.Metadata)), "Entity type check failed"); - InternalForeignKeyBuilder newRelationshipBuilder; + InternalForeignKeyBuilder? newRelationshipBuilder; using (var batch = Metadata.DeclaringEntityType.Model.DelayConventions()) { var referencingSkipNavigations = Metadata.ReferencingSkipNavigations - ?.Select(n => (Navigation: n, ConfigurationSource: n.GetForeignKeyConfigurationSource().Value)).ToList(); + ?.Select(n => (Navigation: n, ConfigurationSource: n.GetForeignKeyConfigurationSource()!.Value)).ToList(); newRelationshipBuilder = GetOrCreateRelationshipBuilder( principalEntityTypeBuilder.Metadata, @@ -2453,7 +2455,7 @@ private InternalForeignKeyBuilder ReplaceForeignKey( ConfigurationSource? foreignKeyPropertiesConfigurationSource = null; if (dependentProperties != null) { - dependentProperties = dependentEntityTypeBuilder.GetActualProperties(dependentProperties, configurationSource); + dependentProperties = dependentEntityTypeBuilder.GetActualProperties(dependentProperties, configurationSource)!; foreignKeyPropertiesConfigurationSource = configurationSource; if (PropertyListComparer.Instance.Equals(Metadata.Properties, dependentProperties) @@ -2484,7 +2486,7 @@ private InternalForeignKeyBuilder ReplaceForeignKey( ConfigurationSource? principalKeyConfigurationSource = null; if (principalProperties != null) { - principalProperties = principalEntityTypeBuilder.GetActualProperties(principalProperties, configurationSource); + principalProperties = principalEntityTypeBuilder.GetActualProperties(principalProperties, configurationSource)!; principalKeyConfigurationSource = configurationSource; if (PropertyListComparer.Instance.Equals( @@ -2515,12 +2517,12 @@ private InternalForeignKeyBuilder ReplaceForeignKey( if (shouldSetProperties) { - Key principalKey = null; + Key? principalKey = null; if (principalProperties != null && principalProperties.Count != 0) { principalKey = principalEntityTypeBuilder.Metadata.RootType().Builder - .HasKey(principalProperties, configurationSource).Metadata; + .HasKey(principalProperties, configurationSource)!.Metadata; } var foreignKey = newRelationshipBuilder.Metadata; @@ -2531,7 +2533,7 @@ private InternalForeignKeyBuilder ReplaceForeignKey( navigationToPrincipal?.Name ?? referencingSkipNavigations?.FirstOrDefault().Navigation?.Inverse?.Name, isRequired, - configurationSource: null); + configurationSource: null)!; if (foreignKeyPropertiesConfigurationSource != null && dependentProperties?.Count != 0) @@ -2541,7 +2543,7 @@ private InternalForeignKeyBuilder ReplaceForeignKey( } if (principalKeyConfigurationSource != null - && principalProperties.Count != 0) + && principalProperties!.Count != 0) { newRelationshipBuilder.Metadata.UpdatePrincipalKeyConfigurationSource( principalKeyConfigurationSource.Value); @@ -2563,12 +2565,13 @@ private InternalForeignKeyBuilder ReplaceForeignKey( ?? newRelationshipBuilder; } else if (!oldRelationshipInverted - && Metadata.GetIsUniqueConfigurationSource().HasValue + && Metadata.GetIsUniqueConfigurationSource() is var isUniqueConfigurationSource + && isUniqueConfigurationSource.HasValue && !newRelationshipBuilder.Metadata.GetIsUniqueConfigurationSource().HasValue) { newRelationshipBuilder = newRelationshipBuilder.IsUnique( Metadata.IsUnique, - Metadata.GetIsUniqueConfigurationSource().Value) + isUniqueConfigurationSource.Value) ?? newRelationshipBuilder; } @@ -2589,23 +2592,26 @@ private InternalForeignKeyBuilder ReplaceForeignKey( { if (!oldRelationshipInverted) { - if (Metadata.GetIsRequiredConfigurationSource().HasValue + if (Metadata.GetIsRequiredConfigurationSource() is var isRequiredConfigurationSource + && isRequiredConfigurationSource.HasValue && !newRelationshipBuilder.Metadata.GetIsRequiredConfigurationSource().HasValue) { newRelationshipBuilder = newRelationshipBuilder.IsRequired( Metadata.IsRequired, - Metadata.GetIsRequiredConfigurationSource().Value) + isRequiredConfigurationSource.Value) ?? newRelationshipBuilder; } } else { - if (Metadata.GetIsRequiredDependentConfigurationSource().Overrides(ConfigurationSource.Explicit) + if (Metadata.GetIsRequiredDependentConfigurationSource() is var isRequiredDependentConfigurationSource + && isRequiredDependentConfigurationSource.HasValue + && isRequiredDependentConfigurationSource.Value.Overrides(ConfigurationSource.Explicit) && !newRelationshipBuilder.Metadata.GetIsRequiredConfigurationSource().HasValue) { newRelationshipBuilder = newRelationshipBuilder.IsRequired( Metadata.IsRequiredDependent, - Metadata.GetIsRequiredDependentConfigurationSource().Value) + isRequiredDependentConfigurationSource.Value) ?? newRelationshipBuilder; } } @@ -2629,23 +2635,26 @@ private InternalForeignKeyBuilder ReplaceForeignKey( { if (!oldRelationshipInverted) { - if (Metadata.GetIsRequiredDependentConfigurationSource().HasValue + if (Metadata.GetIsRequiredDependentConfigurationSource() is var isRequiredDependentConfigurationSource + && isRequiredDependentConfigurationSource.HasValue && !newRelationshipBuilder.Metadata.GetIsRequiredDependentConfigurationSource().HasValue) { newRelationshipBuilder = newRelationshipBuilder.IsRequiredDependent( Metadata.IsRequiredDependent, - Metadata.GetIsRequiredDependentConfigurationSource().Value) + isRequiredDependentConfigurationSource.Value) ?? newRelationshipBuilder; } } else { - if (Metadata.GetIsRequiredConfigurationSource().Overrides(ConfigurationSource.Explicit) + if (Metadata.GetIsRequiredConfigurationSource() is var isRequiredConfigurationSource + && isRequiredConfigurationSource.HasValue + && isRequiredConfigurationSource.Value.Overrides(ConfigurationSource.Explicit) && !newRelationshipBuilder.Metadata.GetIsRequiredDependentConfigurationSource().HasValue) { newRelationshipBuilder = newRelationshipBuilder.IsRequiredDependent( Metadata.IsRequired, - Metadata.GetIsRequiredConfigurationSource().Value) + isRequiredConfigurationSource.Value) ?? newRelationshipBuilder; } } @@ -2666,12 +2675,13 @@ private InternalForeignKeyBuilder ReplaceForeignKey( ?? newRelationshipBuilder; } else if (!oldRelationshipInverted - && Metadata.GetDeleteBehaviorConfigurationSource().HasValue + && Metadata.GetDeleteBehaviorConfigurationSource() is var deleteBehaviorConfigurationSource + && deleteBehaviorConfigurationSource.HasValue && !newRelationshipBuilder.Metadata.GetDeleteBehaviorConfigurationSource().HasValue) { newRelationshipBuilder = newRelationshipBuilder.OnDelete( Metadata.DeleteBehavior, - Metadata.GetDeleteBehaviorConfigurationSource().Value) + deleteBehaviorConfigurationSource.Value) ?? newRelationshipBuilder; } @@ -2708,7 +2718,7 @@ private InternalForeignKeyBuilder ReplaceForeignKey( newRelationshipBuilder = newRelationshipBuilder.HasNavigations( oldNavigationToPrincipal.CreateMemberIdentity(), navigationToDependent: null, - oldToPrincipalConfigurationSource.Value) + oldToPrincipalConfigurationSource!.Value) ?? newRelationshipBuilder; if (newRelationshipBuilder.Metadata.DependentToPrincipal != null) @@ -2751,7 +2761,7 @@ private InternalForeignKeyBuilder ReplaceForeignKey( newRelationshipBuilder = newRelationshipBuilder.HasNavigations( navigationToPrincipal: null, oldNavigationToDependent.CreateMemberIdentity(), - oldToDependentConfigurationSource.Value) + oldToDependentConfigurationSource!.Value) ?? newRelationshipBuilder; if (newRelationshipBuilder.Metadata.PrincipalToDependent != null) @@ -2775,11 +2785,12 @@ private InternalForeignKeyBuilder ReplaceForeignKey( ?? newRelationshipBuilder; } else if (!oldRelationshipInverted - && Metadata.GetIsOwnershipConfigurationSource().HasValue) + && Metadata.GetIsOwnershipConfigurationSource() is var getIsOwnershipConfigurationSource + && getIsOwnershipConfigurationSource.HasValue) { newRelationshipBuilder = newRelationshipBuilder.IsOwnership( Metadata.IsOwnership, - Metadata.GetIsOwnershipConfigurationSource().Value) + getIsOwnershipConfigurationSource.Value) ?? newRelationshipBuilder; } @@ -2788,10 +2799,10 @@ private InternalForeignKeyBuilder ReplaceForeignKey( foreach (var referencingNavigationTuple in referencingSkipNavigations) { var skipNavigation = referencingNavigationTuple.Navigation; - if (skipNavigation.Builder == null) + if (!skipNavigation.IsInModel) { var navigationEntityType = skipNavigation.DeclaringEntityType; - skipNavigation = navigationEntityType.Builder == null + skipNavigation = !navigationEntityType.IsInModel ? null : navigationEntityType.FindSkipNavigation(skipNavigation.Name); } @@ -2814,7 +2825,7 @@ private InternalForeignKeyBuilder ReplaceForeignKey( private InternalForeignKeyBuilder MergeFacetsFrom(Navigation newNavigation, Navigation oldNavigation) { - newNavigation?.Builder.MergeAnnotationsFrom(oldNavigation); + newNavigation.Builder.MergeAnnotationsFrom(oldNavigation); var builder = newNavigation.Builder; @@ -2825,34 +2836,34 @@ private InternalForeignKeyBuilder MergeFacetsFrom(Navigation newNavigation, Navi propertyAccessModeConfigurationSource)) { builder = builder.UsePropertyAccessMode( - ((IConventionNavigation)oldNavigation).GetPropertyAccessMode(), propertyAccessModeConfigurationSource.Value); + ((IConventionNavigation)oldNavigation).GetPropertyAccessMode(), propertyAccessModeConfigurationSource.Value)!; } var oldFieldInfoConfigurationSource = oldNavigation.GetFieldInfoConfigurationSource(); if (oldFieldInfoConfigurationSource.HasValue && builder.CanSetField(oldNavigation.FieldInfo, oldFieldInfoConfigurationSource)) { - builder = builder.HasField(oldNavigation.FieldInfo, oldFieldInfoConfigurationSource.Value); + builder = builder.HasField(oldNavigation.FieldInfo, oldFieldInfoConfigurationSource.Value)!; } var oldIsEagerLoadedConfigurationSource = ((IConventionNavigation)oldNavigation).GetIsEagerLoadedConfigurationSource(); if (oldIsEagerLoadedConfigurationSource.HasValue && builder.CanSetAutoInclude(((INavigation)oldNavigation).IsEagerLoaded, oldIsEagerLoadedConfigurationSource.Value)) { - builder = builder.AutoInclude(((INavigation)oldNavigation).IsEagerLoaded, oldIsEagerLoadedConfigurationSource.Value); + builder = builder.AutoInclude(((INavigation)oldNavigation).IsEagerLoaded, oldIsEagerLoadedConfigurationSource.Value)!; } return builder.Metadata.ForeignKey.Builder; } - private InternalForeignKeyBuilder GetOrCreateRelationshipBuilder( + private InternalForeignKeyBuilder? GetOrCreateRelationshipBuilder( EntityType principalEntityType, EntityType dependentEntityType, MemberIdentity? navigationToPrincipal, MemberIdentity? navigationToDependent, - IReadOnlyList dependentProperties, - IReadOnlyList oldNameDependentProperties, - IReadOnlyList principalProperties, + IReadOnlyList? dependentProperties, + IReadOnlyList? oldNameDependentProperties, + IReadOnlyList? principalProperties, bool? isRequired, bool removeCurrent, ConfigurationSource? principalEndConfigurationSource, @@ -2885,7 +2896,7 @@ private InternalForeignKeyBuilder GetOrCreateRelationshipBuilder( && ((IConventionProperty)p).IsImplicitlyCreated()).ToList(); var tempIndex = temporaryProperties?.Count > 0 && dependentEntityType.FindIndex(temporaryProperties) == null - ? dependentEntityType.Builder.HasIndex(temporaryProperties, ConfigurationSource.Convention).Metadata + ? dependentEntityType.Builder.HasIndex(temporaryProperties, ConfigurationSource.Convention)!.Metadata : null; var temporaryKeyProperties = principalProperties?.Where( @@ -2893,12 +2904,12 @@ private InternalForeignKeyBuilder GetOrCreateRelationshipBuilder( && ((IConventionProperty)p).IsImplicitlyCreated()).ToList(); var keyTempIndex = temporaryKeyProperties?.Count > 0 && principalEntityType.FindIndex(temporaryKeyProperties) == null - ? principalEntityType.Builder.HasIndex(temporaryKeyProperties, ConfigurationSource.Convention).Metadata + ? principalEntityType.Builder.HasIndex(temporaryKeyProperties, ConfigurationSource.Convention)!.Metadata : null; var removedForeignKeys = new List(); var referencingSkipNavigationName = Metadata.ReferencingSkipNavigations?.FirstOrDefault()?.Inverse?.Name; - if (Metadata.Builder == null) + if (!Metadata.IsInModel) { removedForeignKeys.Add(Metadata); } @@ -2954,16 +2965,16 @@ private InternalForeignKeyBuilder GetOrCreateRelationshipBuilder( if (resolution.HasFlag(Resolution.ResetToPrincipal)) { resolvableRelationship = resolvableRelationship.HasNavigations( - MemberIdentity.None, navigationToDependent: null, resolvableRelationship.Metadata.GetConfigurationSource()); + MemberIdentity.None, navigationToDependent: null, resolvableRelationship.Metadata.GetConfigurationSource())!; } if (resolution.HasFlag(Resolution.ResetToDependent)) { resolvableRelationship = resolvableRelationship.HasNavigations( - navigationToPrincipal: null, MemberIdentity.None, resolvableRelationship.Metadata.GetConfigurationSource()); + navigationToPrincipal: null, MemberIdentity.None, resolvableRelationship.Metadata.GetConfigurationSource())!; } - if (resolvableRelationship.Metadata.Builder == null) + if (!resolvableRelationship.Metadata.IsInModel) { continue; } @@ -2981,14 +2992,14 @@ private InternalForeignKeyBuilder GetOrCreateRelationshipBuilder( if (resolution.HasFlag(Resolution.ResetDependentProperties)) { var foreignKey = resolvableRelationship.Metadata; - resolvableRelationship.HasForeignKey((IReadOnlyList)null, foreignKey.GetConfigurationSource()); + resolvableRelationship.HasForeignKey((IReadOnlyList?)null, foreignKey.GetConfigurationSource()); } } if (newRelationshipBuilder == null) { var principalKey = principalProperties != null - ? principalEntityType.RootType().Builder.HasKey(principalProperties, configurationSource).Metadata + ? principalEntityType.RootType().Builder.HasKey(principalProperties, configurationSource)!.Metadata : principalEntityType.FindPrimaryKey(); if (principalKey != null) { @@ -3004,15 +3015,15 @@ private InternalForeignKeyBuilder GetOrCreateRelationshipBuilder( p => ConfigurationSource.Convention.Overrides(p.GetTypeConfigurationSource()) && (p.IsShadowProperty() || p.IsIndexerProperty())))) { - dependentProperties = oldNameDependentProperties ?? dependentProperties; + dependentProperties = (oldNameDependentProperties ?? dependentProperties)!; if (principalKey.Properties.Count == dependentProperties.Count) { - var detachedProperties = InternalEntityTypeBuilder.DetachProperties(dependentProperties); + var detachedProperties = InternalEntityTypeBuilder.DetachProperties(dependentProperties)!; dependentProperties = dependentEntityType.Builder.GetOrCreateProperties( dependentProperties.Select(p => p.Name).ToList(), ConfigurationSource.Convention, principalKey.Properties, - isRequired ?? false); + isRequired ?? false)!; detachedProperties.Attach(dependentEntityType.Builder); } } @@ -3042,7 +3053,7 @@ private InternalForeignKeyBuilder GetOrCreateRelationshipBuilder( principalKey, navigationToPrincipal?.Name ?? referencingSkipNavigationName, isRequired, - ConfigurationSource.Convention); + ConfigurationSource.Convention)!; } foreach (var removedForeignKey in removedForeignKeys) @@ -3050,12 +3061,12 @@ private InternalForeignKeyBuilder GetOrCreateRelationshipBuilder( Metadata.DeclaringEntityType.Model.ConventionDispatcher.Tracker.Update(removedForeignKey, newRelationshipBuilder.Metadata); } - if (tempIndex?.Builder != null) + if (tempIndex?.IsInModel == true) { dependentEntityType.RemoveIndex(tempIndex.Properties); } - if (keyTempIndex?.Builder != null) + if (keyTempIndex?.IsInModel == true) { keyTempIndex.DeclaringEntityType.RemoveIndex(keyTempIndex.Properties); } @@ -3063,13 +3074,13 @@ private InternalForeignKeyBuilder GetOrCreateRelationshipBuilder( return newRelationshipBuilder; } - private InternalForeignKeyBuilder FindCompatibleRelationship( + private InternalForeignKeyBuilder? FindCompatibleRelationship( EntityType principalEntityType, EntityType dependentEntityType, MemberIdentity? navigationToPrincipal, MemberIdentity? navigationToDependent, - IReadOnlyList dependentProperties, - IReadOnlyList principalProperties, + IReadOnlyList? dependentProperties, + IReadOnlyList? principalProperties, ConfigurationSource? principalEndConfigurationSource, ConfigurationSource? configurationSource, out bool? existingRelationshipInverted, @@ -3278,7 +3289,7 @@ private InternalForeignKeyBuilder FindCompatibleRelationship( } } - InternalForeignKeyBuilder newRelationshipBuilder = null; + InternalForeignKeyBuilder? newRelationshipBuilder = null; var candidates = unresolvableRelationships.Concat( resolvableRelationships.Where(r => r.SameConfigurationSource).Concat( @@ -3375,8 +3386,8 @@ public static void ThrowForConflictingNavigation( [NotNull] IForeignKey foreignKey, [NotNull] IEntityType principalEntityType, [NotNull] IEntityType dependentEntityType, - [CanBeNull] string navigationToDependent, - [CanBeNull] string navigationToPrincipal) + [CanBeNull] string? navigationToDependent, + [CanBeNull] string? navigationToPrincipal) => throw new InvalidOperationException( CoreStrings.ConflictingRelationshipNavigation( principalEntityType.DisplayName() @@ -3401,8 +3412,8 @@ private static IReadOnlyList FindRelationships( [NotNull] EntityType dependentEntityType, MemberIdentity? navigationToPrincipal, MemberIdentity? navigationToDependent, - IReadOnlyList dependentProperties, - IReadOnlyList principalProperties) + IReadOnlyList? dependentProperties, + IReadOnlyList? principalProperties) { var existingRelationships = new List(); if (navigationToPrincipal?.Name != null) @@ -3453,15 +3464,15 @@ private static IReadOnlyList FindRelationships( /// 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. /// - public static InternalForeignKeyBuilder FindCurrentForeignKeyBuilder( + public static InternalForeignKeyBuilder? FindCurrentForeignKeyBuilder( [NotNull] EntityType principalEntityType, [NotNull] EntityType dependentEntityType, MemberIdentity? navigationToPrincipal, MemberIdentity? navigationToDependent, - [CanBeNull] IReadOnlyList dependentProperties, - [CanBeNull] IReadOnlyList principalProperties) + [CanBeNull] IReadOnlyList? dependentProperties, + [CanBeNull] IReadOnlyList? principalProperties) { - InternalForeignKeyBuilder currentRelationship = null; + InternalForeignKeyBuilder? currentRelationship = null; var matchingRelationships = FindRelationships( principalEntityType, dependentEntityType, @@ -3536,13 +3547,13 @@ public static InternalForeignKeyBuilder FindCurrentForeignKeyBuilder( /// 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. /// - public virtual InternalForeignKeyBuilder Attach([NotNull] InternalEntityTypeBuilder entityTypeBuilder) + public virtual InternalForeignKeyBuilder? Attach([NotNull] InternalEntityTypeBuilder entityTypeBuilder) { var configurationSource = Metadata.GetConfigurationSource(); var model = Metadata.DeclaringEntityType.Model; InternalEntityTypeBuilder principalEntityTypeBuilder; - EntityType principalEntityType; - if (Metadata.PrincipalEntityType.Builder != null) + EntityType? principalEntityType; + if (Metadata.PrincipalEntityType.IsInModel) { principalEntityTypeBuilder = Metadata.PrincipalEntityType.Builder; principalEntityType = Metadata.PrincipalEntityType; @@ -3563,11 +3574,11 @@ public virtual InternalForeignKeyBuilder Attach([NotNull] InternalEntityTypeBuil var ownership = Metadata.PrincipalEntityType.FindOwnership(); if (Metadata.PrincipalEntityType.HasSharedClrType && ownership != null - && ownership.PrincipalEntityType.Builder != null) + && ownership.PrincipalEntityType.IsInModel) { principalEntityType = model.FindEntityType( Metadata.PrincipalEntityType.ClrType, - ownership.PrincipalToDependent.Name, + ownership.PrincipalToDependent!.Name, ownership.PrincipalEntityType); if (principalEntityType == null) { @@ -3594,8 +3605,8 @@ public virtual InternalForeignKeyBuilder Attach([NotNull] InternalEntityTypeBuil } InternalEntityTypeBuilder dependentEntityTypeBuilder; - EntityType dependentEntityType; - if (Metadata.DeclaringEntityType.Builder != null) + EntityType? dependentEntityType; + if (Metadata.DeclaringEntityType.IsInModel) { dependentEntityTypeBuilder = Metadata.DeclaringEntityType.Builder; dependentEntityType = Metadata.DeclaringEntityType; @@ -3629,7 +3640,7 @@ public virtual InternalForeignKeyBuilder Attach([NotNull] InternalEntityTypeBuil name, Metadata.DeclaringEntityType.ClrType, Metadata.DeclaringEntityType.GetConfigurationSource(), - shouldBeOwned: null).Metadata; + shouldBeOwned: null)!.Metadata; } else { @@ -3639,8 +3650,8 @@ public virtual InternalForeignKeyBuilder Attach([NotNull] InternalEntityTypeBuil else { dependentEntityType = Metadata.DeclaringEntityType.ClrType == null - ? ModelBuilder.Entity(Metadata.DeclaringEntityType.Name, configurationSource).Metadata - : ModelBuilder.Entity(Metadata.DeclaringEntityType.ClrType, configurationSource).Metadata; + ? ModelBuilder.Entity(Metadata.DeclaringEntityType.Name, configurationSource)!.Metadata + : ModelBuilder.Entity(Metadata.DeclaringEntityType.ClrType, configurationSource)!.Metadata; } } } @@ -3659,7 +3670,7 @@ public virtual InternalForeignKeyBuilder Attach([NotNull] InternalEntityTypeBuil if (dependentEntityType.GetForeignKeys().Contains(Metadata, LegacyReferenceEqualityComparer.Instance)) { - Check.DebugAssert(Metadata.Builder != null, "Metadata.Builder is null"); + Check.DebugAssert(Metadata.IsInModel, "Metadata isn't in the model"); return Metadata.Builder; } @@ -3723,10 +3734,10 @@ public virtual InternalForeignKeyBuilder Attach([NotNull] InternalEntityTypeBuil public static bool AreCompatible( [NotNull] EntityType principalEntityType, [NotNull] EntityType dependentEntityType, - [CanBeNull] MemberInfo navigationToPrincipal, - [CanBeNull] MemberInfo navigationToDependent, - [CanBeNull] IReadOnlyList dependentProperties, - [CanBeNull] IReadOnlyList principalProperties, + [CanBeNull] MemberInfo? navigationToPrincipal, + [CanBeNull] MemberInfo? navigationToDependent, + [CanBeNull] IReadOnlyList? dependentProperties, + [CanBeNull] IReadOnlyList? principalProperties, bool? isUnique, ConfigurationSource? configurationSource) => ForeignKey.AreCompatible( @@ -3938,7 +3949,7 @@ private bool CanSetRelatedTypes( out invertedShouldBeUnique)) { if (!configurationSource.HasValue - || !CanSetNavigation((string)null, pointsToPrincipal: true, configurationSource.Value)) + || !CanSetNavigation((string?)null, pointsToPrincipal: true, configurationSource.Value)) { return false; } @@ -3992,7 +4003,7 @@ private bool CanSetRelatedTypes( out toDependentShouldBeUnique)) { if (!configurationSource.HasValue - || !CanSetNavigation((string)null, pointsToPrincipal: false, configurationSource.Value)) + || !CanSetNavigation((string?)null, pointsToPrincipal: false, configurationSource.Value)) { return false; } @@ -4056,7 +4067,7 @@ IConventionForeignKey IConventionForeignKeyBuilder.Metadata /// [DebuggerStepThrough] - IConventionForeignKeyBuilder IConventionForeignKeyBuilder.HasEntityTypes( + IConventionForeignKeyBuilder? IConventionForeignKeyBuilder.HasEntityTypes( IConventionEntityType principalEntityType, IConventionEntityType dependentEntityType, bool fromDataAnnotation) @@ -4076,15 +4087,15 @@ bool IConventionForeignKeyBuilder.CanSetEntityTypes( /// [DebuggerStepThrough] - bool IConventionForeignKeyBuilder.CanInvert(IReadOnlyList newForeignKeyProperties, bool fromDataAnnotation) + bool IConventionForeignKeyBuilder.CanInvert(IReadOnlyList? newForeignKeyProperties, bool fromDataAnnotation) => CanInvert( - (IReadOnlyList)newForeignKeyProperties, + (IReadOnlyList?)newForeignKeyProperties, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// [DebuggerStepThrough] - IConventionForeignKeyBuilder IConventionForeignKeyBuilder.HasForeignKey( - [CanBeNull] IReadOnlyList properties, + IConventionForeignKeyBuilder? IConventionForeignKeyBuilder.HasForeignKey( + IReadOnlyList? properties, bool fromDataAnnotation) => HasForeignKey( properties, @@ -4092,8 +4103,8 @@ IConventionForeignKeyBuilder IConventionForeignKeyBuilder.HasForeignKey( /// [DebuggerStepThrough] - IConventionForeignKeyBuilder IConventionForeignKeyBuilder.HasForeignKey( - IReadOnlyList properties, + IConventionForeignKeyBuilder? IConventionForeignKeyBuilder.HasForeignKey( + IReadOnlyList? properties, bool fromDataAnnotation) => HasForeignKey( properties as IReadOnlyList ?? properties?.Cast().ToList(), @@ -4102,7 +4113,7 @@ IConventionForeignKeyBuilder IConventionForeignKeyBuilder.HasForeignKey( /// [DebuggerStepThrough] bool IConventionForeignKeyBuilder.CanSetForeignKey( - [CanBeNull] IReadOnlyList properties, + IReadOnlyList? properties, bool fromDataAnnotation) => CanSetForeignKey( properties, @@ -4110,15 +4121,15 @@ bool IConventionForeignKeyBuilder.CanSetForeignKey( /// [DebuggerStepThrough] - bool IConventionForeignKeyBuilder.CanSetForeignKey(IReadOnlyList properties, bool fromDataAnnotation) + bool IConventionForeignKeyBuilder.CanSetForeignKey(IReadOnlyList? properties, bool fromDataAnnotation) => CanSetForeignKey( properties as IReadOnlyList ?? properties?.Cast().ToList(), fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// [DebuggerStepThrough] - IConventionForeignKeyBuilder IConventionForeignKeyBuilder.HasPrincipalKey( - [CanBeNull] IReadOnlyList properties, + IConventionForeignKeyBuilder? IConventionForeignKeyBuilder.HasPrincipalKey( + IReadOnlyList? properties, bool fromDataAnnotation) => HasPrincipalKey( properties, @@ -4126,8 +4137,8 @@ IConventionForeignKeyBuilder IConventionForeignKeyBuilder.HasPrincipalKey( /// [DebuggerStepThrough] - IConventionForeignKeyBuilder IConventionForeignKeyBuilder.HasPrincipalKey( - IReadOnlyList properties, + IConventionForeignKeyBuilder? IConventionForeignKeyBuilder.HasPrincipalKey( + IReadOnlyList? properties, bool fromDataAnnotation) => HasPrincipalKey( properties as IReadOnlyList ?? properties?.Cast().ToList(), @@ -4136,7 +4147,7 @@ IConventionForeignKeyBuilder IConventionForeignKeyBuilder.HasPrincipalKey( /// [DebuggerStepThrough] bool IConventionForeignKeyBuilder.CanSetPrincipalKey( - [CanBeNull] IReadOnlyList properties, + IReadOnlyList? properties, bool fromDataAnnotation) => CanSetPrincipalKey( properties, @@ -4144,15 +4155,15 @@ bool IConventionForeignKeyBuilder.CanSetPrincipalKey( /// [DebuggerStepThrough] - bool IConventionForeignKeyBuilder.CanSetPrincipalKey(IReadOnlyList properties, bool fromDataAnnotation) + bool IConventionForeignKeyBuilder.CanSetPrincipalKey(IReadOnlyList? properties, bool fromDataAnnotation) => CanSetPrincipalKey( properties as IReadOnlyList ?? properties?.Cast().ToList(), fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// [DebuggerStepThrough] - IConventionForeignKeyBuilder IConventionForeignKeyBuilder.HasNavigation( - string name, + IConventionForeignKeyBuilder? IConventionForeignKeyBuilder.HasNavigation( + string? name, bool pointsToPrincipal, bool fromDataAnnotation) => HasNavigation( @@ -4161,8 +4172,8 @@ IConventionForeignKeyBuilder IConventionForeignKeyBuilder.HasNavigation( /// [DebuggerStepThrough] - IConventionForeignKeyBuilder IConventionForeignKeyBuilder.HasNavigation( - MemberInfo property, + IConventionForeignKeyBuilder? IConventionForeignKeyBuilder.HasNavigation( + MemberInfo? property, bool pointsToPrincipal, bool fromDataAnnotation) => HasNavigation( @@ -4171,9 +4182,9 @@ IConventionForeignKeyBuilder IConventionForeignKeyBuilder.HasNavigation( /// [DebuggerStepThrough] - IConventionForeignKeyBuilder IConventionForeignKeyBuilder.HasNavigations( - string navigationToPrincipalName, - string navigationToDependentName, + IConventionForeignKeyBuilder? IConventionForeignKeyBuilder.HasNavigations( + string? navigationToPrincipalName, + string? navigationToDependentName, bool fromDataAnnotation) => HasNavigations( navigationToPrincipalName, navigationToDependentName, @@ -4181,9 +4192,9 @@ IConventionForeignKeyBuilder IConventionForeignKeyBuilder.HasNavigations( /// [DebuggerStepThrough] - IConventionForeignKeyBuilder IConventionForeignKeyBuilder.HasNavigations( - MemberInfo navigationToPrincipal, - MemberInfo navigationToDependent, + IConventionForeignKeyBuilder? IConventionForeignKeyBuilder.HasNavigations( + MemberInfo? navigationToPrincipal, + MemberInfo? navigationToDependent, bool fromDataAnnotation) => HasNavigations( navigationToPrincipal, navigationToDependent, @@ -4192,7 +4203,7 @@ IConventionForeignKeyBuilder IConventionForeignKeyBuilder.HasNavigations( /// [DebuggerStepThrough] bool IConventionForeignKeyBuilder.CanSetNavigation( - MemberInfo property, + MemberInfo? property, bool pointsToPrincipal, bool fromDataAnnotation) => CanSetNavigation( @@ -4201,7 +4212,7 @@ bool IConventionForeignKeyBuilder.CanSetNavigation( /// [DebuggerStepThrough] - bool IConventionForeignKeyBuilder.CanSetNavigation(string name, bool pointsToPrincipal, bool fromDataAnnotation) + bool IConventionForeignKeyBuilder.CanSetNavigation(string? name, bool pointsToPrincipal, bool fromDataAnnotation) => CanSetNavigation( name, pointsToPrincipal, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); @@ -4209,8 +4220,8 @@ bool IConventionForeignKeyBuilder.CanSetNavigation(string name, bool pointsToPri /// [DebuggerStepThrough] bool IConventionForeignKeyBuilder.CanSetNavigations( - MemberInfo navigationToPrincipal, - MemberInfo navigationToDependent, + MemberInfo? navigationToPrincipal, + MemberInfo? navigationToDependent, bool fromDataAnnotation) => CanSetNavigations( navigationToPrincipal, navigationToDependent, @@ -4219,8 +4230,8 @@ bool IConventionForeignKeyBuilder.CanSetNavigations( /// [DebuggerStepThrough] bool IConventionForeignKeyBuilder.CanSetNavigations( - string navigationToPrincipalName, - string navigationToDependentName, + string? navigationToPrincipalName, + string? navigationToDependentName, bool fromDataAnnotation) => CanSetNavigations( navigationToPrincipalName, navigationToDependentName, @@ -4228,7 +4239,7 @@ bool IConventionForeignKeyBuilder.CanSetNavigations( /// [DebuggerStepThrough] - IConventionForeignKeyBuilder IConventionForeignKeyBuilder.IsRequired(bool? required, bool fromDataAnnotation) + IConventionForeignKeyBuilder? IConventionForeignKeyBuilder.IsRequired(bool? required, bool fromDataAnnotation) => IsRequired(required, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// @@ -4238,7 +4249,7 @@ bool IConventionForeignKeyBuilder.CanSetIsRequired(bool? required, bool fromData /// [DebuggerStepThrough] - IConventionForeignKeyBuilder IConventionForeignKeyBuilder.IsRequiredDependent(bool? required, bool fromDataAnnotation) + IConventionForeignKeyBuilder? IConventionForeignKeyBuilder.IsRequiredDependent(bool? required, bool fromDataAnnotation) => IsRequiredDependent(required, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// @@ -4254,7 +4265,7 @@ bool IConventionForeignKeyBuilder.CanSetIsRequiredDependent(bool? required, bool /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [DebuggerStepThrough] - IConventionForeignKeyBuilder IConventionForeignKeyBuilder.IsOwnership(bool? ownership, bool fromDataAnnotation) + IConventionForeignKeyBuilder? IConventionForeignKeyBuilder.IsOwnership(bool? ownership, bool fromDataAnnotation) => IsOwnership(ownership, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// @@ -4274,7 +4285,7 @@ bool IConventionForeignKeyBuilder.CanSetIsOwnership(bool? ownership, bool fromDa /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [DebuggerStepThrough] - IConventionForeignKeyBuilder IConventionForeignKeyBuilder.OnDelete( + IConventionForeignKeyBuilder? IConventionForeignKeyBuilder.OnDelete( DeleteBehavior? deleteBehavior, bool fromDataAnnotation) => OnDelete(deleteBehavior, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); @@ -4297,7 +4308,7 @@ bool IConventionForeignKeyBuilder.CanSetOnDelete(DeleteBehavior? deleteBehavior, /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [DebuggerStepThrough] - IConventionForeignKeyBuilder IConventionForeignKeyBuilder.IsUnique(bool? unique, bool fromDataAnnotation) + IConventionForeignKeyBuilder? IConventionForeignKeyBuilder.IsUnique(bool? unique, bool fromDataAnnotation) => IsUnique(unique, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// diff --git a/src/EFCore/Metadata/Internal/InternalIndexBuilder.cs b/src/EFCore/Metadata/Internal/InternalIndexBuilder.cs index 57e1d121dad..444148972b5 100644 --- a/src/EFCore/Metadata/Internal/InternalIndexBuilder.cs +++ b/src/EFCore/Metadata/Internal/InternalIndexBuilder.cs @@ -5,6 +5,8 @@ using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata.Builders; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Internal { /// @@ -32,7 +34,7 @@ public InternalIndexBuilder([NotNull] Index index, [NotNull] InternalModelBuilde /// 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. /// - public virtual InternalIndexBuilder IsUnique(bool? unique, ConfigurationSource configurationSource) + public virtual InternalIndexBuilder? IsUnique(bool? unique, ConfigurationSource configurationSource) { if (!CanSetIsUnique(unique, configurationSource)) { @@ -59,7 +61,7 @@ public virtual bool CanSetIsUnique(bool? unique, ConfigurationSource? configurat /// 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. /// - public virtual InternalIndexBuilder Attach([NotNull] InternalEntityTypeBuilder entityTypeBuilder) + public virtual InternalIndexBuilder? Attach([NotNull] InternalEntityTypeBuilder entityTypeBuilder) { var properties = entityTypeBuilder.GetActualProperties(Metadata.Properties, null); if (properties == null) @@ -96,7 +98,7 @@ IConventionIndex IConventionIndexBuilder.Metadata /// 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. /// - IConventionIndexBuilder IConventionIndexBuilder.IsUnique(bool? unique, bool fromDataAnnotation) + IConventionIndexBuilder? IConventionIndexBuilder.IsUnique(bool? unique, bool fromDataAnnotation) => IsUnique( unique, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); diff --git a/src/EFCore/Metadata/Internal/InternalKeyBuilder.cs b/src/EFCore/Metadata/Internal/InternalKeyBuilder.cs index 42081847eae..13b94cebcc1 100644 --- a/src/EFCore/Metadata/Internal/InternalKeyBuilder.cs +++ b/src/EFCore/Metadata/Internal/InternalKeyBuilder.cs @@ -6,6 +6,8 @@ using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata.Builders; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Internal { /// @@ -33,7 +35,7 @@ public InternalKeyBuilder([NotNull] Key key, [NotNull] InternalModelBuilder mode /// 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. /// - public virtual InternalKeyBuilder Attach( + public virtual InternalKeyBuilder? Attach( [NotNull] InternalEntityTypeBuilder entityTypeBuilder, ConfigurationSource? primaryKeyConfigurationSource) { diff --git a/src/EFCore/Metadata/Internal/InternalModelBuilder.cs b/src/EFCore/Metadata/Internal/InternalModelBuilder.cs index c2aa02c6889..172e8c6cd25 100644 --- a/src/EFCore/Metadata/Internal/InternalModelBuilder.cs +++ b/src/EFCore/Metadata/Internal/InternalModelBuilder.cs @@ -10,6 +10,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Internal { /// @@ -27,7 +29,7 @@ public class InternalModelBuilder : AnnotatableBuilder public InternalModelBuilder([NotNull] Model metadata) - : base(metadata, null) + : base(metadata, null!) { } @@ -46,7 +48,7 @@ public override InternalModelBuilder ModelBuilder /// 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. /// - public virtual InternalEntityTypeBuilder Entity( + public virtual InternalEntityTypeBuilder? Entity( [NotNull] string name, ConfigurationSource configurationSource, bool? shouldBeOwned = false) @@ -58,9 +60,9 @@ public virtual InternalEntityTypeBuilder Entity( /// 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. /// - public virtual InternalEntityTypeBuilder SharedTypeEntity( + public virtual InternalEntityTypeBuilder? SharedTypeEntity( [NotNull] string name, - [CanBeNull] Type type, + [CanBeNull] Type? type, ConfigurationSource configurationSource, bool? shouldBeOwned = false) => Entity(new TypeIdentity(name, type ?? Model.DefaultPropertyBagType), configurationSource, shouldBeOwned); @@ -71,13 +73,13 @@ public virtual InternalEntityTypeBuilder SharedTypeEntity( /// 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. /// - public virtual InternalEntityTypeBuilder Entity( + public virtual InternalEntityTypeBuilder? Entity( [NotNull] Type type, ConfigurationSource configurationSource, bool? shouldBeOwned = false) => Entity(new TypeIdentity(type, Metadata), configurationSource, shouldBeOwned); - private InternalEntityTypeBuilder Entity( + private InternalEntityTypeBuilder? Entity( in TypeIdentity type, ConfigurationSource configurationSource, bool? shouldBeOwned) @@ -89,8 +91,8 @@ private InternalEntityTypeBuilder Entity( using var batch = Metadata.DelayConventions(); var clrType = type.Type; - EntityType entityType; - EntityType.Snapshot entityTypeSnapshot = null; + EntityType? entityType; + EntityType.Snapshot? entityTypeSnapshot = null; if (type.IsNamed) { if (clrType != null) @@ -110,7 +112,7 @@ private InternalEntityTypeBuilder Entity( { return configurationSource == ConfigurationSource.Explicit ? throw new InvalidOperationException(CoreStrings.ClashingNonSharedType(type.Name, clrType.ShortDisplayName())) - : (InternalEntityTypeBuilder)null; + : (InternalEntityTypeBuilder?)null; } entityTypeSnapshot = InternalEntityTypeBuilder.DetachAllMembers(entityType); @@ -123,15 +125,16 @@ private InternalEntityTypeBuilder Entity( } else { + // TODO-NULLABLE: is it actually possible to have an unnamed TypeIdentity here without a CLR type? clrType = type.Type ?? Metadata.FindClrType(type.Name); - if (Metadata.IsShared(clrType)) + if (Metadata.IsShared(clrType!)) { return configurationSource == ConfigurationSource.Explicit ? throw new InvalidOperationException(CoreStrings.ClashingSharedType(clrType.ShortDisplayName())) - : (InternalEntityTypeBuilder)null; + : (InternalEntityTypeBuilder?)null; } - entityType = Metadata.FindEntityType(clrType); + entityType = Metadata.FindEntityType(clrType!); } if (shouldBeOwned == false @@ -151,7 +154,7 @@ private InternalEntityTypeBuilder Entity( && configurationSource == ConfigurationSource.Explicit && entityType.GetConfigurationSource() == ConfigurationSource.Explicit) { - throw new InvalidOperationException(CoreStrings.ClashingNonOwnedEntityType(clrType.ShortDisplayName())); + throw new InvalidOperationException(CoreStrings.ClashingNonOwnedEntityType(clrType!.ShortDisplayName())); } foreach (var derivedType in entityType.GetDerivedTypes()) @@ -184,7 +187,7 @@ private InternalEntityTypeBuilder Entity( return configurationSource == ConfigurationSource.Explicit ? throw new InvalidOperationException( CoreStrings.ClashingMismatchedSharedType(type.Name, entityType.ClrType?.ShortDisplayName())) - : (InternalEntityTypeBuilder)null; + : (InternalEntityTypeBuilder?)null; } } @@ -193,7 +196,7 @@ private InternalEntityTypeBuilder Entity( ? clrType == null ? Metadata.AddEntityType(type.Name, configurationSource) : Metadata.AddEntityType(type.Name, clrType, configurationSource) - : Metadata.AddEntityType(clrType, configurationSource); + : Metadata.AddEntityType(clrType!, configurationSource); if (entityType != null && entityTypeSnapshot != null) @@ -210,7 +213,7 @@ private InternalEntityTypeBuilder Entity( /// 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. /// - public virtual InternalEntityTypeBuilder Entity( + public virtual InternalEntityTypeBuilder? Entity( [NotNull] string name, [NotNull] string definingNavigationName, [NotNull] EntityType definingEntityType, @@ -223,14 +226,14 @@ public virtual InternalEntityTypeBuilder Entity( /// 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. /// - public virtual InternalEntityTypeBuilder Entity( + public virtual InternalEntityTypeBuilder? Entity( [NotNull] Type type, [NotNull] string definingNavigationName, [NotNull] EntityType definingEntityType, ConfigurationSource configurationSource) => Entity(new TypeIdentity(type, Metadata), definingNavigationName, definingEntityType, configurationSource); - private InternalEntityTypeBuilder Entity( + private InternalEntityTypeBuilder? Entity( in TypeIdentity type, string definingNavigationName, EntityType definingEntityType, @@ -245,11 +248,11 @@ private InternalEntityTypeBuilder Entity( /// 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. /// - public virtual InternalModelBuilder RemoveImplicitJoinEntity([NotNull] EntityType joinEntityType) + public virtual InternalModelBuilder? RemoveImplicitJoinEntity([NotNull] EntityType joinEntityType) { Check.NotNull(joinEntityType, nameof(joinEntityType)); - if (joinEntityType.Builder == null) + if (!joinEntityType.IsInModel) { return this; } @@ -268,7 +271,7 @@ public virtual InternalModelBuilder RemoveImplicitJoinEntity([NotNull] EntityTyp /// 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. /// - public virtual IConventionOwnedEntityTypeBuilder Owned( + public virtual IConventionOwnedEntityTypeBuilder? Owned( [NotNull] Type type, ConfigurationSource configurationSource) { @@ -381,7 +384,7 @@ private bool IsIgnored(in TypeIdentity type, ConfigurationSource configurationSo /// 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. /// - public virtual InternalModelBuilder Ignore([NotNull] Type type, ConfigurationSource configurationSource) + public virtual InternalModelBuilder? Ignore([NotNull] Type type, ConfigurationSource configurationSource) => Ignore(new TypeIdentity(type, Metadata), configurationSource); /// @@ -390,10 +393,10 @@ public virtual InternalModelBuilder Ignore([NotNull] Type type, ConfigurationSou /// 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. /// - public virtual InternalModelBuilder Ignore([NotNull] string name, ConfigurationSource configurationSource) + public virtual InternalModelBuilder? Ignore([NotNull] string name, ConfigurationSource configurationSource) => Ignore(new TypeIdentity(name), configurationSource); - private InternalModelBuilder Ignore(in TypeIdentity type, ConfigurationSource configurationSource) + private InternalModelBuilder? Ignore(in TypeIdentity type, ConfigurationSource configurationSource) { var name = type.Name; var ignoredConfigurationSource = Metadata.FindIgnoredConfigurationSource(name); @@ -491,7 +494,7 @@ private bool CanIgnore(in TypeIdentity type, ConfigurationSource configurationSo /// 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. /// - public virtual InternalModelBuilder HasNoEntityType([NotNull] EntityType entityType, ConfigurationSource configurationSource) + public virtual InternalModelBuilder? HasNoEntityType([NotNull] EntityType entityType, ConfigurationSource configurationSource) { var entityTypeConfigurationSource = entityType.GetConfigurationSource(); if (!configurationSource.Overrides(entityTypeConfigurationSource)) @@ -540,7 +543,7 @@ public virtual InternalModelBuilder HasNoEntityType([NotNull] EntityType entityT /// 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. /// - public virtual InternalModelBuilder UseChangeTrackingStrategy( + public virtual InternalModelBuilder? UseChangeTrackingStrategy( ChangeTrackingStrategy? changeTrackingStrategy, ConfigurationSource configurationSource) { @@ -572,7 +575,7 @@ public virtual bool CanSetChangeTrackingStrategy( /// 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. /// - public virtual InternalModelBuilder UsePropertyAccessMode( + public virtual InternalModelBuilder? UsePropertyAccessMode( PropertyAccessMode? propertyAccessMode, ConfigurationSource configurationSource) { @@ -617,7 +620,7 @@ IConventionModel IConventionModelBuilder.Metadata /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [DebuggerStepThrough] - IConventionEntityTypeBuilder IConventionModelBuilder.Entity(string name, bool? shouldBeOwned, bool fromDataAnnotation) + IConventionEntityTypeBuilder? IConventionModelBuilder.Entity(string name, bool? shouldBeOwned, bool fromDataAnnotation) => Entity(name, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention, shouldBeOwned); /// @@ -627,7 +630,7 @@ IConventionEntityTypeBuilder IConventionModelBuilder.Entity(string name, bool? s /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [DebuggerStepThrough] - IConventionEntityTypeBuilder IConventionModelBuilder.SharedTypeEntity( + IConventionEntityTypeBuilder? IConventionModelBuilder.SharedTypeEntity( string name, Type type, bool? shouldBeOwned, @@ -642,7 +645,7 @@ IConventionEntityTypeBuilder IConventionModelBuilder.SharedTypeEntity( /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [DebuggerStepThrough] - IConventionEntityTypeBuilder IConventionModelBuilder.Entity(Type type, bool? shouldBeOwned, bool fromDataAnnotation) + IConventionEntityTypeBuilder? IConventionModelBuilder.Entity(Type type, bool? shouldBeOwned, bool fromDataAnnotation) => Entity(type, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention, shouldBeOwned); /// @@ -652,7 +655,7 @@ IConventionEntityTypeBuilder IConventionModelBuilder.Entity(Type type, bool? sho /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [DebuggerStepThrough] - IConventionEntityTypeBuilder IConventionModelBuilder.Entity( + IConventionEntityTypeBuilder? IConventionModelBuilder.Entity( string name, string definingNavigationName, IConventionEntityType definingEntityType, @@ -670,7 +673,7 @@ IConventionEntityTypeBuilder IConventionModelBuilder.Entity( /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [DebuggerStepThrough] - IConventionEntityTypeBuilder IConventionModelBuilder.Entity( + IConventionEntityTypeBuilder? IConventionModelBuilder.Entity( Type type, string definingNavigationName, IConventionEntityType definingEntityType, @@ -688,7 +691,7 @@ IConventionEntityTypeBuilder IConventionModelBuilder.Entity( /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [DebuggerStepThrough] - IConventionOwnedEntityTypeBuilder IConventionModelBuilder.Owned(Type type, bool fromDataAnnotation) + IConventionOwnedEntityTypeBuilder? IConventionModelBuilder.Owned(Type type, bool fromDataAnnotation) => Owned(type, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// @@ -718,7 +721,7 @@ bool IConventionModelBuilder.IsIgnored(string name, bool fromDataAnnotation) /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [DebuggerStepThrough] - IConventionModelBuilder IConventionModelBuilder.Ignore(Type type, bool fromDataAnnotation) + IConventionModelBuilder? IConventionModelBuilder.Ignore(Type type, bool fromDataAnnotation) => Ignore(type, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// @@ -728,7 +731,7 @@ IConventionModelBuilder IConventionModelBuilder.Ignore(Type type, bool fromDataA /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [DebuggerStepThrough] - IConventionModelBuilder IConventionModelBuilder.Ignore(string name, bool fromDataAnnotation) + IConventionModelBuilder? IConventionModelBuilder.Ignore(string name, bool fromDataAnnotation) => Ignore(name, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// @@ -738,7 +741,7 @@ IConventionModelBuilder IConventionModelBuilder.Ignore(string name, bool fromDat /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [DebuggerStepThrough] - IConventionModelBuilder IConventionModelBuilder.HasNoEntityType(IConventionEntityType entityType, bool fromDataAnnotation) + IConventionModelBuilder? IConventionModelBuilder.HasNoEntityType(IConventionEntityType entityType, bool fromDataAnnotation) => HasNoEntityType( (EntityType)entityType, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); @@ -769,7 +772,7 @@ bool IConventionModelBuilder.CanIgnore(string name, bool fromDataAnnotation) /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [DebuggerStepThrough] - IConventionModelBuilder IConventionModelBuilder.HasChangeTrackingStrategy( + IConventionModelBuilder? IConventionModelBuilder.HasChangeTrackingStrategy( ChangeTrackingStrategy? changeTrackingStrategy, bool fromDataAnnotation) => UseChangeTrackingStrategy( @@ -793,7 +796,7 @@ bool IConventionModelBuilder.CanSetChangeTrackingStrategy(ChangeTrackingStrategy /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [DebuggerStepThrough] - IConventionModelBuilder IConventionModelBuilder.UsePropertyAccessMode( + IConventionModelBuilder? IConventionModelBuilder.UsePropertyAccessMode( PropertyAccessMode? propertyAccessMode, bool fromDataAnnotation) => UsePropertyAccessMode( diff --git a/src/EFCore/Metadata/Internal/InternalNavigationBuilder.cs b/src/EFCore/Metadata/Internal/InternalNavigationBuilder.cs index 23871fc283a..02a4477eba9 100644 --- a/src/EFCore/Metadata/Internal/InternalNavigationBuilder.cs +++ b/src/EFCore/Metadata/Internal/InternalNavigationBuilder.cs @@ -8,6 +8,8 @@ using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Metadata.Builders; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Internal { /// @@ -35,8 +37,8 @@ public InternalNavigationBuilder([NotNull] Navigation metadata, [NotNull] Intern /// 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. /// - public new virtual InternalNavigationBuilder HasField([CanBeNull] string fieldName, ConfigurationSource configurationSource) - => (InternalNavigationBuilder)base.HasField(fieldName, configurationSource); + public new virtual InternalNavigationBuilder? HasField([CanBeNull] string? fieldName, ConfigurationSource configurationSource) + => (InternalNavigationBuilder?)base.HasField(fieldName, configurationSource); /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -44,8 +46,8 @@ public InternalNavigationBuilder([NotNull] Navigation metadata, [NotNull] Intern /// 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. /// - public new virtual InternalNavigationBuilder HasField([CanBeNull] FieldInfo fieldInfo, ConfigurationSource configurationSource) - => (InternalNavigationBuilder)base.HasField(fieldInfo, configurationSource); + public new virtual InternalNavigationBuilder? HasField([CanBeNull] FieldInfo? fieldInfo, ConfigurationSource configurationSource) + => (InternalNavigationBuilder?)base.HasField(fieldInfo, configurationSource); /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -53,10 +55,10 @@ public InternalNavigationBuilder([NotNull] Navigation metadata, [NotNull] Intern /// 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. /// - public new virtual InternalNavigationBuilder UsePropertyAccessMode( + public new virtual InternalNavigationBuilder? UsePropertyAccessMode( PropertyAccessMode? propertyAccessMode, ConfigurationSource configurationSource) - => (InternalNavigationBuilder)base.UsePropertyAccessMode(propertyAccessMode, configurationSource); + => (InternalNavigationBuilder?)base.UsePropertyAccessMode(propertyAccessMode, configurationSource); /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -78,7 +80,7 @@ public virtual bool CanSetAutoInclude(bool? autoInclude, ConfigurationSource con /// 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. /// - public virtual InternalNavigationBuilder AutoInclude(bool? autoInclude, ConfigurationSource configurationSource) + public virtual InternalNavigationBuilder? AutoInclude(bool? autoInclude, ConfigurationSource configurationSource) { if (CanSetAutoInclude(autoInclude, configurationSource)) { @@ -116,7 +118,7 @@ public virtual bool CanSetIsRequired(bool? required, ConfigurationSource configu /// 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. /// - public virtual InternalNavigationBuilder IsRequired(bool? required, ConfigurationSource configurationSource) + public virtual InternalNavigationBuilder? IsRequired(bool? required, ConfigurationSource configurationSource) { if (configurationSource == ConfigurationSource.Explicit || CanSetIsRequired(required, configurationSource)) @@ -134,16 +136,16 @@ public virtual InternalNavigationBuilder IsRequired(bool? required, Configuratio } return Metadata.IsOnDependent - ? foreignKey.Builder.IsRequired(required, configurationSource) - .Metadata.DependentToPrincipal.Builder - : foreignKey.Builder.IsRequiredDependent(required, configurationSource) - .Metadata.PrincipalToDependent.Builder; + ? foreignKey.Builder.IsRequired(required, configurationSource)! + .Metadata.DependentToPrincipal!.Builder + : foreignKey.Builder.IsRequiredDependent(required, configurationSource)! + .Metadata.PrincipalToDependent!.Builder; } if (Metadata.IsOnDependent) { - return foreignKey.Builder.IsRequired(required, configurationSource) - .Metadata.DependentToPrincipal.Builder; + return foreignKey.Builder.IsRequired(required, configurationSource)! + .Metadata.DependentToPrincipal!.Builder; } throw new InvalidOperationException( @@ -174,7 +176,7 @@ bool IConventionPropertyBaseBuilder.CanSetPropertyAccessMode(PropertyAccessMode? /// [DebuggerStepThrough] - IConventionPropertyBaseBuilder IConventionPropertyBaseBuilder.UsePropertyAccessMode( + IConventionPropertyBaseBuilder? IConventionPropertyBaseBuilder.UsePropertyAccessMode( PropertyAccessMode? propertyAccessMode, bool fromDataAnnotation) => UsePropertyAccessMode( @@ -182,7 +184,7 @@ IConventionPropertyBaseBuilder IConventionPropertyBaseBuilder.UsePropertyAccessM /// [DebuggerStepThrough] - IConventionNavigationBuilder IConventionNavigationBuilder.UsePropertyAccessMode( + IConventionNavigationBuilder? IConventionNavigationBuilder.UsePropertyAccessMode( PropertyAccessMode? propertyAccessMode, bool fromDataAnnotation) => UsePropertyAccessMode( @@ -190,42 +192,42 @@ IConventionNavigationBuilder IConventionNavigationBuilder.UsePropertyAccessMode( /// [DebuggerStepThrough] - bool IConventionPropertyBaseBuilder.CanSetField(string fieldName, bool fromDataAnnotation) + bool IConventionPropertyBaseBuilder.CanSetField(string? fieldName, bool fromDataAnnotation) => CanSetField( fieldName, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// [DebuggerStepThrough] - IConventionPropertyBaseBuilder IConventionPropertyBaseBuilder.HasField(string fieldName, bool fromDataAnnotation) + IConventionPropertyBaseBuilder? IConventionPropertyBaseBuilder.HasField(string? fieldName, bool fromDataAnnotation) => HasField( fieldName, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// [DebuggerStepThrough] - IConventionNavigationBuilder IConventionNavigationBuilder.HasField(string fieldName, bool fromDataAnnotation) + IConventionNavigationBuilder? IConventionNavigationBuilder.HasField(string? fieldName, bool fromDataAnnotation) => HasField( fieldName, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// [DebuggerStepThrough] - bool IConventionPropertyBaseBuilder.CanSetField(FieldInfo fieldInfo, bool fromDataAnnotation) + bool IConventionPropertyBaseBuilder.CanSetField(FieldInfo? fieldInfo, bool fromDataAnnotation) => CanSetField( fieldInfo, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// [DebuggerStepThrough] - IConventionPropertyBaseBuilder IConventionPropertyBaseBuilder.HasField(FieldInfo fieldInfo, bool fromDataAnnotation) + IConventionPropertyBaseBuilder? IConventionPropertyBaseBuilder.HasField(FieldInfo? fieldInfo, bool fromDataAnnotation) => HasField( fieldInfo, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// [DebuggerStepThrough] - IConventionNavigationBuilder IConventionNavigationBuilder.HasField(FieldInfo fieldInfo, bool fromDataAnnotation) + IConventionNavigationBuilder? IConventionNavigationBuilder.HasField(FieldInfo? fieldInfo, bool fromDataAnnotation) => HasField( fieldInfo, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); @@ -237,7 +239,7 @@ bool IConventionNavigationBuilder.CanSetAutoInclude(bool? autoInclude, bool from /// [DebuggerStepThrough] - IConventionNavigationBuilder IConventionNavigationBuilder.AutoInclude(bool? autoInclude, bool fromDataAnnotation) + IConventionNavigationBuilder? IConventionNavigationBuilder.AutoInclude(bool? autoInclude, bool fromDataAnnotation) => AutoInclude(autoInclude, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// @@ -247,7 +249,7 @@ bool IConventionNavigationBuilder.CanSetIsRequired(bool? required, bool fromData /// [DebuggerStepThrough] - IConventionNavigationBuilder IConventionNavigationBuilder.IsRequired(bool? required, bool fromDataAnnotation) + IConventionNavigationBuilder? IConventionNavigationBuilder.IsRequired(bool? required, bool fromDataAnnotation) => IsRequired(required, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); } } diff --git a/src/EFCore/Metadata/Internal/InternalOwnedEntityTypeBuilder.cs b/src/EFCore/Metadata/Internal/InternalOwnedEntityTypeBuilder.cs index 46a64d748ff..460eabb5682 100644 --- a/src/EFCore/Metadata/Internal/InternalOwnedEntityTypeBuilder.cs +++ b/src/EFCore/Metadata/Internal/InternalOwnedEntityTypeBuilder.cs @@ -3,6 +3,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Builders; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Internal { /// diff --git a/src/EFCore/Metadata/Internal/InternalPropertyBaseBuilder`.cs b/src/EFCore/Metadata/Internal/InternalPropertyBaseBuilder`.cs index 8144eef0f24..aebc7360351 100644 --- a/src/EFCore/Metadata/Internal/InternalPropertyBaseBuilder`.cs +++ b/src/EFCore/Metadata/Internal/InternalPropertyBaseBuilder`.cs @@ -5,6 +5,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Infrastructure; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Internal { /// @@ -33,8 +35,8 @@ public InternalPropertyBaseBuilder([NotNull] TPropertyBase metadata, [NotNull] I /// 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. /// - public virtual InternalPropertyBaseBuilder HasField( - [CanBeNull] string fieldName, + public virtual InternalPropertyBaseBuilder? HasField( + [CanBeNull] string? fieldName, ConfigurationSource configurationSource) { if (CanSetField(fieldName, configurationSource)) @@ -53,7 +55,7 @@ public virtual InternalPropertyBaseBuilder HasField( /// 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. /// - public virtual bool CanSetField([CanBeNull] string fieldName, ConfigurationSource? configurationSource) + public virtual bool CanSetField([CanBeNull] string? fieldName, ConfigurationSource? configurationSource) { if (configurationSource.Overrides(Metadata.GetFieldInfoConfigurationSource())) { @@ -81,8 +83,8 @@ public virtual bool CanSetField([CanBeNull] string fieldName, ConfigurationSourc /// 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. /// - public virtual InternalPropertyBaseBuilder HasField( - [CanBeNull] FieldInfo fieldInfo, + public virtual InternalPropertyBaseBuilder? HasField( + [CanBeNull] FieldInfo? fieldInfo, ConfigurationSource configurationSource) { if (CanSetField(fieldInfo, configurationSource)) @@ -101,7 +103,7 @@ public virtual InternalPropertyBaseBuilder HasField( /// 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. /// - public virtual bool CanSetField([CanBeNull] FieldInfo fieldInfo, ConfigurationSource? configurationSource) + public virtual bool CanSetField([CanBeNull] FieldInfo? fieldInfo, ConfigurationSource? configurationSource) => (configurationSource.Overrides(Metadata.GetFieldInfoConfigurationSource()) && (fieldInfo == null || PropertyBase.IsCompatible( @@ -115,7 +117,7 @@ public virtual bool CanSetField([CanBeNull] FieldInfo fieldInfo, ConfigurationSo /// 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. /// - public virtual InternalPropertyBaseBuilder UsePropertyAccessMode( + public virtual InternalPropertyBaseBuilder? UsePropertyAccessMode( PropertyAccessMode? propertyAccessMode, ConfigurationSource configurationSource) { diff --git a/src/EFCore/Metadata/Internal/InternalPropertyBuilder.cs b/src/EFCore/Metadata/Internal/InternalPropertyBuilder.cs index 8ec52043a32..62db8cdf9bd 100644 --- a/src/EFCore/Metadata/Internal/InternalPropertyBuilder.cs +++ b/src/EFCore/Metadata/Internal/InternalPropertyBuilder.cs @@ -15,6 +15,8 @@ using Microsoft.EntityFrameworkCore.Utilities; using Microsoft.EntityFrameworkCore.ValueGeneration; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Internal { /// @@ -42,7 +44,7 @@ public InternalPropertyBuilder([NotNull] Property property, [NotNull] InternalMo /// 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. /// - public virtual InternalPropertyBuilder IsRequired(bool? required, ConfigurationSource configurationSource) + public virtual InternalPropertyBuilder? IsRequired(bool? required, ConfigurationSource configurationSource) { if (configurationSource != ConfigurationSource.Explicit && !CanSetIsRequired(required, configurationSource)) @@ -98,7 +100,7 @@ public virtual bool CanSetIsRequired(bool? required, ConfigurationSource? config /// 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. /// - public virtual InternalPropertyBuilder ValueGenerated(ValueGenerated? valueGenerated, ConfigurationSource configurationSource) + public virtual InternalPropertyBuilder? ValueGenerated(ValueGenerated? valueGenerated, ConfigurationSource configurationSource) { if (CanSetValueGenerated(valueGenerated, configurationSource)) { @@ -126,7 +128,7 @@ public virtual bool CanSetValueGenerated(ValueGenerated? valueGenerated, Configu /// 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. /// - public virtual InternalPropertyBuilder IsConcurrencyToken(bool? concurrencyToken, ConfigurationSource configurationSource) + public virtual InternalPropertyBuilder? IsConcurrencyToken(bool? concurrencyToken, ConfigurationSource configurationSource) { if (CanSetIsConcurrencyToken(concurrencyToken, configurationSource)) { @@ -153,8 +155,8 @@ public virtual bool CanSetIsConcurrencyToken(bool? concurrencyToken, Configurati /// 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. /// - public new virtual InternalPropertyBuilder HasField([CanBeNull] string fieldName, ConfigurationSource configurationSource) - => (InternalPropertyBuilder)base.HasField(fieldName, configurationSource); + public new virtual InternalPropertyBuilder? HasField([CanBeNull] string? fieldName, ConfigurationSource configurationSource) + => (InternalPropertyBuilder?)base.HasField(fieldName, configurationSource); /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -162,8 +164,8 @@ public virtual bool CanSetIsConcurrencyToken(bool? concurrencyToken, Configurati /// 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. /// - public new virtual InternalPropertyBuilder HasField([CanBeNull] FieldInfo fieldInfo, ConfigurationSource configurationSource) - => (InternalPropertyBuilder)base.HasField(fieldInfo, configurationSource); + public new virtual InternalPropertyBuilder? HasField([CanBeNull] FieldInfo? fieldInfo, ConfigurationSource configurationSource) + => (InternalPropertyBuilder?)base.HasField(fieldInfo, configurationSource); /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -171,10 +173,10 @@ public virtual bool CanSetIsConcurrencyToken(bool? concurrencyToken, Configurati /// 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. /// - public new virtual InternalPropertyBuilder UsePropertyAccessMode( + public new virtual InternalPropertyBuilder? UsePropertyAccessMode( PropertyAccessMode? propertyAccessMode, ConfigurationSource configurationSource) - => (InternalPropertyBuilder)base.UsePropertyAccessMode(propertyAccessMode, configurationSource); + => (InternalPropertyBuilder?)base.UsePropertyAccessMode(propertyAccessMode, configurationSource); /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -182,7 +184,7 @@ public virtual bool CanSetIsConcurrencyToken(bool? concurrencyToken, Configurati /// 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. /// - public virtual InternalPropertyBuilder HasMaxLength(int? maxLength, ConfigurationSource configurationSource) + public virtual InternalPropertyBuilder? HasMaxLength(int? maxLength, ConfigurationSource configurationSource) { if (CanSetMaxLength(maxLength, configurationSource)) { @@ -210,7 +212,7 @@ public virtual bool CanSetMaxLength(int? maxLength, ConfigurationSource? configu /// 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. /// - public virtual InternalPropertyBuilder HasPrecision(int? precision, ConfigurationSource configurationSource) + public virtual InternalPropertyBuilder? HasPrecision(int? precision, ConfigurationSource configurationSource) { if (CanSetPrecision(precision, configurationSource)) { @@ -238,7 +240,7 @@ public virtual bool CanSetPrecision(int? precision, ConfigurationSource? configu /// 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. /// - public virtual InternalPropertyBuilder HasScale(int? scale, ConfigurationSource configurationSource) + public virtual InternalPropertyBuilder? HasScale(int? scale, ConfigurationSource configurationSource) { if (CanSetScale(scale, configurationSource)) { @@ -266,7 +268,7 @@ public virtual bool CanSetScale(int? scale, ConfigurationSource? configurationSo /// 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. /// - public virtual InternalPropertyBuilder IsUnicode(bool? unicode, ConfigurationSource configurationSource) + public virtual InternalPropertyBuilder? IsUnicode(bool? unicode, ConfigurationSource configurationSource) { if (CanSetIsUnicode(unicode, configurationSource)) { @@ -294,7 +296,7 @@ public virtual bool CanSetIsUnicode(bool? unicode, ConfigurationSource? configur /// 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. /// - public virtual InternalPropertyBuilder BeforeSave(PropertySaveBehavior? behavior, ConfigurationSource configurationSource) + public virtual InternalPropertyBuilder? BeforeSave(PropertySaveBehavior? behavior, ConfigurationSource configurationSource) { if (CanSetBeforeSave(behavior, configurationSource)) { @@ -322,7 +324,7 @@ public virtual bool CanSetBeforeSave(PropertySaveBehavior? behavior, Configurati /// 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. /// - public virtual InternalPropertyBuilder AfterSave(PropertySaveBehavior? behavior, ConfigurationSource configurationSource) + public virtual InternalPropertyBuilder? AfterSave(PropertySaveBehavior? behavior, ConfigurationSource configurationSource) { if (CanSetAfterSave(behavior, configurationSource)) { @@ -352,13 +354,13 @@ public virtual bool CanSetAfterSave(PropertySaveBehavior? behavior, Configuratio /// 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. /// - public virtual InternalPropertyBuilder HasValueGenerator( - [CanBeNull] Type valueGeneratorType, + public virtual InternalPropertyBuilder? HasValueGenerator( + [CanBeNull] Type? valueGeneratorType, ConfigurationSource configurationSource) { if (valueGeneratorType == null) { - return HasValueGenerator((Func)null, configurationSource); + return HasValueGenerator((Func?)null, configurationSource); } if (!typeof(ValueGenerator).IsAssignableFrom(valueGeneratorType)) @@ -373,7 +375,7 @@ public virtual InternalPropertyBuilder HasValueGenerator( { try { - return (ValueGenerator)Activator.CreateInstance(valueGeneratorType); + return (ValueGenerator)Activator.CreateInstance(valueGeneratorType)!; } catch (Exception e) { @@ -389,8 +391,8 @@ public virtual InternalPropertyBuilder HasValueGenerator( /// 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. /// - public virtual InternalPropertyBuilder HasValueGenerator( - [CanBeNull] Func factory, + public virtual InternalPropertyBuilder? HasValueGenerator( + [CanBeNull] Func? factory, ConfigurationSource configurationSource) { if (CanSetValueGenerator(factory, configurationSource)) @@ -410,7 +412,7 @@ public virtual InternalPropertyBuilder HasValueGenerator( /// doing so can result in application failures when updating to a new Entity Framework Core release. /// public virtual bool CanSetValueGenerator( - [CanBeNull] Func factory, + [CanBeNull] Func? factory, ConfigurationSource? configurationSource) => configurationSource.Overrides(Metadata.GetValueGeneratorFactoryConfigurationSource()) || Metadata.GetValueGeneratorFactory() == factory; @@ -421,7 +423,7 @@ public virtual bool CanSetValueGenerator( /// 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. /// - public virtual InternalPropertyBuilder HasConversion([CanBeNull] ValueConverter converter, ConfigurationSource configurationSource) + public virtual InternalPropertyBuilder? HasConversion([CanBeNull] ValueConverter? converter, ConfigurationSource configurationSource) { if (CanSetConversion(converter, configurationSource)) { @@ -440,7 +442,7 @@ public virtual InternalPropertyBuilder HasConversion([CanBeNull] ValueConverter /// doing so can result in application failures when updating to a new Entity Framework Core release. /// public virtual bool CanSetConversion( - [CanBeNull] ValueConverter converter, + [CanBeNull] ValueConverter? converter, ConfigurationSource? configurationSource) => configurationSource == ConfigurationSource.Explicit || (configurationSource.Overrides(Metadata.GetValueConverterConfigurationSource()) @@ -453,7 +455,7 @@ public virtual bool CanSetConversion( /// 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. /// - public virtual InternalPropertyBuilder HasConversion([CanBeNull] Type providerClrType, ConfigurationSource configurationSource) + public virtual InternalPropertyBuilder? HasConversion([CanBeNull] Type? providerClrType, ConfigurationSource configurationSource) { if (CanSetConversion(providerClrType, configurationSource)) { @@ -471,7 +473,7 @@ public virtual InternalPropertyBuilder HasConversion([CanBeNull] Type providerCl /// 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. /// - public virtual bool CanSetConversion([CanBeNull] Type providerClrType, ConfigurationSource? configurationSource) + public virtual bool CanSetConversion([CanBeNull] Type? providerClrType, ConfigurationSource? configurationSource) => configurationSource.Overrides(Metadata.GetProviderClrTypeConfigurationSource()) || Metadata.GetProviderClrType() == providerClrType; @@ -481,8 +483,8 @@ public virtual bool CanSetConversion([CanBeNull] Type providerClrType, Configura /// 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. /// - public virtual InternalPropertyBuilder HasTypeMapping( - [NotNull] CoreTypeMapping typeMapping, + public virtual InternalPropertyBuilder? HasTypeMapping( + [CanBeNull] CoreTypeMapping? typeMapping, ConfigurationSource configurationSource) { if (CanSetTypeMapping(typeMapping, configurationSource)) @@ -501,7 +503,7 @@ public virtual InternalPropertyBuilder HasTypeMapping( /// 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. /// - public virtual bool CanSetTypeMapping([CanBeNull] CoreTypeMapping typeMapping, ConfigurationSource? configurationSource) + public virtual bool CanSetTypeMapping([CanBeNull] CoreTypeMapping? typeMapping, ConfigurationSource? configurationSource) => configurationSource.Overrides(Metadata.GetTypeMappingConfigurationSource()) || Metadata.TypeMapping == typeMapping; @@ -511,8 +513,8 @@ public virtual bool CanSetTypeMapping([CanBeNull] CoreTypeMapping typeMapping, C /// 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. /// - public virtual InternalPropertyBuilder HasValueComparer( - [CanBeNull] ValueComparer comparer, + public virtual InternalPropertyBuilder? HasValueComparer( + [CanBeNull] ValueComparer? comparer, ConfigurationSource configurationSource) { if (CanSetValueComparer(comparer, configurationSource)) @@ -531,7 +533,7 @@ public virtual InternalPropertyBuilder HasValueComparer( /// 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. /// - public virtual bool CanSetValueComparer([CanBeNull] ValueComparer comparer, ConfigurationSource? configurationSource) + public virtual bool CanSetValueComparer([CanBeNull] ValueComparer? comparer, ConfigurationSource? configurationSource) { if (configurationSource.Overrides(Metadata.GetValueComparerConfigurationSource())) { @@ -558,8 +560,8 @@ public virtual bool CanSetValueComparer([CanBeNull] ValueComparer comparer, Conf /// 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. /// - public virtual InternalPropertyBuilder HasKeyValueComparer( - [CanBeNull] ValueComparer comparer, + public virtual InternalPropertyBuilder? HasKeyValueComparer( + [CanBeNull] ValueComparer? comparer, ConfigurationSource configurationSource) => HasValueComparer(comparer, configurationSource); @@ -569,7 +571,7 @@ public virtual InternalPropertyBuilder HasKeyValueComparer( /// 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. /// - public virtual bool CanSetKeyValueComparer([CanBeNull] ValueComparer comparer, ConfigurationSource? configurationSource) + public virtual bool CanSetKeyValueComparer([CanBeNull] ValueComparer? comparer, ConfigurationSource? configurationSource) => CanSetValueComparer(comparer, configurationSource); /// @@ -585,6 +587,7 @@ public virtual InternalPropertyBuilder Attach([NotNull] InternalEntityTypeBuilde var configurationSource = Metadata.GetConfigurationSource(); var typeConfigurationSource = Metadata.GetTypeConfigurationSource(); if (newProperty != null + && newProperty.IsInModel && (newProperty.GetConfigurationSource().Overrides(configurationSource) || newProperty.GetTypeConfigurationSource().Overrides(typeConfigurationSource) || (Metadata.ClrType == newProperty.ClrType @@ -603,10 +606,10 @@ public virtual InternalPropertyBuilder Attach([NotNull] InternalEntityTypeBuilde newPropertyBuilder = identifyingMemberInfo == null ? entityTypeBuilder.Property( - Metadata.ClrType, Metadata.Name, Metadata.GetTypeConfigurationSource(), configurationSource) + Metadata.ClrType, Metadata.Name, Metadata.GetTypeConfigurationSource(), configurationSource)! : (identifyingMemberInfo as PropertyInfo)?.IsIndexerProperty() == true - ? entityTypeBuilder.IndexerProperty(Metadata.ClrType, Metadata.Name, configurationSource) - : entityTypeBuilder.Property(identifyingMemberInfo, configurationSource); + ? entityTypeBuilder.IndexerProperty(Metadata.ClrType, Metadata.Name, configurationSource)! + : entityTypeBuilder.Property(identifyingMemberInfo, configurationSource!)!; } if (newProperty == Metadata) @@ -699,7 +702,7 @@ IConventionProperty IConventionPropertyBuilder.Metadata /// 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. /// - IConventionPropertyBuilder IConventionPropertyBuilder.IsRequired(bool? required, bool fromDataAnnotation) + IConventionPropertyBuilder? IConventionPropertyBuilder.IsRequired(bool? required, bool fromDataAnnotation) => IsRequired(required, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// @@ -717,7 +720,7 @@ bool IConventionPropertyBuilder.CanSetIsRequired(bool? required, bool fromDataAn /// 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. /// - IConventionPropertyBuilder IConventionPropertyBuilder.ValueGenerated(ValueGenerated? valueGenerated, bool fromDataAnnotation) + IConventionPropertyBuilder? IConventionPropertyBuilder.ValueGenerated(ValueGenerated? valueGenerated, bool fromDataAnnotation) => ValueGenerated(valueGenerated, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// @@ -736,7 +739,7 @@ bool IConventionPropertyBuilder.CanSetValueGenerated(ValueGenerated? valueGenera /// 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. /// - IConventionPropertyBuilder IConventionPropertyBuilder.IsConcurrencyToken(bool? concurrencyToken, bool fromDataAnnotation) + IConventionPropertyBuilder? IConventionPropertyBuilder.IsConcurrencyToken(bool? concurrencyToken, bool fromDataAnnotation) => IsConcurrencyToken( concurrencyToken, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); @@ -756,7 +759,7 @@ bool IConventionPropertyBuilder.CanSetIsConcurrencyToken(bool? concurrencyToken, /// 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. /// - IConventionPropertyBaseBuilder IConventionPropertyBaseBuilder.HasField(string fieldName, bool fromDataAnnotation) + IConventionPropertyBaseBuilder? IConventionPropertyBaseBuilder.HasField(string? fieldName, bool fromDataAnnotation) => HasField(fieldName, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// @@ -765,7 +768,7 @@ IConventionPropertyBaseBuilder IConventionPropertyBaseBuilder.HasField(string fi /// 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. /// - IConventionPropertyBuilder IConventionPropertyBuilder.HasField(string fieldName, bool fromDataAnnotation) + IConventionPropertyBuilder? IConventionPropertyBuilder.HasField(string? fieldName, bool fromDataAnnotation) => HasField(fieldName, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// @@ -774,7 +777,7 @@ IConventionPropertyBuilder IConventionPropertyBuilder.HasField(string fieldName, /// 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. /// - IConventionPropertyBaseBuilder IConventionPropertyBaseBuilder.HasField(FieldInfo fieldInfo, bool fromDataAnnotation) + IConventionPropertyBaseBuilder? IConventionPropertyBaseBuilder.HasField(FieldInfo? fieldInfo, bool fromDataAnnotation) => HasField(fieldInfo, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// @@ -783,7 +786,7 @@ IConventionPropertyBaseBuilder IConventionPropertyBaseBuilder.HasField(FieldInfo /// 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. /// - IConventionPropertyBuilder IConventionPropertyBuilder.HasField(FieldInfo fieldInfo, bool fromDataAnnotation) + IConventionPropertyBuilder? IConventionPropertyBuilder.HasField(FieldInfo? fieldInfo, bool fromDataAnnotation) => HasField(fieldInfo, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// @@ -792,7 +795,7 @@ IConventionPropertyBuilder IConventionPropertyBuilder.HasField(FieldInfo fieldIn /// 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. /// - bool IConventionPropertyBaseBuilder.CanSetField(string fieldName, bool fromDataAnnotation) + bool IConventionPropertyBaseBuilder.CanSetField(string? fieldName, bool fromDataAnnotation) => CanSetField(fieldName, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// @@ -801,7 +804,7 @@ bool IConventionPropertyBaseBuilder.CanSetField(string fieldName, bool fromDataA /// 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. /// - bool IConventionPropertyBaseBuilder.CanSetField(FieldInfo fieldInfo, bool fromDataAnnotation) + bool IConventionPropertyBaseBuilder.CanSetField(FieldInfo? fieldInfo, bool fromDataAnnotation) => CanSetField(fieldInfo, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// @@ -810,7 +813,7 @@ bool IConventionPropertyBaseBuilder.CanSetField(FieldInfo fieldInfo, bool fromDa /// 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. /// - IConventionPropertyBaseBuilder IConventionPropertyBaseBuilder.UsePropertyAccessMode( + IConventionPropertyBaseBuilder? IConventionPropertyBaseBuilder.UsePropertyAccessMode( PropertyAccessMode? propertyAccessMode, bool fromDataAnnotation) => UsePropertyAccessMode( @@ -822,7 +825,7 @@ IConventionPropertyBaseBuilder IConventionPropertyBaseBuilder.UsePropertyAccessM /// 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. /// - IConventionPropertyBuilder IConventionPropertyBuilder.UsePropertyAccessMode( + IConventionPropertyBuilder? IConventionPropertyBuilder.UsePropertyAccessMode( PropertyAccessMode? propertyAccessMode, bool fromDataAnnotation) => UsePropertyAccessMode( @@ -844,7 +847,7 @@ bool IConventionPropertyBaseBuilder.CanSetPropertyAccessMode(PropertyAccessMode? /// 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. /// - IConventionPropertyBuilder IConventionPropertyBuilder.HasMaxLength(int? maxLength, bool fromDataAnnotation) + IConventionPropertyBuilder? IConventionPropertyBuilder.HasMaxLength(int? maxLength, bool fromDataAnnotation) => HasMaxLength(maxLength, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// @@ -862,7 +865,7 @@ bool IConventionPropertyBuilder.CanSetMaxLength(int? maxLength, bool fromDataAnn /// 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. /// - IConventionPropertyBuilder IConventionPropertyBuilder.IsUnicode(bool? unicode, bool fromDataAnnotation) + IConventionPropertyBuilder? IConventionPropertyBuilder.IsUnicode(bool? unicode, bool fromDataAnnotation) => IsUnicode(unicode, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// @@ -880,7 +883,7 @@ bool IConventionPropertyBuilder.CanSetIsUnicode(bool? unicode, bool fromDataAnno /// 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. /// - IConventionPropertyBuilder IConventionPropertyBuilder.HasPrecision(int? precision, bool fromDataAnnotation) + IConventionPropertyBuilder? IConventionPropertyBuilder.HasPrecision(int? precision, bool fromDataAnnotation) => HasPrecision(precision, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// @@ -898,7 +901,7 @@ bool IConventionPropertyBuilder.CanSetPrecision(int? precision, bool fromDataAnn /// 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. /// - IConventionPropertyBuilder IConventionPropertyBuilder.HasScale(int? scale, bool fromDataAnnotation) + IConventionPropertyBuilder? IConventionPropertyBuilder.HasScale(int? scale, bool fromDataAnnotation) => HasScale(scale, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// @@ -916,7 +919,7 @@ bool IConventionPropertyBuilder.CanSetScale(int? scale, bool fromDataAnnotation) /// 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. /// - IConventionPropertyBuilder IConventionPropertyBuilder.BeforeSave(PropertySaveBehavior? behavior, bool fromDataAnnotation) + IConventionPropertyBuilder? IConventionPropertyBuilder.BeforeSave(PropertySaveBehavior? behavior, bool fromDataAnnotation) => BeforeSave(behavior, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// @@ -934,7 +937,7 @@ bool IConventionPropertyBuilder.CanSetBeforeSave(PropertySaveBehavior? behavior, /// 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. /// - IConventionPropertyBuilder IConventionPropertyBuilder.AfterSave(PropertySaveBehavior? behavior, bool fromDataAnnotation) + IConventionPropertyBuilder? IConventionPropertyBuilder.AfterSave(PropertySaveBehavior? behavior, bool fromDataAnnotation) => AfterSave(behavior, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// @@ -952,7 +955,7 @@ bool IConventionPropertyBuilder.CanSetAfterSave(PropertySaveBehavior? behavior, /// 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. /// - IConventionPropertyBuilder IConventionPropertyBuilder.HasValueGenerator(Type valueGeneratorType, bool fromDataAnnotation) + IConventionPropertyBuilder? IConventionPropertyBuilder.HasValueGenerator(Type? valueGeneratorType, bool fromDataAnnotation) => HasValueGenerator( valueGeneratorType, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); @@ -962,8 +965,8 @@ IConventionPropertyBuilder IConventionPropertyBuilder.HasValueGenerator(Type val /// 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. /// - IConventionPropertyBuilder IConventionPropertyBuilder.HasValueGenerator( - Func factory, + IConventionPropertyBuilder? IConventionPropertyBuilder.HasValueGenerator( + Func? factory, bool fromDataAnnotation) => HasValueGenerator(factory, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); @@ -973,7 +976,7 @@ IConventionPropertyBuilder IConventionPropertyBuilder.HasValueGenerator( /// 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. /// - bool IConventionPropertyBuilder.CanSetValueGenerator(Func factory, bool fromDataAnnotation) + bool IConventionPropertyBuilder.CanSetValueGenerator(Func? factory, bool fromDataAnnotation) => CanSetValueGenerator(factory, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// @@ -982,7 +985,7 @@ bool IConventionPropertyBuilder.CanSetValueGenerator(Func - IConventionPropertyBuilder IConventionPropertyBuilder.HasConversion(ValueConverter converter, bool fromDataAnnotation) + IConventionPropertyBuilder? IConventionPropertyBuilder.HasConversion(ValueConverter? converter, bool fromDataAnnotation) => HasConversion(converter, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// @@ -991,7 +994,7 @@ IConventionPropertyBuilder IConventionPropertyBuilder.HasConversion(ValueConvert /// 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. /// - bool IConventionPropertyBuilder.CanSetConversion(ValueConverter converter, bool fromDataAnnotation) + bool IConventionPropertyBuilder.CanSetConversion(ValueConverter? converter, bool fromDataAnnotation) => CanSetConversion(converter, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// @@ -1000,7 +1003,7 @@ bool IConventionPropertyBuilder.CanSetConversion(ValueConverter converter, bool /// 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. /// - IConventionPropertyBuilder IConventionPropertyBuilder.HasConversion(Type providerClrType, bool fromDataAnnotation) + IConventionPropertyBuilder? IConventionPropertyBuilder.HasConversion(Type? providerClrType, bool fromDataAnnotation) => HasConversion(providerClrType, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// @@ -1009,11 +1012,11 @@ IConventionPropertyBuilder IConventionPropertyBuilder.HasConversion(Type provide /// 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. /// - bool IConventionPropertyBuilder.CanSetConversion(Type providerClrType, bool fromDataAnnotation) + bool IConventionPropertyBuilder.CanSetConversion(Type? providerClrType, bool fromDataAnnotation) => CanSetConversion(providerClrType, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// - IConventionPropertyBuilder IConventionPropertyBuilder.HasTypeMapping(CoreTypeMapping typeMapping, bool fromDataAnnotation) + IConventionPropertyBuilder? IConventionPropertyBuilder.HasTypeMapping(CoreTypeMapping? typeMapping, bool fromDataAnnotation) => HasTypeMapping(typeMapping, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// @@ -1026,7 +1029,7 @@ bool IConventionPropertyBuilder.CanSetTypeMapping(CoreTypeMapping typeMapping, b /// 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. /// - IConventionPropertyBuilder IConventionPropertyBuilder.HasValueComparer(ValueComparer comparer, bool fromDataAnnotation) + IConventionPropertyBuilder? IConventionPropertyBuilder.HasValueComparer(ValueComparer? comparer, bool fromDataAnnotation) => HasValueComparer(comparer, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// @@ -1035,7 +1038,7 @@ IConventionPropertyBuilder IConventionPropertyBuilder.HasValueComparer(ValueComp /// 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. /// - bool IConventionPropertyBuilder.CanSetValueComparer(ValueComparer comparer, bool fromDataAnnotation) + bool IConventionPropertyBuilder.CanSetValueComparer(ValueComparer? comparer, bool fromDataAnnotation) => CanSetValueComparer(comparer, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// @@ -1044,7 +1047,7 @@ bool IConventionPropertyBuilder.CanSetValueComparer(ValueComparer comparer, bool /// 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. /// - IConventionPropertyBuilder IConventionPropertyBuilder.HasKeyValueComparer(ValueComparer comparer, bool fromDataAnnotation) + IConventionPropertyBuilder? IConventionPropertyBuilder.HasKeyValueComparer(ValueComparer? comparer, bool fromDataAnnotation) => HasKeyValueComparer(comparer, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// @@ -1053,7 +1056,7 @@ IConventionPropertyBuilder IConventionPropertyBuilder.HasKeyValueComparer(ValueC /// 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. /// - bool IConventionPropertyBuilder.CanSetKeyValueComparer(ValueComparer comparer, bool fromDataAnnotation) + bool IConventionPropertyBuilder.CanSetKeyValueComparer(ValueComparer? comparer, bool fromDataAnnotation) => CanSetKeyValueComparer(comparer, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// @@ -1062,7 +1065,7 @@ bool IConventionPropertyBuilder.CanSetKeyValueComparer(ValueComparer comparer, b /// 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. /// - IConventionPropertyBuilder IConventionPropertyBuilder.HasStructuralValueComparer(ValueComparer comparer, bool fromDataAnnotation) + IConventionPropertyBuilder? IConventionPropertyBuilder.HasStructuralValueComparer(ValueComparer? comparer, bool fromDataAnnotation) => HasKeyValueComparer( comparer, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); @@ -1072,7 +1075,7 @@ IConventionPropertyBuilder IConventionPropertyBuilder.HasStructuralValueComparer /// 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. /// - bool IConventionPropertyBuilder.CanSetStructuralValueComparer(ValueComparer comparer, bool fromDataAnnotation) + bool IConventionPropertyBuilder.CanSetStructuralValueComparer(ValueComparer? comparer, bool fromDataAnnotation) => CanSetKeyValueComparer( comparer, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); } diff --git a/src/EFCore/Metadata/Internal/InternalServicePropertyBuilder.cs b/src/EFCore/Metadata/Internal/InternalServicePropertyBuilder.cs index ca43b01dda2..ff45f0c831f 100644 --- a/src/EFCore/Metadata/Internal/InternalServicePropertyBuilder.cs +++ b/src/EFCore/Metadata/Internal/InternalServicePropertyBuilder.cs @@ -5,6 +5,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Metadata.Builders; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Internal { /// @@ -32,8 +34,8 @@ public InternalServicePropertyBuilder([NotNull] ServiceProperty property, [NotNu /// 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. /// - public new virtual InternalServicePropertyBuilder HasField([CanBeNull] string fieldName, ConfigurationSource configurationSource) - => (InternalServicePropertyBuilder)base.HasField(fieldName, configurationSource); + public new virtual InternalServicePropertyBuilder? HasField([CanBeNull] string? fieldName, ConfigurationSource configurationSource) + => (InternalServicePropertyBuilder?)base.HasField(fieldName, configurationSource); /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -41,8 +43,10 @@ public InternalServicePropertyBuilder([NotNull] ServiceProperty property, [NotNu /// 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. /// - public new virtual InternalServicePropertyBuilder HasField([CanBeNull] FieldInfo fieldInfo, ConfigurationSource configurationSource) - => (InternalServicePropertyBuilder)base.HasField(fieldInfo, configurationSource); + public new virtual InternalServicePropertyBuilder? HasField( + [CanBeNull] FieldInfo? fieldInfo, + ConfigurationSource configurationSource) + => (InternalServicePropertyBuilder?)base.HasField(fieldInfo, configurationSource); /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -50,10 +54,10 @@ public InternalServicePropertyBuilder([NotNull] ServiceProperty property, [NotNu /// 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. /// - public new virtual InternalServicePropertyBuilder UsePropertyAccessMode( + public new virtual InternalServicePropertyBuilder? UsePropertyAccessMode( PropertyAccessMode? propertyAccessMode, ConfigurationSource configurationSource) - => (InternalServicePropertyBuilder)base.UsePropertyAccessMode(propertyAccessMode, configurationSource); + => (InternalServicePropertyBuilder?)base.UsePropertyAccessMode(propertyAccessMode, configurationSource); /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -61,8 +65,8 @@ public InternalServicePropertyBuilder([NotNull] ServiceProperty property, [NotNu /// 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. /// - public virtual InternalServicePropertyBuilder HasParameterBinding( - [CanBeNull] ServiceParameterBinding parameterBinding, + public virtual InternalServicePropertyBuilder? HasParameterBinding( + [CanBeNull] ServiceParameterBinding? parameterBinding, ConfigurationSource configurationSource) { if (CanSetParameterBinding(parameterBinding, configurationSource)) @@ -81,7 +85,7 @@ public virtual InternalServicePropertyBuilder HasParameterBinding( /// doing so can result in application failures when updating to a new Entity Framework Core release. /// public virtual bool CanSetParameterBinding( - [CanBeNull] ServiceParameterBinding parameterBinding, + [CanBeNull] ServiceParameterBinding? parameterBinding, ConfigurationSource? configurationSource) => configurationSource.Overrides(Metadata.GetParameterBindingConfigurationSource()) || (Metadata.ParameterBinding == parameterBinding); @@ -92,10 +96,10 @@ public virtual bool CanSetParameterBinding( /// 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. /// - public virtual InternalServicePropertyBuilder Attach([NotNull] InternalEntityTypeBuilder entityTypeBuilder = null) + public virtual InternalServicePropertyBuilder? Attach([NotNull] InternalEntityTypeBuilder entityTypeBuilder) { var newPropertyBuilder = entityTypeBuilder.ServiceProperty( - Metadata.GetIdentifyingMemberInfo(), Metadata.GetConfigurationSource()); + Metadata.GetIdentifyingMemberInfo()!, Metadata.GetConfigurationSource()); if (newPropertyBuilder == null) { return null; @@ -143,7 +147,7 @@ IConventionServiceProperty IConventionServicePropertyBuilder.Metadata /// 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. /// - IConventionPropertyBaseBuilder IConventionPropertyBaseBuilder.HasField(string fieldName, bool fromDataAnnotation) + IConventionPropertyBaseBuilder? IConventionPropertyBaseBuilder.HasField(string? fieldName, bool fromDataAnnotation) => HasField(fieldName, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// @@ -152,7 +156,7 @@ IConventionPropertyBaseBuilder IConventionPropertyBaseBuilder.HasField(string fi /// 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. /// - IConventionPropertyBaseBuilder IConventionPropertyBaseBuilder.HasField(FieldInfo fieldInfo, bool fromDataAnnotation) + IConventionPropertyBaseBuilder? IConventionPropertyBaseBuilder.HasField(FieldInfo? fieldInfo, bool fromDataAnnotation) => HasField(fieldInfo, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// @@ -161,7 +165,7 @@ IConventionPropertyBaseBuilder IConventionPropertyBaseBuilder.HasField(FieldInfo /// 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. /// - IConventionServicePropertyBuilder IConventionServicePropertyBuilder.HasField(string fieldName, bool fromDataAnnotation) + IConventionServicePropertyBuilder? IConventionServicePropertyBuilder.HasField(string? fieldName, bool fromDataAnnotation) => HasField(fieldName, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// @@ -170,7 +174,7 @@ IConventionServicePropertyBuilder IConventionServicePropertyBuilder.HasField(str /// 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. /// - IConventionServicePropertyBuilder IConventionServicePropertyBuilder.HasField(FieldInfo fieldInfo, bool fromDataAnnotation) + IConventionServicePropertyBuilder? IConventionServicePropertyBuilder.HasField(FieldInfo? fieldInfo, bool fromDataAnnotation) => HasField(fieldInfo, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// @@ -179,7 +183,7 @@ IConventionServicePropertyBuilder IConventionServicePropertyBuilder.HasField(Fie /// 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. /// - bool IConventionPropertyBaseBuilder.CanSetField(string fieldName, bool fromDataAnnotation) + bool IConventionPropertyBaseBuilder.CanSetField(string? fieldName, bool fromDataAnnotation) => CanSetField(fieldName, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// @@ -188,7 +192,7 @@ bool IConventionPropertyBaseBuilder.CanSetField(string fieldName, bool fromDataA /// 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. /// - bool IConventionPropertyBaseBuilder.CanSetField(FieldInfo fieldInfo, bool fromDataAnnotation) + bool IConventionPropertyBaseBuilder.CanSetField(FieldInfo? fieldInfo, bool fromDataAnnotation) => CanSetField(fieldInfo, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// @@ -197,7 +201,7 @@ bool IConventionPropertyBaseBuilder.CanSetField(FieldInfo fieldInfo, bool fromDa /// 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. /// - IConventionPropertyBaseBuilder IConventionPropertyBaseBuilder.UsePropertyAccessMode( + IConventionPropertyBaseBuilder? IConventionPropertyBaseBuilder.UsePropertyAccessMode( PropertyAccessMode? propertyAccessMode, bool fromDataAnnotation) => UsePropertyAccessMode( @@ -209,7 +213,7 @@ IConventionPropertyBaseBuilder IConventionPropertyBaseBuilder.UsePropertyAccessM /// 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. /// - IConventionServicePropertyBuilder IConventionServicePropertyBuilder.UsePropertyAccessMode( + IConventionServicePropertyBuilder? IConventionServicePropertyBuilder.UsePropertyAccessMode( PropertyAccessMode? propertyAccessMode, bool fromDataAnnotation) => UsePropertyAccessMode( @@ -231,8 +235,8 @@ bool IConventionPropertyBaseBuilder.CanSetPropertyAccessMode(PropertyAccessMode? /// 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. /// - IConventionServicePropertyBuilder IConventionServicePropertyBuilder.HasParameterBinding( - ServiceParameterBinding parameterBinding, + IConventionServicePropertyBuilder? IConventionServicePropertyBuilder.HasParameterBinding( + ServiceParameterBinding? parameterBinding, bool fromDataAnnotation) => HasParameterBinding( parameterBinding, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); @@ -243,7 +247,7 @@ IConventionServicePropertyBuilder IConventionServicePropertyBuilder.HasParameter /// 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. /// - bool IConventionServicePropertyBuilder.CanSetParameterBinding(ServiceParameterBinding parameterBinding, bool fromDataAnnotation) + bool IConventionServicePropertyBuilder.CanSetParameterBinding(ServiceParameterBinding? parameterBinding, bool fromDataAnnotation) => CanSetParameterBinding( parameterBinding, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); } diff --git a/src/EFCore/Metadata/Internal/InternalSkipNavigationBuilder.cs b/src/EFCore/Metadata/Internal/InternalSkipNavigationBuilder.cs index 8b7cf5458db..c4dc527d156 100644 --- a/src/EFCore/Metadata/Internal/InternalSkipNavigationBuilder.cs +++ b/src/EFCore/Metadata/Internal/InternalSkipNavigationBuilder.cs @@ -7,6 +7,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Metadata.Builders; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Internal { /// @@ -34,8 +36,8 @@ public InternalSkipNavigationBuilder([NotNull] SkipNavigation metadata, [NotNull /// 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. /// - public new virtual InternalSkipNavigationBuilder HasField([CanBeNull] string fieldName, ConfigurationSource configurationSource) - => (InternalSkipNavigationBuilder)base.HasField(fieldName, configurationSource); + public new virtual InternalSkipNavigationBuilder? HasField([CanBeNull] string? fieldName, ConfigurationSource configurationSource) + => (InternalSkipNavigationBuilder?)base.HasField(fieldName, configurationSource); /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -43,8 +45,8 @@ public InternalSkipNavigationBuilder([NotNull] SkipNavigation metadata, [NotNull /// 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. /// - public new virtual InternalSkipNavigationBuilder HasField([CanBeNull] FieldInfo fieldInfo, ConfigurationSource configurationSource) - => (InternalSkipNavigationBuilder)base.HasField(fieldInfo, configurationSource); + public new virtual InternalSkipNavigationBuilder? HasField([CanBeNull] FieldInfo? fieldInfo, ConfigurationSource configurationSource) + => (InternalSkipNavigationBuilder?)base.HasField(fieldInfo, configurationSource); /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -52,10 +54,10 @@ public InternalSkipNavigationBuilder([NotNull] SkipNavigation metadata, [NotNull /// 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. /// - public new virtual InternalSkipNavigationBuilder UsePropertyAccessMode( + public new virtual InternalSkipNavigationBuilder? UsePropertyAccessMode( PropertyAccessMode? propertyAccessMode, ConfigurationSource configurationSource) - => (InternalSkipNavigationBuilder)base.UsePropertyAccessMode(propertyAccessMode, configurationSource); + => (InternalSkipNavigationBuilder?)base.UsePropertyAccessMode(propertyAccessMode, configurationSource); /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -63,8 +65,8 @@ public InternalSkipNavigationBuilder([NotNull] SkipNavigation metadata, [NotNull /// 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. /// - public virtual InternalSkipNavigationBuilder HasForeignKey( - [CanBeNull] ForeignKey foreignKey, + public virtual InternalSkipNavigationBuilder? HasForeignKey( + [CanBeNull] ForeignKey? foreignKey, ConfigurationSource configurationSource) { if (!CanSetForeignKey(foreignKey, configurationSource)) @@ -88,7 +90,7 @@ public virtual InternalSkipNavigationBuilder HasForeignKey( Metadata.SetForeignKey(foreignKey, configurationSource); - if (oldForeignKey?.Builder != null + if (oldForeignKey?.IsInModel == true && oldForeignKey != foreignKey && oldForeignKey.ReferencingSkipNavigations?.Any() != true) { @@ -104,7 +106,7 @@ public virtual InternalSkipNavigationBuilder HasForeignKey( /// 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. /// - public virtual bool CanSetForeignKey([CanBeNull] ForeignKey foreignKey, ConfigurationSource? configurationSource) + public virtual bool CanSetForeignKey([CanBeNull] ForeignKey? foreignKey, ConfigurationSource? configurationSource) { if (!configurationSource.Overrides(Metadata.GetForeignKeyConfigurationSource())) { @@ -138,8 +140,8 @@ public virtual bool CanSetForeignKey([CanBeNull] ForeignKey foreignKey, Configur /// 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. /// - public virtual InternalSkipNavigationBuilder HasInverse( - [CanBeNull] SkipNavigation inverse, + public virtual InternalSkipNavigationBuilder? HasInverse( + [CanBeNull] SkipNavigation? inverse, ConfigurationSource configurationSource) { if (!CanSetInverse(inverse, configurationSource)) @@ -178,7 +180,7 @@ public virtual InternalSkipNavigationBuilder HasInverse( /// doing so can result in application failures when updating to a new Entity Framework Core release. /// public virtual bool CanSetInverse( - [CanBeNull] SkipNavigation inverse, + [CanBeNull] SkipNavigation? inverse, ConfigurationSource? configurationSource) { if (!configurationSource.Overrides(Metadata.GetInverseConfigurationSource()) @@ -206,23 +208,29 @@ public virtual bool CanSetInverse( /// 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. /// - public virtual InternalSkipNavigationBuilder Attach( - [CanBeNull] InternalEntityTypeBuilder entityTypeBuilder = null, - [CanBeNull] EntityType targetEntityType = null, - [CanBeNull] InternalSkipNavigationBuilder inverseBuilder = null) + public virtual InternalSkipNavigationBuilder? Attach( + [CanBeNull] InternalEntityTypeBuilder? entityTypeBuilder = null, + [CanBeNull] EntityType? targetEntityType = null, + [CanBeNull] InternalSkipNavigationBuilder? inverseBuilder = null) { - entityTypeBuilder ??= Metadata.DeclaringEntityType.Builder; - if (entityTypeBuilder == null) + if (entityTypeBuilder is null) { - entityTypeBuilder = Metadata.DeclaringEntityType.Model.FindEntityType(Metadata.DeclaringEntityType.Name)?.Builder; - if (entityTypeBuilder == null) + if (Metadata.DeclaringEntityType.IsInModel) + { + entityTypeBuilder = Metadata.DeclaringEntityType.Builder; + } + else if (Metadata.DeclaringEntityType.Model.FindEntityType(Metadata.DeclaringEntityType.Name) is EntityType entityType) + { + entityTypeBuilder = entityType.Builder; + } + else { return null; } } targetEntityType ??= Metadata.TargetEntityType; - if (targetEntityType.Builder == null) + if (!targetEntityType.IsInModel) { targetEntityType = Metadata.DeclaringEntityType.Model.FindEntityType(targetEntityType.Name); if (targetEntityType == null) @@ -247,8 +255,8 @@ public virtual InternalSkipNavigationBuilder Attach( var foreignKeyConfigurationSource = Metadata.GetForeignKeyConfigurationSource(); if (foreignKeyConfigurationSource.HasValue) { - var foreignKey = Metadata.ForeignKey; - if (foreignKey.Builder == null) + var foreignKey = Metadata.ForeignKey!; + if (!foreignKey.IsInModel) { foreignKey = InternalForeignKeyBuilder.FindCurrentForeignKeyBuilder( foreignKey.PrincipalEntityType, @@ -268,8 +276,8 @@ public virtual InternalSkipNavigationBuilder Attach( var inverseConfigurationSource = Metadata.GetInverseConfigurationSource(); if (inverseConfigurationSource.HasValue) { - var inverse = Metadata.Inverse; - if (inverse.Builder == null) + var inverse = Metadata.Inverse!; + if (!inverse.IsInModel) { inverse = inverse.DeclaringEntityType.FindSkipNavigation(inverse.Name); } @@ -323,7 +331,7 @@ public virtual bool CanSetAutoInclude(bool? autoInclude, ConfigurationSource con /// 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. /// - public virtual InternalSkipNavigationBuilder AutoInclude(bool? autoInclude, ConfigurationSource configurationSource) + public virtual InternalSkipNavigationBuilder? AutoInclude(bool? autoInclude, ConfigurationSource configurationSource) { if (CanSetAutoInclude(autoInclude, configurationSource)) { @@ -348,49 +356,49 @@ IConventionSkipNavigation IConventionSkipNavigationBuilder.Metadata /// [DebuggerStepThrough] - IConventionPropertyBaseBuilder IConventionPropertyBaseBuilder.HasField(string fieldName, bool fromDataAnnotation) + IConventionPropertyBaseBuilder? IConventionPropertyBaseBuilder.HasField(string? fieldName, bool fromDataAnnotation) => HasField( fieldName, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// [DebuggerStepThrough] - IConventionPropertyBaseBuilder IConventionPropertyBaseBuilder.HasField(FieldInfo fieldInfo, bool fromDataAnnotation) + IConventionPropertyBaseBuilder? IConventionPropertyBaseBuilder.HasField(FieldInfo? fieldInfo, bool fromDataAnnotation) => HasField( fieldInfo, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// [DebuggerStepThrough] - IConventionSkipNavigationBuilder IConventionSkipNavigationBuilder.HasField(string fieldName, bool fromDataAnnotation) + IConventionSkipNavigationBuilder? IConventionSkipNavigationBuilder.HasField(string? fieldName, bool fromDataAnnotation) => HasField( fieldName, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// [DebuggerStepThrough] - IConventionSkipNavigationBuilder IConventionSkipNavigationBuilder.HasField(FieldInfo fieldInfo, bool fromDataAnnotation) + IConventionSkipNavigationBuilder? IConventionSkipNavigationBuilder.HasField(FieldInfo? fieldInfo, bool fromDataAnnotation) => HasField( fieldInfo, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// [DebuggerStepThrough] - bool IConventionPropertyBaseBuilder.CanSetField(string fieldName, bool fromDataAnnotation) + bool IConventionPropertyBaseBuilder.CanSetField(string? fieldName, bool fromDataAnnotation) => CanSetField( fieldName, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// [DebuggerStepThrough] - bool IConventionPropertyBaseBuilder.CanSetField(FieldInfo fieldInfo, bool fromDataAnnotation) + bool IConventionPropertyBaseBuilder.CanSetField(FieldInfo? fieldInfo, bool fromDataAnnotation) => CanSetField( fieldInfo, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// [DebuggerStepThrough] - IConventionPropertyBaseBuilder IConventionPropertyBaseBuilder.UsePropertyAccessMode( + IConventionPropertyBaseBuilder? IConventionPropertyBaseBuilder.UsePropertyAccessMode( PropertyAccessMode? propertyAccessMode, bool fromDataAnnotation) => UsePropertyAccessMode( @@ -399,7 +407,7 @@ IConventionPropertyBaseBuilder IConventionPropertyBaseBuilder.UsePropertyAccessM /// [DebuggerStepThrough] - IConventionSkipNavigationBuilder IConventionSkipNavigationBuilder.UsePropertyAccessMode( + IConventionSkipNavigationBuilder? IConventionSkipNavigationBuilder.UsePropertyAccessMode( PropertyAccessMode? propertyAccessMode, bool fromDataAnnotation) => UsePropertyAccessMode( @@ -417,38 +425,38 @@ bool IConventionPropertyBaseBuilder.CanSetPropertyAccessMode( /// [DebuggerStepThrough] - IConventionSkipNavigationBuilder IConventionSkipNavigationBuilder.HasForeignKey( - IConventionForeignKey foreignKey, + IConventionSkipNavigationBuilder? IConventionSkipNavigationBuilder.HasForeignKey( + IConventionForeignKey? foreignKey, bool fromDataAnnotation) => HasForeignKey( - (ForeignKey)foreignKey, + (ForeignKey?)foreignKey, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// [DebuggerStepThrough] bool IConventionSkipNavigationBuilder.CanSetForeignKey( - IConventionForeignKey foreignKey, + IConventionForeignKey? foreignKey, bool fromDataAnnotation) => CanSetForeignKey( - (ForeignKey)foreignKey, + (ForeignKey?)foreignKey, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// [DebuggerStepThrough] - IConventionSkipNavigationBuilder IConventionSkipNavigationBuilder.HasInverse( - IConventionSkipNavigation inverse, + IConventionSkipNavigationBuilder? IConventionSkipNavigationBuilder.HasInverse( + IConventionSkipNavigation? inverse, bool fromDataAnnotation) => HasInverse( - (SkipNavigation)inverse, + (SkipNavigation?)inverse, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// [DebuggerStepThrough] bool IConventionSkipNavigationBuilder.CanSetInverse( - IConventionSkipNavigation inverse, + IConventionSkipNavigation? inverse, bool fromDataAnnotation) => CanSetInverse( - (SkipNavigation)inverse, + (SkipNavigation?)inverse, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// @@ -458,7 +466,7 @@ bool IConventionSkipNavigationBuilder.CanSetAutoInclude(bool? autoInclude, bool /// [DebuggerStepThrough] - IConventionSkipNavigationBuilder IConventionSkipNavigationBuilder.AutoInclude(bool? autoInclude, bool fromDataAnnotation) + IConventionSkipNavigationBuilder? IConventionSkipNavigationBuilder.AutoInclude(bool? autoInclude, bool fromDataAnnotation) => AutoInclude(autoInclude, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); } } diff --git a/src/EFCore/Metadata/Internal/Key.cs b/src/EFCore/Metadata/Internal/Key.cs index 707c0024430..21e0828204b 100644 --- a/src/EFCore/Metadata/Internal/Key.cs +++ b/src/EFCore/Metadata/Internal/Key.cs @@ -8,6 +8,7 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.ChangeTracking; using Microsoft.EntityFrameworkCore.ChangeTracking.Internal; +using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Internal; using Microsoft.EntityFrameworkCore.Metadata.Builders; @@ -25,6 +26,7 @@ namespace Microsoft.EntityFrameworkCore.Metadata.Internal /// public class Key : ConventionAnnotatable, IMutableKey, IConventionKey { + private InternalKeyBuilder? _builder; private ConfigurationSource _configurationSource; // Warning: Never access these fields directly as access needs to be thread-safe @@ -46,7 +48,7 @@ public Key([NotNull] IReadOnlyList properties, ConfigurationSource con Properties = properties; _configurationSource = configurationSource; - Builder = new InternalKeyBuilder(this, DeclaringEntityType.Model.Builder); + _builder = new InternalKeyBuilder(this, DeclaringEntityType.Model.Builder); } /// @@ -74,12 +76,9 @@ public virtual EntityType DeclaringEntityType /// 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. /// - public virtual InternalKeyBuilder? Builder + public virtual InternalKeyBuilder Builder { - [DebuggerStepThrough] get; - [DebuggerStepThrough] - [param: CanBeNull] - set; + [DebuggerStepThrough] get => _builder ?? throw new InvalidOperationException(CoreStrings.ObjectRemovedFromModel); } /// @@ -88,7 +87,25 @@ public virtual InternalKeyBuilder? Builder /// 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. /// - protected override bool IsReadonly => DeclaringEntityType.Model.ConventionDispatcher == null; + public virtual bool IsInModel + => _builder is not null; + + /// + /// 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. + /// + public virtual void SetRemovedFromModel() + => _builder = null; + + /// + /// 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. + /// + protected override bool IsReadonly => DeclaringEntityType.Model.IsModelReadonly; /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -122,11 +139,11 @@ public virtual void UpdateConfigurationSource(ConfigurationSource configurationS /// The annotation set. /// The old annotation. /// The annotation that was set. - protected override IConventionAnnotation OnAnnotationSet( + protected override IConventionAnnotation? OnAnnotationSet( string name, IConventionAnnotation? annotation, IConventionAnnotation? oldAnnotation) - => Builder!.ModelBuilder.Metadata.ConventionDispatcher.OnKeyAnnotationChanged(Builder, name, annotation, oldAnnotation); + => Builder.ModelBuilder.Metadata.ConventionDispatcher.OnKeyAnnotationChanged(Builder, name, annotation, oldAnnotation); /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -235,7 +252,7 @@ IMutableEntityType IMutableKey.DeclaringEntityType /// 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. /// - IConventionKeyBuilder? IConventionKey.Builder + IConventionKeyBuilder IConventionKey.Builder { [DebuggerStepThrough] get => Builder; } @@ -246,7 +263,7 @@ IMutableEntityType IMutableKey.DeclaringEntityType /// 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. /// - IConventionAnnotatableBuilder? IConventionAnnotatable.Builder + IConventionAnnotatableBuilder IConventionAnnotatable.Builder { [DebuggerStepThrough] get => Builder; diff --git a/src/EFCore/Metadata/Internal/MemberClassifier.cs b/src/EFCore/Metadata/Internal/MemberClassifier.cs index 719dbca1513..a06bb85c409 100644 --- a/src/EFCore/Metadata/Internal/MemberClassifier.cs +++ b/src/EFCore/Metadata/Internal/MemberClassifier.cs @@ -8,6 +8,8 @@ using Microsoft.EntityFrameworkCore.Utilities; using Microsoft.Extensions.DependencyInjection; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Internal { /// @@ -51,7 +53,7 @@ public MemberClassifier( /// 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. /// - public virtual Type FindCandidateNavigationPropertyType(MemberInfo memberInfo) + public virtual Type? FindCandidateNavigationPropertyType(MemberInfo memberInfo) { Check.NotNull(memberInfo, nameof(memberInfo)); diff --git a/src/EFCore/Metadata/Internal/MetadataExtensions.cs b/src/EFCore/Metadata/Internal/MetadataExtensions.cs index ab52c902df6..48e9ecd9e5a 100644 --- a/src/EFCore/Metadata/Internal/MetadataExtensions.cs +++ b/src/EFCore/Metadata/Internal/MetadataExtensions.cs @@ -6,6 +6,8 @@ using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Infrastructure; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Internal { /// @@ -24,6 +26,7 @@ public static class MetadataExtensions /// public static TConcrete AsConcreteMetadataType([NotNull] TInterface @interface, [NotNull] string methodName) where TConcrete : class + where TInterface : notnull { if (!(@interface is TConcrete concrete)) { diff --git a/src/EFCore/Metadata/Internal/Model.cs b/src/EFCore/Metadata/Internal/Model.cs index 265188098f9..2947d235bf2 100644 --- a/src/EFCore/Metadata/Internal/Model.cs +++ b/src/EFCore/Metadata/Internal/Model.cs @@ -16,6 +16,7 @@ using Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal; using Microsoft.EntityFrameworkCore.Utilities; using Microsoft.Extensions.DependencyInjection; +using CA = System.Diagnostics.CodeAnalysis; #nullable enable @@ -42,21 +43,14 @@ public class Model : ConventionAnnotatable, IMutableModel, IConventionModel /// public static readonly Type DefaultPropertyBagType = typeof(Dictionary); - private readonly SortedDictionary _entityTypes - = new(StringComparer.Ordinal); - - private readonly ConcurrentDictionary _indexerPropertyInfoMap - = new(); - - private readonly ConcurrentDictionary _clrTypeNameMap - = new(); - - private readonly Dictionary _ignoredTypeNames - = new(StringComparer.Ordinal); - + private readonly SortedDictionary _entityTypes = new(StringComparer.Ordinal); + private readonly ConcurrentDictionary _indexerPropertyInfoMap = new(); + private readonly ConcurrentDictionary _clrTypeNameMap = new(); + private readonly Dictionary _ignoredTypeNames = new(StringComparer.Ordinal); private readonly Dictionary Types)> _sharedTypes = new() { { DefaultPropertyBagType, (ConfigurationSource.Convention, new SortedSet(EntityTypeFullNameComparer.Instance)) } }; + private ConventionDispatcher? _conventionDispatcher; private bool? _skipDetectChanges; private ChangeTrackingStrategy? _changeTrackingStrategy; @@ -84,7 +78,7 @@ public Model([NotNull] ConventionSet conventions, [CanBeNull] ModelDependencies? ModelDependencies = modelDependencies; var dispatcher = new ConventionDispatcher(conventions); var builder = new InternalModelBuilder(this); - ConventionDispatcher = dispatcher; + _conventionDispatcher = dispatcher; Builder = builder; dispatcher.OnModelInitialized(builder); } @@ -95,7 +89,10 @@ public Model([NotNull] ConventionSet conventions, [CanBeNull] ModelDependencies? /// 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. /// - public virtual ConventionDispatcher ConventionDispatcher { get; private set; } + public virtual ConventionDispatcher ConventionDispatcher + { + [DebuggerStepThrough] get => _conventionDispatcher ?? throw new InvalidOperationException(CoreStrings.ModelReadOnly); + } /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -108,7 +105,13 @@ public Model([NotNull] ConventionSet conventions, [CanBeNull] ModelDependencies? /// /// Indicates whether the model is read-only. /// - protected override bool IsReadonly => ConventionDispatcher == null; + protected override bool IsReadonly + => IsModelReadonly; + + /// + /// Indicates whether the model is read-only. + /// + public virtual bool IsModelReadonly => _conventionDispatcher == null; /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -315,7 +318,7 @@ private static void AssertCanRemove(EntityType entityType) /// public virtual EntityType? RemoveEntityType([CanBeNull] EntityType? entityType) { - if (entityType?.Builder == null) + if (entityType is null || !entityType.IsInModel) { return null; } @@ -418,7 +421,7 @@ public virtual string GetDisplayName([NotNull] Type type) /// doing so can result in application failures when updating to a new Entity Framework Core release. /// public virtual EntityType? FindActualEntityType([NotNull] EntityType entityType) - => entityType.Builder != null + => entityType.IsInModel ? entityType : FindEntityType(entityType.Name) ?? (entityType.HasSharedClrType @@ -847,7 +850,7 @@ public virtual ChangeTrackingStrategy GetChangeTrackingStrategy() /// The annotation set. /// The old annotation. /// The annotation that was set. - protected override IConventionAnnotation OnAnnotationSet( + protected override IConventionAnnotation? OnAnnotationSet( string name, IConventionAnnotation? annotation, IConventionAnnotation? oldAnnotation) @@ -871,7 +874,7 @@ public virtual IConventionBatch DelayConventions() /// 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. /// - public virtual T Track([NotNull] Func func, [CanBeNull] ref IConventionForeignKey foreignKey) + public virtual T Track([NotNull] Func func, [CanBeNull] [CA.DisallowNull] ref IConventionForeignKey? foreignKey) { EnsureReadonly(false); return ConventionDispatcher.Track(func, ref foreignKey); @@ -906,7 +909,7 @@ public virtual IModel FinalizeModel() private IModel MakeReadonly() { // ConventionDispatcher should never be accessed once the model is made read-only. - ConventionDispatcher = null!; + _conventionDispatcher = null; ModelDependencies = null; IsValidated = true; return this; diff --git a/src/EFCore/Metadata/Internal/Navigation.cs b/src/EFCore/Metadata/Internal/Navigation.cs index 94f64242fa8..8f34817887a 100644 --- a/src/EFCore/Metadata/Internal/Navigation.cs +++ b/src/EFCore/Metadata/Internal/Navigation.cs @@ -23,6 +23,8 @@ namespace Microsoft.EntityFrameworkCore.Metadata.Internal /// public class Navigation : PropertyBase, IMutableNavigation, IConventionNavigation { + private InternalNavigationBuilder? _builder; + // Warning: Never access these fields directly as access needs to be thread-safe private IClrCollectionAccessor? _collectionAccessor; private bool _collectionAccessorInitialized; @@ -44,7 +46,7 @@ public Navigation( ForeignKey = foreignKey; - Builder = new InternalNavigationBuilder(this, foreignKey.DeclaringEntityType.Model.Builder); + _builder = new InternalNavigationBuilder(this, foreignKey.DeclaringEntityType.Model.Builder); } /// @@ -70,7 +72,28 @@ public override Type ClrType /// 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. /// - public virtual InternalNavigationBuilder? Builder { get; [param: CanBeNull] set; } + public virtual InternalNavigationBuilder Builder + { + [DebuggerStepThrough] get => _builder ?? throw new InvalidOperationException(CoreStrings.ObjectRemovedFromModel); + } + + /// + /// 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. + /// + public virtual bool IsInModel + => _builder is not null; + + /// + /// 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. + /// + public virtual void SetRemovedFromModel() + => _builder = null; /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -286,7 +309,7 @@ public virtual IClrCollectionAccessor? CollectionAccessor /// The annotation set. /// The old annotation. /// The annotation that was set. - protected override IConventionAnnotation OnAnnotationSet( + protected override IConventionAnnotation? OnAnnotationSet( string name, IConventionAnnotation? annotation, IConventionAnnotation? oldAnnotation) @@ -340,7 +363,7 @@ IForeignKey INavigation.ForeignKey IConventionNavigation? IConventionNavigation.SetInverse(MemberInfo? inverse, bool fromDataAnnotation) => SetInverse(inverse, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); - IConventionNavigationBuilder? IConventionNavigation.Builder + IConventionNavigationBuilder IConventionNavigation.Builder { [DebuggerStepThrough] get => Builder; } @@ -351,7 +374,7 @@ IForeignKey INavigation.ForeignKey /// 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. /// - IConventionAnnotatableBuilder? IConventionAnnotatable.Builder + IConventionAnnotatableBuilder IConventionAnnotatable.Builder { [DebuggerStepThrough] get => Builder; } diff --git a/src/EFCore/Metadata/Internal/NullableEnumClrPropertySetter.cs b/src/EFCore/Metadata/Internal/NullableEnumClrPropertySetter.cs index 80834b0c403..1c538b5997c 100644 --- a/src/EFCore/Metadata/Internal/NullableEnumClrPropertySetter.cs +++ b/src/EFCore/Metadata/Internal/NullableEnumClrPropertySetter.cs @@ -4,6 +4,8 @@ using System; using JetBrains.Annotations; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Internal { /// @@ -34,14 +36,14 @@ public NullableEnumClrPropertySetter([NotNull] Action setter) /// 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. /// - public virtual void SetClrValue(object instance, object value) + public virtual void SetClrValue(object instance, object? value) { if (value != null) { value = (TNonNullableEnumValue)value; } - _setter((TEntity)instance, (TValue)value); + _setter((TEntity)instance, (TValue)value!); } } } diff --git a/src/EFCore/Metadata/Internal/ParameterBindingFactories.cs b/src/EFCore/Metadata/Internal/ParameterBindingFactories.cs index 3794568f7aa..c866cd13d57 100644 --- a/src/EFCore/Metadata/Internal/ParameterBindingFactories.cs +++ b/src/EFCore/Metadata/Internal/ParameterBindingFactories.cs @@ -8,6 +8,8 @@ using Microsoft.EntityFrameworkCore.Internal; using Microsoft.Extensions.DependencyInjection; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Internal { /// @@ -35,7 +37,7 @@ public class ParameterBindingFactories : IParameterBindingFactories /// doing so can result in application failures when updating to a new Entity Framework Core release. /// public ParameterBindingFactories( - [CanBeNull] IEnumerable registeredFactories, + [CanBeNull] IEnumerable? registeredFactories, [NotNull] IRegisteredServices registeredServices) { _registeredServices = registeredServices; @@ -50,7 +52,7 @@ public ParameterBindingFactories( /// 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. /// - public virtual IParameterBindingFactory FindFactory(Type parameterType, string parameterName) + public virtual IParameterBindingFactory? FindFactory(Type parameterType, string parameterName) => _parameterBindingFactories.FirstOrDefault(f => f.CanBind(parameterType, parameterName)) ?? (_registeredServices.Services.Contains(parameterType) ? new ServiceParameterBindingFactory(parameterType) diff --git a/src/EFCore/Metadata/Internal/PropertiesSnapshot.cs b/src/EFCore/Metadata/Internal/PropertiesSnapshot.cs index c695301fa15..185aa511649 100644 --- a/src/EFCore/Metadata/Internal/PropertiesSnapshot.cs +++ b/src/EFCore/Metadata/Internal/PropertiesSnapshot.cs @@ -5,6 +5,8 @@ using System.Diagnostics; using JetBrains.Annotations; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Internal { /// @@ -22,10 +24,10 @@ public class PropertiesSnapshot /// doing so can result in application failures when updating to a new Entity Framework Core release. /// public PropertiesSnapshot( - [CanBeNull] List properties, - [CanBeNull] List indexes, - [CanBeNull] List<(InternalKeyBuilder, ConfigurationSource?)> keys, - [CanBeNull] List relationships) + [CanBeNull] List? properties, + [CanBeNull] List? indexes, + [CanBeNull] List<(InternalKeyBuilder, ConfigurationSource?)>? keys, + [CanBeNull] List? relationships) { Properties = properties; Indexes = indexes; @@ -33,10 +35,10 @@ public PropertiesSnapshot( Relationships = relationships; } - private List Properties { [DebuggerStepThrough] get; } - private List Relationships { [DebuggerStepThrough] get; set; } - private List Indexes { [DebuggerStepThrough] get; set; } - private List<(InternalKeyBuilder, ConfigurationSource?)> Keys { [DebuggerStepThrough] get; set; } + private List? Properties { [DebuggerStepThrough] get; } + private List? Relationships { [DebuggerStepThrough] get; set; } + private List? Indexes { [DebuggerStepThrough] get; set; } + private List<(InternalKeyBuilder, ConfigurationSource?)>? Keys { [DebuggerStepThrough] get; set; } /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to diff --git a/src/EFCore/Metadata/Internal/Property.cs b/src/EFCore/Metadata/Internal/Property.cs index 65543f5c699..50389e2e519 100644 --- a/src/EFCore/Metadata/Internal/Property.cs +++ b/src/EFCore/Metadata/Internal/Property.cs @@ -33,6 +33,7 @@ public class Property : PropertyBase, IMutableProperty, IConventionProperty private bool? _isNullable; private ValueGenerated? _valueGenerated; private CoreTypeMapping? _typeMapping; + private InternalPropertyBuilder? _builder; private ConfigurationSource? _typeConfigurationSource; private ConfigurationSource? _isNullableConfigurationSource; @@ -63,7 +64,7 @@ public Property( ClrType = clrType; _typeConfigurationSource = typeConfigurationSource; - Builder = new InternalPropertyBuilder(this, declaringEntityType.Model.Builder); + _builder = new InternalPropertyBuilder(this, declaringEntityType.Model.Builder); } /// @@ -100,7 +101,28 @@ public override TypeBase DeclaringType /// 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. /// - public virtual InternalPropertyBuilder? Builder { get; [param: CanBeNull] set; } + public virtual InternalPropertyBuilder Builder + { + [DebuggerStepThrough] get => _builder ?? throw new InvalidOperationException(CoreStrings.ObjectRemovedFromModel); + } + + /// + /// 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. + /// + public virtual bool IsInModel + => _builder is not null; + + /// + /// 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. + /// + public virtual void SetRemovedFromModel() + => _builder = null; /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -495,7 +517,8 @@ public virtual CoreTypeMapping? TypeMapping /// 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. /// - public virtual CoreTypeMapping SetTypeMapping([NotNull] CoreTypeMapping typeMapping, ConfigurationSource configurationSource) + // [return: CA.NotNullIfNotNull("typeMapping")] + public virtual CoreTypeMapping? SetTypeMapping([CanBeNull] CoreTypeMapping? typeMapping, ConfigurationSource configurationSource) { _typeMapping = typeMapping; _typeMappingConfigurationSource = configurationSource.Max(_typeMappingConfigurationSource); @@ -678,7 +701,7 @@ public virtual DebugView DebugView /// 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. /// - IConventionPropertyBuilder? IConventionProperty.Builder + IConventionPropertyBuilder IConventionProperty.Builder { [DebuggerStepThrough] get => Builder; } @@ -689,7 +712,7 @@ public virtual DebugView DebugView /// 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. /// - IConventionAnnotatableBuilder? IConventionAnnotatable.Builder + IConventionAnnotatableBuilder IConventionAnnotatable.Builder { [DebuggerStepThrough] get => Builder; diff --git a/src/EFCore/Metadata/Internal/PropertyAccessors.cs b/src/EFCore/Metadata/Internal/PropertyAccessors.cs index da6cd462be3..9338cb29690 100644 --- a/src/EFCore/Metadata/Internal/PropertyAccessors.cs +++ b/src/EFCore/Metadata/Internal/PropertyAccessors.cs @@ -5,6 +5,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Storage; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Internal { /// @@ -25,9 +27,9 @@ public sealed class PropertyAccessors public PropertyAccessors( [NotNull] Delegate currentValueGetter, [NotNull] Delegate preStoreGeneratedCurrentValueGetter, - [CanBeNull] Delegate originalValueGetter, + [CanBeNull] Delegate? originalValueGetter, [NotNull] Delegate relationshipSnapshotGetter, - [CanBeNull] Func valueBufferGetter) + [CanBeNull] Func? valueBufferGetter) { CurrentValueGetter = currentValueGetter; PreStoreGeneratedCurrentValueGetter = preStoreGeneratedCurrentValueGetter; @@ -58,7 +60,7 @@ public PropertyAccessors( /// 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. /// - public Delegate OriginalValueGetter { get; } + public Delegate? OriginalValueGetter { get; } /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -74,6 +76,6 @@ public PropertyAccessors( /// 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. /// - public Func ValueBufferGetter { get; } + public Func? ValueBufferGetter { get; } } } diff --git a/src/EFCore/Metadata/Internal/PropertyAccessorsFactory.cs b/src/EFCore/Metadata/Internal/PropertyAccessorsFactory.cs index bdb62973869..532416f6b4e 100644 --- a/src/EFCore/Metadata/Internal/PropertyAccessorsFactory.cs +++ b/src/EFCore/Metadata/Internal/PropertyAccessorsFactory.cs @@ -12,6 +12,8 @@ using Microsoft.EntityFrameworkCore.Storage; using Microsoft.EntityFrameworkCore.Update; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Internal { /// @@ -31,11 +33,10 @@ public class PropertyAccessorsFactory public virtual PropertyAccessors Create([NotNull] IPropertyBase propertyBase) => (PropertyAccessors)_genericCreate .MakeGenericMethod(propertyBase.ClrType) - .Invoke( - null, new object[] { propertyBase }); + .Invoke(null, new object[] { propertyBase })!; private static readonly MethodInfo _genericCreate - = typeof(PropertyAccessorsFactory).GetTypeInfo().GetDeclaredMethod(nameof(CreateGeneric)); + = typeof(PropertyAccessorsFactory).GetTypeInfo().GetDeclaredMethod(nameof(CreateGeneric))!; [UsedImplicitly] private static PropertyAccessors CreateGeneric(IPropertyBase propertyBase) diff --git a/src/EFCore/Metadata/Internal/PropertyBase.cs b/src/EFCore/Metadata/Internal/PropertyBase.cs index 412f7e31695..28fc000f473 100644 --- a/src/EFCore/Metadata/Internal/PropertyBase.cs +++ b/src/EFCore/Metadata/Internal/PropertyBase.cs @@ -70,7 +70,7 @@ protected PropertyBase( /// /// Indicates whether the model is read-only. /// - protected override bool IsReadonly => DeclaringType.Model.ConventionDispatcher == null; + protected override bool IsReadonly => DeclaringType.Model.IsModelReadonly; /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -410,7 +410,7 @@ public virtual IComparer CurrentValueComparer /// doing so can result in application failures when updating to a new Entity Framework Core release. /// public static Expression CreateMemberAccess( - [CanBeNull] IPropertyBase property, + [CanBeNull] IPropertyBase? property, [NotNull] Expression instanceExpression, [NotNull] MemberInfo memberInfo) { diff --git a/src/EFCore/Metadata/Internal/PropertyBaseExtensions.cs b/src/EFCore/Metadata/Internal/PropertyBaseExtensions.cs index 3d6ccc0aef6..7e4867a04a1 100644 --- a/src/EFCore/Metadata/Internal/PropertyBaseExtensions.cs +++ b/src/EFCore/Metadata/Internal/PropertyBaseExtensions.cs @@ -8,6 +8,8 @@ using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Infrastructure; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Internal { /// @@ -80,9 +82,9 @@ public static PropertyAccessors GetPropertyAccessors([NotNull] this IPropertyBas /// // Note: only use this to find the property/field that defines the property in the model. Use // GetMemberInfo to get the property/field to use, which may be different. - public static MemberInfo GetIdentifyingMemberInfo( + public static MemberInfo? GetIdentifyingMemberInfo( [NotNull] this IPropertyBase propertyBase) - => propertyBase.PropertyInfo ?? (MemberInfo)propertyBase.FieldInfo; + => propertyBase.PropertyInfo ?? (MemberInfo?)propertyBase.FieldInfo; /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -94,8 +96,8 @@ public static bool TryGetMemberInfo( [NotNull] this IPropertyBase propertyBase, bool forConstruction, bool forSet, - out MemberInfo memberInfo, - out string errorMessage) + out MemberInfo? memberInfo, + out string? errorMessage) { memberInfo = null; errorMessage = null; @@ -338,7 +340,7 @@ public static bool TryGetMemberInfo( private static string GetNoFieldErrorMessage(IPropertyBase propertyBase) { - var constructorBinding = (InstantiationBinding)propertyBase.DeclaringType[CoreAnnotationNames.ConstructorBinding]; + var constructorBinding = (InstantiationBinding?)propertyBase.DeclaringType[CoreAnnotationNames.ConstructorBinding]; return constructorBinding?.ParameterBindings .OfType() diff --git a/src/EFCore/Metadata/Internal/PropertyCounts.cs b/src/EFCore/Metadata/Internal/PropertyCounts.cs index 5f165f48467..8a81b94f33f 100644 --- a/src/EFCore/Metadata/Internal/PropertyCounts.cs +++ b/src/EFCore/Metadata/Internal/PropertyCounts.cs @@ -1,6 +1,8 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Internal { /// diff --git a/src/EFCore/Metadata/Internal/PropertyIndexes.cs b/src/EFCore/Metadata/Internal/PropertyIndexes.cs index fcbe7fdc8ea..baac383864c 100644 --- a/src/EFCore/Metadata/Internal/PropertyIndexes.cs +++ b/src/EFCore/Metadata/Internal/PropertyIndexes.cs @@ -1,6 +1,8 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Internal { /// diff --git a/src/EFCore/Metadata/Internal/PropertyParameterBindingFactory.cs b/src/EFCore/Metadata/Internal/PropertyParameterBindingFactory.cs index 486bb0745bb..1e1768d001f 100644 --- a/src/EFCore/Metadata/Internal/PropertyParameterBindingFactory.cs +++ b/src/EFCore/Metadata/Internal/PropertyParameterBindingFactory.cs @@ -6,6 +6,8 @@ using System.Linq; using Microsoft.Extensions.DependencyInjection; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Internal { /// @@ -29,7 +31,7 @@ public class PropertyParameterBindingFactory : IPropertyParameterBindingFactory /// 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. /// - public virtual ParameterBinding FindParameter( + public virtual ParameterBinding? FindParameter( IEntityType entityType, Type parameterType, string parameterName) diff --git a/src/EFCore/Metadata/Internal/RelationshipSnapshot.cs b/src/EFCore/Metadata/Internal/RelationshipSnapshot.cs index e2941744e14..8a07ee88637 100644 --- a/src/EFCore/Metadata/Internal/RelationshipSnapshot.cs +++ b/src/EFCore/Metadata/Internal/RelationshipSnapshot.cs @@ -5,6 +5,8 @@ using System.Diagnostics; using JetBrains.Annotations; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Internal { /// @@ -23,8 +25,8 @@ public class RelationshipSnapshot /// public RelationshipSnapshot( [NotNull] InternalForeignKeyBuilder relationship, - [CanBeNull] EntityType.Snapshot ownedEntityTypeSnapshot, - [CanBeNull] List<(SkipNavigation, ConfigurationSource)> referencingSkipNavigations) + [CanBeNull] EntityType.Snapshot? ownedEntityTypeSnapshot, + [CanBeNull] List<(SkipNavigation, ConfigurationSource)>? referencingSkipNavigations) { Relationship = relationship; OwnedEntityTypeSnapshot = ownedEntityTypeSnapshot; @@ -45,7 +47,7 @@ public RelationshipSnapshot( /// 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. /// - public virtual EntityType.Snapshot OwnedEntityTypeSnapshot { [DebuggerStepThrough] get; } + public virtual EntityType.Snapshot? OwnedEntityTypeSnapshot { [DebuggerStepThrough] get; } /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -53,7 +55,7 @@ public RelationshipSnapshot( /// 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. /// - public virtual List<(SkipNavigation SkipNavigation, ConfigurationSource ForeignKeyConfigurationSource)> ReferencingSkipNavigations + public virtual List<(SkipNavigation SkipNavigation, ConfigurationSource ForeignKeyConfigurationSource)>? ReferencingSkipNavigations { [DebuggerStepThrough] get; } @@ -64,7 +66,7 @@ public RelationshipSnapshot( /// 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. /// - public virtual InternalForeignKeyBuilder Attach([CanBeNull] InternalEntityTypeBuilder entityTypeBuilder = null) + public virtual InternalForeignKeyBuilder? Attach([CanBeNull] InternalEntityTypeBuilder? entityTypeBuilder = null) { entityTypeBuilder ??= Relationship.Metadata.DeclaringEntityType.Builder; @@ -79,10 +81,10 @@ public virtual InternalForeignKeyBuilder Attach([CanBeNull] InternalEntityTypeBu foreach (var referencingNavigationTuple in ReferencingSkipNavigations) { var skipNavigation = referencingNavigationTuple.SkipNavigation; - if (skipNavigation.Builder == null) + if (!skipNavigation.IsInModel) { var navigationEntityType = skipNavigation.DeclaringEntityType; - skipNavigation = navigationEntityType.Builder == null + skipNavigation = !navigationEntityType.IsInModel ? null : navigationEntityType.FindSkipNavigation(skipNavigation.Name); } diff --git a/src/EFCore/Metadata/Internal/ServiceProperty.cs b/src/EFCore/Metadata/Internal/ServiceProperty.cs index d6ff8574c78..7bee0784588 100644 --- a/src/EFCore/Metadata/Internal/ServiceProperty.cs +++ b/src/EFCore/Metadata/Internal/ServiceProperty.cs @@ -5,6 +5,7 @@ using System.Diagnostics; using System.Reflection; using JetBrains.Annotations; +using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Utilities; @@ -22,6 +23,7 @@ namespace Microsoft.EntityFrameworkCore.Metadata.Internal public class ServiceProperty : PropertyBase, IMutableServiceProperty, IConventionServiceProperty { private ServiceParameterBinding? _parameterBinding; + private InternalServicePropertyBuilder? _builder; private ConfigurationSource? _parameterBindingConfigurationSource; @@ -44,7 +46,7 @@ public ServiceProperty( DeclaringEntityType = declaringEntityType; ClrType = (propertyInfo?.PropertyType ?? fieldInfo?.FieldType)!; - Builder = new InternalServicePropertyBuilder(this, declaringEntityType.Model.Builder); + _builder = new InternalServicePropertyBuilder(this, declaringEntityType.Model.Builder); } /// @@ -80,12 +82,30 @@ public override TypeBase DeclaringType /// 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. /// - public virtual InternalServicePropertyBuilder? Builder + public virtual InternalServicePropertyBuilder Builder { - get; - [param: CanBeNull] set; + [DebuggerStepThrough] + get => _builder ?? throw new InvalidOperationException(CoreStrings.ObjectRemovedFromModel); } + /// + /// 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. + /// + public virtual bool IsInModel + => _builder is not null; + + /// + /// 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. + /// + public virtual void SetRemovedFromModel() + => _builder = null; + /// /// 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 @@ -169,7 +189,7 @@ IMutableEntityType IMutableServiceProperty.DeclaringEntityType /// 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. /// - IConventionServicePropertyBuilder? IConventionServiceProperty.Builder + IConventionServicePropertyBuilder IConventionServiceProperty.Builder { [DebuggerStepThrough] get => Builder; } @@ -180,7 +200,7 @@ IMutableEntityType IMutableServiceProperty.DeclaringEntityType /// 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. /// - IConventionAnnotatableBuilder? IConventionAnnotatable.Builder + IConventionAnnotatableBuilder IConventionAnnotatable.Builder { [DebuggerStepThrough] get => Builder; } diff --git a/src/EFCore/Metadata/Internal/SkipNavigation.cs b/src/EFCore/Metadata/Internal/SkipNavigation.cs index 45e89f79372..8cc6ba3e36a 100644 --- a/src/EFCore/Metadata/Internal/SkipNavigation.cs +++ b/src/EFCore/Metadata/Internal/SkipNavigation.cs @@ -26,6 +26,7 @@ public class SkipNavigation : PropertyBase, IMutableSkipNavigation, IConventionS { private ConfigurationSource? _foreignKeyConfigurationSource; private ConfigurationSource? _inverseConfigurationSource; + private InternalSkipNavigationBuilder? _builder; // Warning: Never access these fields directly as access needs to be thread-safe private IClrCollectionAccessor? _collectionAccessor; @@ -56,7 +57,7 @@ public SkipNavigation( TargetEntityType = targetEntityType; IsCollection = collection; IsOnDependent = onDependent; - Builder = new InternalSkipNavigationBuilder(this, targetEntityType.Model.Builder); + _builder = new InternalSkipNavigationBuilder(this, targetEntityType.Model.Builder); } private void ProcessForeignKey(ForeignKey foreignKey) @@ -88,7 +89,29 @@ public override Type ClrType /// 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. /// - public virtual InternalSkipNavigationBuilder? Builder { get; [param: CanBeNull] set; } + public virtual InternalSkipNavigationBuilder Builder + { + [DebuggerStepThrough] + get => _builder ?? throw new InvalidOperationException(CoreStrings.ObjectRemovedFromModel); + } + + /// + /// 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. + /// + public virtual bool IsInModel + => _builder is not null; + + /// + /// 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. + /// + public virtual void SetRemovedFromModel() + => _builder = null; /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -179,9 +202,10 @@ public virtual EntityType? JoinEntityType ForeignKey = null; _foreignKeyConfigurationSource = null; + // TODO-NULLABLE: should OnSkipNavigationForeignKeyChanged be changed to support nullable foreignKey/oldForeignKey? return isChanging ? (ForeignKey?)DeclaringEntityType.Model.ConventionDispatcher - .OnSkipNavigationForeignKeyChanged(Builder, foreignKey, oldForeignKey) + .OnSkipNavigationForeignKeyChanged(Builder, foreignKey!, oldForeignKey!) : foreignKey; } @@ -210,8 +234,8 @@ public virtual EntityType? JoinEntityType } return isChanging - ? (ForeignKey)DeclaringEntityType.Model.ConventionDispatcher - .OnSkipNavigationForeignKeyChanged(Builder, foreignKey, oldForeignKey) + ? (ForeignKey?)DeclaringEntityType.Model.ConventionDispatcher + .OnSkipNavigationForeignKeyChanged(Builder, foreignKey, oldForeignKey!) : foreignKey; } @@ -250,9 +274,10 @@ public virtual void UpdateForeignKeyConfigurationSource(ConfigurationSource conf Inverse = null; _inverseConfigurationSource = null; + // TODO-NULLABLE: should OnSkipNavigationInverseChanged be changed to support nullable inverse/oldInverse? return isChanging - ? (SkipNavigation)DeclaringEntityType.Model.ConventionDispatcher - .OnSkipNavigationInverseChanged(Builder, inverse, oldInverse) + ? (SkipNavigation?)DeclaringEntityType.Model.ConventionDispatcher + .OnSkipNavigationInverseChanged(Builder, inverse!, oldInverse!) : inverse; } @@ -276,8 +301,8 @@ public virtual void UpdateForeignKeyConfigurationSource(ConfigurationSource conf UpdateInverseConfigurationSource(configurationSource); return isChanging - ? (SkipNavigation)DeclaringEntityType.Model.ConventionDispatcher - .OnSkipNavigationInverseChanged(Builder, inverse, oldInverse) + ? (SkipNavigation?)DeclaringEntityType.Model.ConventionDispatcher + .OnSkipNavigationInverseChanged(Builder, inverse, oldInverse!) : inverse; } @@ -315,7 +340,7 @@ public virtual void SetIsEagerLoaded(bool? eagerLoaded, ConfigurationSource conf /// The annotation set. /// The old annotation. /// The annotation that was set. - protected override IConventionAnnotation OnAnnotationSet( + protected override IConventionAnnotation? OnAnnotationSet( string name, IConventionAnnotation? annotation, IConventionAnnotation? oldAnnotation) @@ -367,14 +392,14 @@ public override string ToString() => this.ToDebugString(MetadataDebugStringOptions.SingleLineDefault); /// - IConventionSkipNavigationBuilder? IConventionSkipNavigation.Builder + IConventionSkipNavigationBuilder IConventionSkipNavigation.Builder { [DebuggerStepThrough] get => Builder; } /// - IConventionAnnotatableBuilder? IConventionAnnotatable.Builder + IConventionAnnotatableBuilder IConventionAnnotatable.Builder { [DebuggerStepThrough] get => Builder; diff --git a/src/EFCore/Metadata/Internal/TypeBase.cs b/src/EFCore/Metadata/Internal/TypeBase.cs index d5cae07d0fd..eacd464d169 100644 --- a/src/EFCore/Metadata/Internal/TypeBase.cs +++ b/src/EFCore/Metadata/Internal/TypeBase.cs @@ -95,7 +95,7 @@ protected TypeBase([NotNull] string name, [NotNull] Type type, [NotNull] Model m /// 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. /// - protected override bool IsReadonly => Model.ConventionDispatcher == null; + protected override bool IsReadonly => Model.IsModelReadonly; /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -275,7 +275,7 @@ public virtual void UpdateConfigurationSource(ConfigurationSource configurationS /// 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. /// - public virtual string AddIgnored([NotNull] string name, ConfigurationSource configurationSource) + public virtual string? AddIgnored([NotNull] string name, ConfigurationSource configurationSource) { Check.NotNull(name, nameof(name)); EnsureReadonly(false); @@ -297,7 +297,7 @@ public virtual string AddIgnored([NotNull] string name, ConfigurationSource conf /// 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. /// - public abstract string OnTypeMemberIgnored([NotNull] string name); + public abstract string? OnTypeMemberIgnored([NotNull] string name); /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -401,7 +401,7 @@ Type ITypeBase.ClrType /// 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. /// - string IMutableTypeBase.AddIgnored(string name) + string? IMutableTypeBase.AddIgnored(string name) => AddIgnored(name, ConfigurationSource.Explicit); /// @@ -410,7 +410,7 @@ string IMutableTypeBase.AddIgnored(string name) /// 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. /// - string IConventionTypeBase.AddIgnored(string name, bool fromDataAnnotation) + string? IConventionTypeBase.AddIgnored(string name, bool fromDataAnnotation) => AddIgnored(name, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); } } diff --git a/src/EFCore/Metadata/Internal/TypeBaseExtensions.cs b/src/EFCore/Metadata/Internal/TypeBaseExtensions.cs index 5b723b3194c..aa1d5e42eed 100644 --- a/src/EFCore/Metadata/Internal/TypeBaseExtensions.cs +++ b/src/EFCore/Metadata/Internal/TypeBaseExtensions.cs @@ -2,11 +2,12 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections.Generic; -using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using JetBrains.Annotations; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Internal { /// @@ -23,8 +24,8 @@ public static class TypeBaseExtensions /// 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. /// - public static IReadOnlyDictionary GetRuntimeProperties([NotNull] this ITypeBase type) - => (type as TypeBase).GetRuntimeProperties(); + public static IReadOnlyDictionary? GetRuntimeProperties([NotNull] this ITypeBase type) + => ((TypeBase)type).GetRuntimeProperties(); /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -32,8 +33,8 @@ public static IReadOnlyDictionary GetRuntimeProperties([No /// 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. /// - public static IReadOnlyDictionary GetRuntimeFields([NotNull] this ITypeBase type) - => (type as TypeBase).GetRuntimeFields(); + public static IReadOnlyDictionary? GetRuntimeFields([NotNull] this ITypeBase type) + => ((TypeBase)type).GetRuntimeFields(); /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -41,8 +42,8 @@ public static IReadOnlyDictionary GetRuntimeFields([NotNull] /// 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. /// - public static PropertyInfo FindIndexerPropertyInfo([NotNull] this ITypeBase type) - => (type as TypeBase).FindIndexerPropertyInfo(); + public static PropertyInfo? FindIndexerPropertyInfo([NotNull] this ITypeBase type) + => ((TypeBase)type).FindIndexerPropertyInfo(); /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to diff --git a/src/EFCore/Metadata/Internal/TypeIdentity.cs b/src/EFCore/Metadata/Internal/TypeIdentity.cs index cd577444e55..dc0170ece65 100644 --- a/src/EFCore/Metadata/Internal/TypeIdentity.cs +++ b/src/EFCore/Metadata/Internal/TypeIdentity.cs @@ -6,6 +6,8 @@ using System.Diagnostics; using JetBrains.Annotations; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Internal { /// @@ -73,7 +75,7 @@ public TypeIdentity([NotNull] Type type, [NotNull] Model model) /// 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. /// - public Type Type { [DebuggerStepThrough] get; } + public Type? Type { [DebuggerStepThrough] get; } /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -87,7 +89,7 @@ private string DebuggerDisplay() => Name; /// - public override bool Equals(object obj) + public override bool Equals(object? obj) => obj is TypeIdentity identity && Equals(identity); /// diff --git a/src/EFCore/Properties/CoreStrings.Designer.cs b/src/EFCore/Properties/CoreStrings.Designer.cs index aae9b4dc7af..60fa776c5ed 100644 --- a/src/EFCore/Properties/CoreStrings.Designer.cs +++ b/src/EFCore/Properties/CoreStrings.Designer.cs @@ -1943,6 +1943,12 @@ public static string NullableKey([CanBeNull] object? entityType, [CanBeNull] obj GetString("NullableKey", nameof(entityType), nameof(property)), entityType, property); + /// + /// The object has been removed from the model. + /// + public static string ObjectRemovedFromModel + => GetString("ObjectRemovedFromModel"); + /// /// Options extension of type '{optionsExtension}' not found. /// diff --git a/src/EFCore/Properties/CoreStrings.resx b/src/EFCore/Properties/CoreStrings.resx index 1b7a36d4060..8a7fb7edba3 100644 --- a/src/EFCore/Properties/CoreStrings.resx +++ b/src/EFCore/Properties/CoreStrings.resx @@ -1158,6 +1158,9 @@ A key on entity type '{entityType}' cannot contain the property '{property}' because it is nullable/optional. All properties on which a key is declared must be marked as non-nullable/required. + + The object has been removed from the model. + Options extension of type '{optionsExtension}' not found. diff --git a/src/EFCore/Storage/CoreTypeMapping.cs b/src/EFCore/Storage/CoreTypeMapping.cs index 58b185660bd..7e287504050 100644 --- a/src/EFCore/Storage/CoreTypeMapping.cs +++ b/src/EFCore/Storage/CoreTypeMapping.cs @@ -221,7 +221,7 @@ public virtual ValueComparer StructuralComparer /// /// The converter to use. /// A new type mapping - public abstract CoreTypeMapping Clone([CanBeNull] ValueConverter converter); + public abstract CoreTypeMapping Clone([CanBeNull] ValueConverter? converter); /// /// Creates a an expression tree that can be used to generate code for the literal value. diff --git a/src/Shared/Check.cs b/src/Shared/Check.cs index 3403a81c904..ddcae01a3df 100644 --- a/src/Shared/Check.cs +++ b/src/Shared/Check.cs @@ -17,11 +17,10 @@ namespace Microsoft.EntityFrameworkCore.Utilities internal static class Check { [ContractAnnotation("value:null => halt")] + [return: CA.NotNull] public static T NotNull([NoEnumeration, CA.AllowNull, CA.NotNull] T value, [InvokerParameterName] [NotNull] string parameterName) { -#pragma warning disable IDE0041 // Use 'is null' check - if (ReferenceEquals(value, null)) -#pragma warning restore IDE0041 // Use 'is null' check + if (value is null) { NotEmpty(parameterName, nameof(parameterName)); @@ -67,8 +66,7 @@ public static string NotEmpty([CA.NotNull] string? value, [InvokerParameterName] public static string? NullButNotEmpty(string? value, [InvokerParameterName] [NotNull] string parameterName) { - if (!(value is null) - && value.Length == 0) + if (value is not null && value.Length == 0) { NotEmpty(parameterName, nameof(parameterName)); diff --git a/test/EFCore.Relational.Tests/Metadata/RelationalMetadataExtensionsTest.cs b/test/EFCore.Relational.Tests/Metadata/RelationalMetadataExtensionsTest.cs index 21a4d03e87b..1952eaa2c28 100644 --- a/test/EFCore.Relational.Tests/Metadata/RelationalMetadataExtensionsTest.cs +++ b/test/EFCore.Relational.Tests/Metadata/RelationalMetadataExtensionsTest.cs @@ -426,11 +426,11 @@ public void Can_get_and_set_dbfunction() Assert.NotNull(dbFunc); Assert.NotNull(dbFunc.Name); Assert.Null(dbFunc.Schema); - Assert.NotNull(((IConventionDbFunction)dbFunc).Builder); + Assert.True(((IConventionDbFunction)dbFunc).IsInModel); Assert.Same(dbFunc, model.RemoveDbFunction(testMethod)); - Assert.Null(((IConventionDbFunction)dbFunc).Builder); + Assert.False(((IConventionDbFunction)dbFunc).IsInModel); } [ConditionalFact] @@ -453,7 +453,7 @@ public void Can_get_and_set_sequence() Assert.Null(sequence.MaxValue); Assert.Same(typeof(long), sequence.Type); Assert.False(sequence.IsCyclic); - Assert.NotNull(((IConventionSequence)sequence).Builder); + Assert.True(((IConventionSequence)sequence).IsInModel); Assert.Same(sequence, model.FindSequence("Foo")); @@ -473,7 +473,7 @@ public void Can_get_and_set_sequence() Assert.Same(sequence, model.RemoveSequence("Foo")); - Assert.Null(((IConventionSequence)sequence).Builder); + Assert.False(((IConventionSequence)sequence).IsInModel); } [ConditionalFact] diff --git a/test/EFCore.Tests/Metadata/Conventions/ConventionDispatcherTest.cs b/test/EFCore.Tests/Metadata/Conventions/ConventionDispatcherTest.cs index 96dbdf084c6..02c38d471f8 100644 --- a/test/EFCore.Tests/Metadata/Conventions/ConventionDispatcherTest.cs +++ b/test/EFCore.Tests/Metadata/Conventions/ConventionDispatcherTest.cs @@ -2047,7 +2047,7 @@ public void ProcessSkipNavigationAdded( IConventionSkipNavigationBuilder skipNavigationBuilder, IConventionContext context) { - Assert.NotNull(skipNavigationBuilder.Metadata.Builder); + Assert.True(skipNavigationBuilder.Metadata.IsInModel); Calls.Add(skipNavigationBuilder.Metadata.Name); @@ -2153,7 +2153,7 @@ public virtual void ProcessSkipNavigationAnnotationChanged( IConventionAnnotation oldAnnotation, IConventionContext context) { - Assert.NotNull(navigationBuilder.Metadata.Builder); + Assert.True(navigationBuilder.Metadata.IsInModel); Calls.Add(annotation?.Value); @@ -2244,7 +2244,7 @@ public virtual void ProcessSkipNavigationForeignKeyChanged( IConventionForeignKey oldForeignKey, IConventionContext context) { - Assert.NotNull(navigationBuilder.Metadata.Builder); + Assert.True(navigationBuilder.Metadata.IsInModel); Calls.Add(foreignKey); @@ -2342,7 +2342,7 @@ public virtual void ProcessSkipNavigationInverseChanged( IConventionSkipNavigation oldInverse, IConventionContext context) { - Assert.NotNull(skipNavigationBuilder.Metadata.Builder); + Assert.True(skipNavigationBuilder.Metadata.IsInModel); Calls.Add(inverse.Name); @@ -3097,7 +3097,7 @@ public void ProcessPropertyAdded( IConventionPropertyBuilder propertyBuilder, IConventionContext context) { - Assert.NotNull(propertyBuilder.Metadata.Builder); + Assert.True(propertyBuilder.Metadata.IsInModel); Calls.Add(propertyBuilder.Metadata.Name); @@ -3336,7 +3336,7 @@ public void ProcessPropertyFieldChanged( FieldInfo oldFieldInfo, IConventionContext context) { - Assert.NotNull(propertyBuilder.Metadata.Builder); + Assert.True(propertyBuilder.Metadata.IsInModel); Calls.Add(oldFieldInfo?.Name); @@ -3437,7 +3437,7 @@ public void ProcessPropertyAnnotationChanged( IConventionAnnotation oldAnnotation, IConventionContext context) { - Assert.NotNull(propertyBuilder.Metadata.Builder); + Assert.True(propertyBuilder.Metadata.IsInModel); Calls.Add(annotation?.Value); diff --git a/test/EFCore.Tests/Metadata/Internal/EntityTypeTest.cs b/test/EFCore.Tests/Metadata/Internal/EntityTypeTest.cs index 3894b752ded..51f55d08b62 100644 --- a/test/EFCore.Tests/Metadata/Internal/EntityTypeTest.cs +++ b/test/EFCore.Tests/Metadata/Internal/EntityTypeTest.cs @@ -482,8 +482,8 @@ public void Can_remove_keys() var key1 = entityType.SetPrimaryKey(new[] { idProperty, nameProperty }); var key2 = entityType.AddKey(idProperty); - Assert.NotNull(((Key)key1).Builder); - Assert.NotNull(((Key)key2).Builder); + Assert.True(((Key)key1).IsInModel); + Assert.True(((Key)key2).IsInModel); Assert.Equal(new[] { key2, key1 }, entityType.GetKeys().ToArray()); Assert.True(idProperty.IsKey()); Assert.Equal(new[] { key1, key2 }, idProperty.GetContainingKeys().ToArray()); @@ -495,8 +495,8 @@ public void Can_remove_keys() Assert.Same(key2, entityType.RemoveKey(new[] { idProperty })); - Assert.Null(((Key)key1).Builder); - Assert.Null(((Key)key2).Builder); + Assert.False(((Key)key1).IsInModel); + Assert.False(((Key)key2).IsInModel); Assert.Empty(entityType.GetKeys()); Assert.False(idProperty.IsKey()); Assert.Empty(idProperty.GetContainingKeys()); @@ -912,8 +912,8 @@ public void Can_remove_foreign_keys() Assert.Same(fk2, orderType.RemoveForeignKey(new[] { customerFk2 }, customerKey, customerType)); - Assert.Null(((ForeignKey)fk1).Builder); - Assert.Null(((ForeignKey)fk2).Builder); + Assert.False(((ForeignKey)fk1).IsInModel); + Assert.False(((ForeignKey)fk2).IsInModel); Assert.Empty(orderType.GetForeignKeys()); } @@ -1608,8 +1608,8 @@ public void Can_add_retrieve_and_remove_indexes() Assert.Same(index2, entityType.RemoveIndex(new[] { property1, property2 })); - Assert.Null(((Index)index1).Builder); - Assert.Null(((Index)index2).Builder); + Assert.False(((Index)index1).IsInModel); + Assert.False(((Index)index2).IsInModel); Assert.Empty(entityType.GetIndexes()); Assert.False(property1.IsIndex()); Assert.Empty(property1.GetContainingIndexes()); @@ -1756,8 +1756,8 @@ public void Can_add_and_remove_properties() var property2 = entityType.AddProperty("Name", typeof(string)); - Assert.NotNull(((Property)property1).Builder); - Assert.NotNull(((Property)property2).Builder); + Assert.True(((Property)property1).IsInModel); + Assert.True(((Property)property2).IsInModel); Assert.True(new[] { property1, property2 }.SequenceEqual(entityType.GetProperties())); Assert.Same(property1, entityType.RemoveProperty(property1.Name)); @@ -1767,8 +1767,8 @@ public void Can_add_and_remove_properties() Assert.Same(property2, entityType.RemoveProperty("Name")); - Assert.Null(((Property)property1).Builder); - Assert.Null(((Property)property2).Builder); + Assert.False(((Property)property1).IsInModel); + Assert.False(((Property)property2).IsInModel); Assert.Empty(entityType.GetProperties()); } diff --git a/test/EFCore.Tests/Metadata/Internal/InternalSkipNavigationBuilderTest.cs b/test/EFCore.Tests/Metadata/Internal/InternalSkipNavigationBuilderTest.cs index 2466268b305..6dd714e5351 100644 --- a/test/EFCore.Tests/Metadata/Internal/InternalSkipNavigationBuilderTest.cs +++ b/test/EFCore.Tests/Metadata/Internal/InternalSkipNavigationBuilderTest.cs @@ -26,7 +26,7 @@ public void Can_only_override_lower_or_equal_source_SkipNavigation() Assert.NotNull(productEntity.HasRelationship( skipNavigation.DeclaringEntityType, null, nameof(Order.Products), fromDataAnnotation: true)); - Assert.Null(skipNavigation.Builder); + Assert.False(skipNavigation.IsInModel); Assert.Empty(skipNavigation.DeclaringEntityType.GetSkipNavigations()); } diff --git a/test/EFCore.Tests/Metadata/Internal/ModelTest.cs b/test/EFCore.Tests/Metadata/Internal/ModelTest.cs index e744bcdbfe9..f9459d5ca03 100644 --- a/test/EFCore.Tests/Metadata/Internal/ModelTest.cs +++ b/test/EFCore.Tests/Metadata/Internal/ModelTest.cs @@ -115,7 +115,7 @@ public void Can_add_and_remove_entity_by_type() Assert.Equal(typeof(Customer), entityType.ClrType); Assert.NotNull(model.FindEntityType(typeof(Customer))); Assert.Same(model, entityType.Model); - Assert.NotNull(((EntityType)entityType).Builder); + Assert.True(((EntityType)entityType).IsInModel); Assert.Same(entityType, model.FindEntityType(typeof(Customer))); @@ -125,7 +125,7 @@ public void Can_add_and_remove_entity_by_type() Assert.Null(model.RemoveEntityType(entityType.ClrType)); Assert.Null(model.FindEntityType(typeof(Customer))); - Assert.Null(((EntityType)entityType).Builder); + Assert.False(((EntityType)entityType).IsInModel); } [ConditionalFact] @@ -141,7 +141,7 @@ public void Can_add_and_remove_entity_by_name() Assert.Equal(typeof(Customer).FullName, entityType.Name); Assert.NotNull(model.FindEntityType(typeof(Customer).FullName)); Assert.Same(model, entityType.Model); - Assert.NotNull(((EntityType)entityType).Builder); + Assert.True(((EntityType)entityType).IsInModel); Assert.Same(entityType, model.FindEntityType(typeof(Customer).FullName)); @@ -151,7 +151,7 @@ public void Can_add_and_remove_entity_by_name() Assert.Null(model.RemoveEntityType(entityType.Name)); Assert.Null(model.FindEntityType(typeof(Customer).FullName)); - Assert.Null(((EntityType)entityType).Builder); + Assert.False(((EntityType)entityType).IsInModel); } [ConditionalFact] @@ -168,7 +168,7 @@ public void Can_add_and_remove_shared_entity() Assert.Equal(entityTypeName, entityType.Name); Assert.NotNull(model.FindEntityType(entityTypeName)); Assert.Same(model, entityType.Model); - Assert.NotNull(((EntityType)entityType).Builder); + Assert.True(((EntityType)entityType).IsInModel); Assert.Same(entityType, model.FindEntityType(entityTypeName)); Assert.Null(model.FindEntityType(typeof(Customer))); @@ -179,7 +179,7 @@ public void Can_add_and_remove_shared_entity() Assert.Null(model.RemoveEntityType(entityType.Name)); Assert.Null(model.FindEntityType(entityTypeName)); - Assert.Null(((EntityType)entityType).Builder); + Assert.False(((EntityType)entityType).IsInModel); } [ConditionalFact] From 44f5c30270ac9af7648f2c1fb982daf49830eb72 Mon Sep 17 00:00:00 2001 From: Shay Rojansky Date: Sat, 16 Jan 2021 19:32:43 +0100 Subject: [PATCH 2/8] Fixes to InMemoryQueryExpression --- .../Query/Internal/InMemoryQueryExpression.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/EFCore.InMemory/Query/Internal/InMemoryQueryExpression.cs b/src/EFCore.InMemory/Query/Internal/InMemoryQueryExpression.cs index 926f0b4a498..60bf77b3c4f 100644 --- a/src/EFCore.InMemory/Query/Internal/InMemoryQueryExpression.cs +++ b/src/EFCore.InMemory/Query/Internal/InMemoryQueryExpression.cs @@ -698,7 +698,7 @@ public virtual void AddInnerJoin( [NotNull] InMemoryQueryExpression innerQueryExpression, [NotNull] LambdaExpression outerKeySelector, [NotNull] LambdaExpression innerKeySelector, - [CanBeNull] Type? transparentIdentifierType) + [NotNull] Type transparentIdentifierType) { var outerParameter = Parameter(typeof(ValueBuffer), "outer"); var innerParameter = Parameter(typeof(ValueBuffer), "inner"); @@ -790,7 +790,7 @@ public virtual void AddLeftJoin( [NotNull] InMemoryQueryExpression innerQueryExpression, [NotNull] LambdaExpression outerKeySelector, [NotNull] LambdaExpression innerKeySelector, - [CanBeNull] Type? transparentIdentifierType) + [NotNull] Type transparentIdentifierType) { // GroupJoin phase var groupTransparentIdentifierType = TransparentIdentifierFactory.Create( @@ -938,7 +938,7 @@ EntityProjectionExpression CopyEntityProjectionToOuter(EntityProjectionExpressio /// public virtual void AddSelectMany( [NotNull] InMemoryQueryExpression innerQueryExpression, - [CanBeNull] Type? transparentIdentifierType, + [NotNull] Type transparentIdentifierType, bool innerNullable) { var outerParameter = Parameter(typeof(ValueBuffer), "outer"); From 7cc0c06c30456e53a61a5e6c7cea5bc1e3e79ae6 Mon Sep 17 00:00:00 2001 From: Shay Rojansky Date: Thu, 21 Jan 2021 13:48:52 +0100 Subject: [PATCH 3/8] Update src/EFCore.Relational/Metadata/Conventions/EntityTypeHierarchyMappingConvention.cs Co-authored-by: Andriy Svyryd --- .../Conventions/EntityTypeHierarchyMappingConvention.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/EFCore.Relational/Metadata/Conventions/EntityTypeHierarchyMappingConvention.cs b/src/EFCore.Relational/Metadata/Conventions/EntityTypeHierarchyMappingConvention.cs index 412d78a7953..61f35e770cc 100644 --- a/src/EFCore.Relational/Metadata/Conventions/EntityTypeHierarchyMappingConvention.cs +++ b/src/EFCore.Relational/Metadata/Conventions/EntityTypeHierarchyMappingConvention.cs @@ -52,7 +52,7 @@ public virtual void ProcessModelFinalizing( && !entityType.FindDeclaredForeignKeys(pk.Properties) .Any(fk => fk.PrincipalKey.IsPrimaryKey() && fk.PrincipalEntityType.IsAssignableFrom(entityType))) { - entityType.Builder.HasRelationship(entityType.BaseType, pk.Properties, entityType.BaseType.FindPrimaryKey()!)! + entityType.Builder.HasRelationship(entityType.BaseType, pk.Properties, pk)? .IsUnique(true); } From 028d378cd462650a37950fd7e602f6bf2ab31cd8 Mon Sep 17 00:00:00 2001 From: Shay Rojansky Date: Thu, 21 Jan 2021 14:22:36 +0100 Subject: [PATCH 4/8] Address Andriy's comments --- .../RelationalEntityTypeBuilderExtensions.cs | 22 +++++++++---------- .../SqlServerIndexBuilderExtensions.cs | 7 ++---- .../Extensions/MutablePropertyExtensions.cs | 6 +++-- .../Extensions/PropertyBaseExtensions.cs | 2 -- .../Infrastructure/ExpressionExtensions.cs | 1 - .../InvertibleRelationshipBuilderBase.cs | 2 -- .../Builders/ReferenceReferenceBuilder`.cs | 2 -- .../Builders/RelationshipBuilderBase.cs | 2 -- .../ForeignKeyAttributeConvention.cs | 6 ++--- .../Conventions/IConventionContext`.cs | 1 - .../ConventionDispatcher.ConventionScope.cs | 5 ++--- ...entionDispatcher.DelayedConventionScope.cs | 14 ++++++------ ...tionDispatcher.ImmediateConventionScope.cs | 4 ++-- .../Internal/ConventionDispatcher.cs | 4 ++-- .../InversePropertyAttributeConvention.cs | 2 +- .../Conventions/ModelCleanupConvention.cs | 4 ++-- .../NavigationAttributeConventionBase.cs | 2 +- .../NotMappedMemberAttributeConvention.cs | 2 +- .../PropertyDiscoveryConvention.cs | 2 +- .../RelationshipDiscoveryConvention.cs | 2 +- .../ServicePropertyDiscoveryConvention.cs | 2 +- .../Metadata/IConventionSkipNavigation.cs | 1 - .../Internal/InternalEntityTypeBuilder.cs | 17 ++++++-------- .../Internal/InternalForeignKeyBuilder.cs | 2 +- .../Metadata/Internal/InternalModelBuilder.cs | 7 +++--- .../Internal/InternalPropertyBuilder.cs | 1 - src/EFCore/Metadata/Internal/Property.cs | 9 ++++---- src/EFCore/Metadata/Internal/PropertyBase.cs | 2 +- .../Metadata/Internal/SkipNavigation.cs | 4 +--- src/EFCore/Metadata/Internal/TypeBase.cs | 8 +++---- .../Metadata/Internal/TypeBaseExtensions.cs | 4 ++-- 31 files changed, 65 insertions(+), 84 deletions(-) diff --git a/src/EFCore.Relational/Extensions/RelationalEntityTypeBuilderExtensions.cs b/src/EFCore.Relational/Extensions/RelationalEntityTypeBuilderExtensions.cs index 0e62c2a773e..d4229fcd57f 100644 --- a/src/EFCore.Relational/Extensions/RelationalEntityTypeBuilderExtensions.cs +++ b/src/EFCore.Relational/Extensions/RelationalEntityTypeBuilderExtensions.cs @@ -41,7 +41,7 @@ public static EntityTypeBuilder ToTable( /// The same builder instance so that multiple calls can be chained. public static EntityTypeBuilder ToTable( [NotNull] this EntityTypeBuilder entityTypeBuilder, - [CanBeNull] string? name, + [NotNull] string name, [NotNull] Action buildAction) => entityTypeBuilder.ToTable(name, null, buildAction); @@ -68,7 +68,7 @@ public static EntityTypeBuilder ToTable( /// The same builder instance so that multiple calls can be chained. public static EntityTypeBuilder ToTable( [NotNull] this EntityTypeBuilder entityTypeBuilder, - [CanBeNull] string? name, + [NotNull] string name, [NotNull] Action buildAction) where TEntity : class => entityTypeBuilder.ToTable(name, null, buildAction); @@ -83,7 +83,7 @@ public static EntityTypeBuilder ToTable( /// The same builder instance so that multiple calls can be chained. public static EntityTypeBuilder ToTable( [NotNull] this EntityTypeBuilder entityTypeBuilder, - [CanBeNull] string? name, + [NotNull] string name, [NotNull] Action> buildAction) where TEntity : class => entityTypeBuilder.ToTable(name, null, buildAction); @@ -115,7 +115,7 @@ public static EntityTypeBuilder ToTable( /// The same builder instance so that multiple calls can be chained. public static EntityTypeBuilder ToTable( [NotNull] this EntityTypeBuilder entityTypeBuilder, - [CanBeNull] string? name, // TODO-NULLABLE: Note nullability change (called with null by other overloads) + [NotNull] string name, [CanBeNull] string? schema, [NotNull] Action buildAction) { @@ -140,7 +140,7 @@ public static EntityTypeBuilder ToTable( /// The same builder instance so that multiple calls can be chained. public static EntityTypeBuilder ToTable( [NotNull] this EntityTypeBuilder entityTypeBuilder, - [CanBeNull] string? name, + [NotNull] string name, [CanBeNull] string? schema, [NotNull] Action buildAction) where TEntity : class @@ -176,7 +176,7 @@ public static EntityTypeBuilder ToTable( /// The same builder instance so that multiple calls can be chained. public static EntityTypeBuilder ToTable( [NotNull] this EntityTypeBuilder entityTypeBuilder, - [CanBeNull] string? name, + [NotNull] string name, [CanBeNull] string? schema, [NotNull] Action> buildAction) where TEntity : class @@ -731,7 +731,7 @@ public static EntityTypeBuilder ToFunction( Check.NotNull(entityTypeBuilder, nameof(entityTypeBuilder)); Check.NullButNotEmpty(name, nameof(name)); - CreateFunction(name, entityTypeBuilder.Metadata); + SetFunction(name, entityTypeBuilder.Metadata); return entityTypeBuilder; } @@ -752,7 +752,7 @@ public static EntityTypeBuilder ToFunction( Check.NullButNotEmpty(name, nameof(name)); Check.NotNull(configureFunction, nameof(configureFunction)); - configureFunction(new TableValuedFunctionBuilder(CreateFunction(name, entityTypeBuilder.Metadata))); + configureFunction(new TableValuedFunctionBuilder(SetFunction(name, entityTypeBuilder.Metadata))); return entityTypeBuilder; } @@ -798,7 +798,7 @@ public static OwnedNavigationBuilder ToFunction( Check.NotNull(ownedNavigationBuilder, nameof(ownedNavigationBuilder)); Check.NullButNotEmpty(name, nameof(name)); - CreateFunction(name, ownedNavigationBuilder.OwnedEntityType); + SetFunction(name, ownedNavigationBuilder.OwnedEntityType); return ownedNavigationBuilder; } @@ -819,7 +819,7 @@ public static OwnedNavigationBuilder ToFunction( Check.NullButNotEmpty(name, nameof(name)); Check.NotNull(configureFunction, nameof(configureFunction)); - configureFunction(new TableValuedFunctionBuilder(CreateFunction(name, ownedNavigationBuilder.OwnedEntityType))); + configureFunction(new TableValuedFunctionBuilder(SetFunction(name, ownedNavigationBuilder.OwnedEntityType))); return ownedNavigationBuilder; } @@ -858,7 +858,7 @@ public static OwnedNavigationBuilder ToFunction diff --git a/src/EFCore/Extensions/MutablePropertyExtensions.cs b/src/EFCore/Extensions/MutablePropertyExtensions.cs index 2c695885c6d..84ece9c2e8b 100644 --- a/src/EFCore/Extensions/MutablePropertyExtensions.cs +++ b/src/EFCore/Extensions/MutablePropertyExtensions.cs @@ -207,10 +207,12 @@ public static void SetProviderClrType([NotNull] this IMutableProperty property, /// /// The property. /// The for this property. - public static CoreTypeMapping SetTypeMapping( + public static void SetTypeMapping( [NotNull] this IMutableProperty property, [NotNull] CoreTypeMapping typeMapping) - => ((Property)property).SetTypeMapping(typeMapping, ConfigurationSource.Explicit)!; + { + ((Property)property).SetTypeMapping(typeMapping, ConfigurationSource.Explicit); + } /// /// Sets the custom for this property. diff --git a/src/EFCore/Extensions/PropertyBaseExtensions.cs b/src/EFCore/Extensions/PropertyBaseExtensions.cs index 761f3a259c2..d0330222c13 100644 --- a/src/EFCore/Extensions/PropertyBaseExtensions.cs +++ b/src/EFCore/Extensions/PropertyBaseExtensions.cs @@ -47,8 +47,6 @@ public static MemberInfo GetMemberInfo( { if (propertyBase.TryGetMemberInfo(forMaterialization, forSet, out var memberInfo, out var errorMessage)) { - // TODO-NULLABLE: memberInfo is null when the property is a collection navigation - but all of the callers seem to - // assume that it's never null. Should TryGetMemberInfo throw for collection navigations instead of returning null? return memberInfo!; } diff --git a/src/EFCore/Infrastructure/ExpressionExtensions.cs b/src/EFCore/Infrastructure/ExpressionExtensions.cs index 200f57ac51a..d8bf102d6ad 100644 --- a/src/EFCore/Infrastructure/ExpressionExtensions.cs +++ b/src/EFCore/Infrastructure/ExpressionExtensions.cs @@ -202,7 +202,6 @@ private static TMemberInfo GetInternalMemberAccess([NotNull] this L { if (targetMethod.Equals(runtimeProperty.GetMethod)) { - // TODO-NULLABLE: this used to return null if the type was wrong, but none of the call sites handled that return (TMemberInfo)(object)runtimeProperty; } } diff --git a/src/EFCore/Metadata/Builders/InvertibleRelationshipBuilderBase.cs b/src/EFCore/Metadata/Builders/InvertibleRelationshipBuilderBase.cs index fb83b34240b..b5ffbb83f89 100644 --- a/src/EFCore/Metadata/Builders/InvertibleRelationshipBuilderBase.cs +++ b/src/EFCore/Metadata/Builders/InvertibleRelationshipBuilderBase.cs @@ -23,8 +23,6 @@ public abstract class InvertibleRelationshipBuilderBase : IInfrastructure? _principalKeyProperties; private readonly bool? _required; - // TODO-NULLABLE: Refactored the construction here, please confirm it makes sense - /// /// 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 diff --git a/src/EFCore/Metadata/Builders/ReferenceReferenceBuilder`.cs b/src/EFCore/Metadata/Builders/ReferenceReferenceBuilder`.cs index 33c315a393e..0056f7e8208 100644 --- a/src/EFCore/Metadata/Builders/ReferenceReferenceBuilder`.cs +++ b/src/EFCore/Metadata/Builders/ReferenceReferenceBuilder`.cs @@ -102,7 +102,6 @@ protected ReferenceReferenceBuilder( dependentEntityTypeName, Check.NotNull(foreignKeyPropertyNames, nameof(foreignKeyPropertyNames))), this, - // TODO-NULLABLE: NRE if entity type cannot be resolved? inverted: Builder.Metadata.DeclaringEntityType.Name != ResolveEntityType(dependentEntityTypeName)!.Name, foreignKeySet: foreignKeyPropertyNames.Length > 0); @@ -213,7 +212,6 @@ public virtual ReferenceReferenceBuilder HasForeignKey< where TDependentEntity : class => new( HasForeignKeyBuilder( - // TODO-NULLABLE: NRE if entity type cannot be resolved? ResolveEntityType(typeof(TDependentEntity))!, typeof(TDependentEntity).ShortDisplayName(), Check.NotNull(foreignKeyExpression, nameof(foreignKeyExpression)).GetMemberAccessList()), diff --git a/src/EFCore/Metadata/Builders/RelationshipBuilderBase.cs b/src/EFCore/Metadata/Builders/RelationshipBuilderBase.cs index 8c84c527d56..4793a75edfe 100644 --- a/src/EFCore/Metadata/Builders/RelationshipBuilderBase.cs +++ b/src/EFCore/Metadata/Builders/RelationshipBuilderBase.cs @@ -21,8 +21,6 @@ public abstract class RelationshipBuilderBase : IInfrastructure? _principalKeyProperties; private readonly bool? _required; - // TODO-NULLABLE: Refactored the construction here, please confirm it makes sense - /// /// 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 diff --git a/src/EFCore/Metadata/Conventions/ForeignKeyAttributeConvention.cs b/src/EFCore/Metadata/Conventions/ForeignKeyAttributeConvention.cs index 20f18d66aab..aa4f8639461 100644 --- a/src/EFCore/Metadata/Conventions/ForeignKeyAttributeConvention.cs +++ b/src/EFCore/Metadata/Conventions/ForeignKeyAttributeConvention.cs @@ -331,7 +331,7 @@ var fkPropertiesOnDependentToPrincipal MemberInfo? candidateProperty = null; - foreach (var memberInfo in entityType.GetRuntimeProperties()!.Values.Cast() + foreach (var memberInfo in entityType.GetRuntimeProperties().Values.Cast() .Concat(entityType.GetRuntimeFields()!.Values)) { if (entityType.Builder.IsIgnored(memberInfo.GetSimpleMemberName()) @@ -405,9 +405,9 @@ private bool IsNavigationToSharedType(IConventionModel model, PropertyInfo prope } var navigationPropertyTargetType = - navigation!.DeclaringEntityType.GetRuntimeProperties()![navigation.Name].PropertyType; + navigation!.DeclaringEntityType.GetRuntimeProperties()[navigation.Name].PropertyType; - var otherNavigations = navigation.DeclaringEntityType.GetRuntimeProperties()!.Values + var otherNavigations = navigation.DeclaringEntityType.GetRuntimeProperties().Values .Where(p => p.PropertyType == navigationPropertyTargetType && p.GetSimpleMemberName() != navigation.Name) .OrderBy(p => p.GetSimpleMemberName()); diff --git a/src/EFCore/Metadata/Conventions/IConventionContext`.cs b/src/EFCore/Metadata/Conventions/IConventionContext`.cs index b727217cf68..bfc3ba924a3 100644 --- a/src/EFCore/Metadata/Conventions/IConventionContext`.cs +++ b/src/EFCore/Metadata/Conventions/IConventionContext`.cs @@ -22,7 +22,6 @@ public interface IConventionContext : IConventionContext /// /// /// The new metadata object or . - // TODO-NULLABLE: TBC (here and below) void StopProcessing([CanBeNull] TMetadata? result); /// diff --git a/src/EFCore/Metadata/Conventions/Internal/ConventionDispatcher.ConventionScope.cs b/src/EFCore/Metadata/Conventions/Internal/ConventionDispatcher.ConventionScope.cs index 84ab1ceddaa..87e288e9607 100644 --- a/src/EFCore/Metadata/Conventions/Internal/ConventionDispatcher.ConventionScope.cs +++ b/src/EFCore/Metadata/Conventions/Internal/ConventionDispatcher.ConventionScope.cs @@ -169,8 +169,8 @@ public int GetLeafCount() public abstract IConventionForeignKey? OnSkipNavigationForeignKeyChanged( [NotNull] IConventionSkipNavigationBuilder navigationBuilder, - [NotNull] IConventionForeignKey foreignKey, - [NotNull] IConventionForeignKey oldForeignKey); + [CanBeNull] IConventionForeignKey? foreignKey, + [CanBeNull] IConventionForeignKey? oldForeignKey); public abstract IConventionAnnotation? OnSkipNavigationAnnotationChanged( [NotNull] IConventionSkipNavigationBuilder navigationBuilder, @@ -178,7 +178,6 @@ public int GetLeafCount() [CanBeNull] IConventionAnnotation? annotation, [CanBeNull] IConventionAnnotation? oldAnnotation); - // TODO-NULLABLE: note annotation change here public abstract IConventionSkipNavigation? OnSkipNavigationInverseChanged( [NotNull] IConventionSkipNavigationBuilder navigationBuilder, [CanBeNull] IConventionSkipNavigation? inverse, diff --git a/src/EFCore/Metadata/Conventions/Internal/ConventionDispatcher.DelayedConventionScope.cs b/src/EFCore/Metadata/Conventions/Internal/ConventionDispatcher.DelayedConventionScope.cs index 2041fb611fa..26e4507ca88 100644 --- a/src/EFCore/Metadata/Conventions/Internal/ConventionDispatcher.DelayedConventionScope.cs +++ b/src/EFCore/Metadata/Conventions/Internal/ConventionDispatcher.DelayedConventionScope.cs @@ -240,10 +240,10 @@ public override IConventionSkipNavigationBuilder OnSkipNavigationAdded( return annotation; } - public override IConventionForeignKey OnSkipNavigationForeignKeyChanged( + public override IConventionForeignKey? OnSkipNavigationForeignKeyChanged( IConventionSkipNavigationBuilder navigationBuilder, - IConventionForeignKey foreignKey, - IConventionForeignKey oldForeignKey) + IConventionForeignKey? foreignKey, + IConventionForeignKey? oldForeignKey) { Add(new OnSkipNavigationForeignKeyChangedNode(navigationBuilder, foreignKey, oldForeignKey)); return foreignKey; @@ -722,8 +722,8 @@ private sealed class OnSkipNavigationForeignKeyChangedNode : ConventionNode { public OnSkipNavigationForeignKeyChangedNode( IConventionSkipNavigationBuilder navigationBuilder, - IConventionForeignKey foreignKey, - IConventionForeignKey oldForeignKey) + IConventionForeignKey? foreignKey, + IConventionForeignKey? oldForeignKey) { NavigationBuilder = navigationBuilder; ForeignKey = foreignKey; @@ -731,8 +731,8 @@ public OnSkipNavigationForeignKeyChangedNode( } public IConventionSkipNavigationBuilder NavigationBuilder { get; } - public IConventionForeignKey ForeignKey { get; } - public IConventionForeignKey OldForeignKey { get; } + public IConventionForeignKey? ForeignKey { get; } + public IConventionForeignKey? OldForeignKey { get; } public override void Run(ConventionDispatcher dispatcher) => dispatcher._immediateConventionScope.OnSkipNavigationForeignKeyChanged(NavigationBuilder, ForeignKey, OldForeignKey); diff --git a/src/EFCore/Metadata/Conventions/Internal/ConventionDispatcher.ImmediateConventionScope.cs b/src/EFCore/Metadata/Conventions/Internal/ConventionDispatcher.ImmediateConventionScope.cs index e7603a5c3a8..78d3f5129d0 100644 --- a/src/EFCore/Metadata/Conventions/Internal/ConventionDispatcher.ImmediateConventionScope.cs +++ b/src/EFCore/Metadata/Conventions/Internal/ConventionDispatcher.ImmediateConventionScope.cs @@ -798,8 +798,8 @@ public override void Run(ConventionDispatcher dispatcher) public override IConventionForeignKey? OnSkipNavigationForeignKeyChanged( IConventionSkipNavigationBuilder navigationBuilder, - IConventionForeignKey foreignKey, - IConventionForeignKey oldForeignKey) + IConventionForeignKey? foreignKey, + IConventionForeignKey? oldForeignKey) { if (!navigationBuilder.Metadata.DeclaringEntityType.IsInModel) { diff --git a/src/EFCore/Metadata/Conventions/Internal/ConventionDispatcher.cs b/src/EFCore/Metadata/Conventions/Internal/ConventionDispatcher.cs index 89af1122fe4..d02a732acad 100644 --- a/src/EFCore/Metadata/Conventions/Internal/ConventionDispatcher.cs +++ b/src/EFCore/Metadata/Conventions/Internal/ConventionDispatcher.cs @@ -357,8 +357,8 @@ public ConventionDispatcher([NotNull] ConventionSet conventionSet) /// public virtual IConventionForeignKey? OnSkipNavigationForeignKeyChanged( [NotNull] IConventionSkipNavigationBuilder navigationBuilder, - [NotNull] IConventionForeignKey foreignKey, - [NotNull] IConventionForeignKey oldForeignKey) + [CanBeNull] IConventionForeignKey? foreignKey, + [CanBeNull] IConventionForeignKey? oldForeignKey) => _scope.OnSkipNavigationForeignKeyChanged(navigationBuilder, foreignKey, oldForeignKey); /// diff --git a/src/EFCore/Metadata/Conventions/InversePropertyAttributeConvention.cs b/src/EFCore/Metadata/Conventions/InversePropertyAttributeConvention.cs index 9b5c7ab280e..9dfdffb62f4 100644 --- a/src/EFCore/Metadata/Conventions/InversePropertyAttributeConvention.cs +++ b/src/EFCore/Metadata/Conventions/InversePropertyAttributeConvention.cs @@ -86,7 +86,7 @@ private void Process( { var entityType = entityTypeBuilder.Metadata; var targetClrType = targetEntityTypeBuilder.Metadata.ClrType; - var inverseNavigationPropertyInfo = targetEntityTypeBuilder.Metadata.GetRuntimeProperties()!.Values + var inverseNavigationPropertyInfo = targetEntityTypeBuilder.Metadata.GetRuntimeProperties().Values .FirstOrDefault(p => string.Equals(p.GetSimpleMemberName(), attribute.Property, StringComparison.OrdinalIgnoreCase)); if (inverseNavigationPropertyInfo == null diff --git a/src/EFCore/Metadata/Conventions/ModelCleanupConvention.cs b/src/EFCore/Metadata/Conventions/ModelCleanupConvention.cs index c7add5f5668..178599fa614 100644 --- a/src/EFCore/Metadata/Conventions/ModelCleanupConvention.cs +++ b/src/EFCore/Metadata/Conventions/ModelCleanupConvention.cs @@ -116,13 +116,13 @@ public override IEnumerable GetOutgoingNeighbors(IConvent .Union( from.GetReferencingForeignKeys().Where(fk => fk.PrincipalToDependent != null).Select(fk => fk.DeclaringEntityType)) .Union(from.GetSkipNavigations().Where(sn => sn.ForeignKey != null).Select(sn => sn.ForeignKey!.DeclaringEntityType)) - .Union(from.GetSkipNavigations().Where(sn => sn.TargetEntityType != null).Select(sn => sn.TargetEntityType)); + .Union(from.GetSkipNavigations().Select(sn => sn.TargetEntityType)); public override IEnumerable GetIncomingNeighbors(IConventionEntityType to) => to.GetForeignKeys().Where(fk => fk.PrincipalToDependent != null).Select(fk => fk.PrincipalEntityType) .Union(to.GetReferencingForeignKeys().Where(fk => fk.DependentToPrincipal != null).Select(fk => fk.DeclaringEntityType)) .Union(to.GetSkipNavigations().Where(sn => sn.ForeignKey != null).Select(sn => sn.ForeignKey!.DeclaringEntityType)) - .Union(to.GetSkipNavigations().Where(sn => sn.TargetEntityType != null).Select(sn => sn.TargetEntityType)); + .Union(to.GetSkipNavigations().Select(sn => sn.TargetEntityType)); public override void Clear() { diff --git a/src/EFCore/Metadata/Conventions/NavigationAttributeConventionBase.cs b/src/EFCore/Metadata/Conventions/NavigationAttributeConventionBase.cs index 6dd1aeb8fca..d11bff80b9a 100644 --- a/src/EFCore/Metadata/Conventions/NavigationAttributeConventionBase.cs +++ b/src/EFCore/Metadata/Conventions/NavigationAttributeConventionBase.cs @@ -188,7 +188,7 @@ public virtual void ProcessEntityTypeBaseTypeChanged( private List<(PropertyInfo, Type)>? GetNavigationsWithAttribute(IConventionEntityType entityType) { var navigations = new List<(PropertyInfo, Type)>(); - foreach (var navigationPropertyInfo in entityType.GetRuntimeProperties()!.Values) + foreach (var navigationPropertyInfo in entityType.GetRuntimeProperties().Values) { var targetClrType = FindCandidateNavigationWithAttributePropertyType(navigationPropertyInfo); if (targetClrType == null) diff --git a/src/EFCore/Metadata/Conventions/NotMappedMemberAttributeConvention.cs b/src/EFCore/Metadata/Conventions/NotMappedMemberAttributeConvention.cs index 7d85b6dd6ae..6a6b70dd9c6 100644 --- a/src/EFCore/Metadata/Conventions/NotMappedMemberAttributeConvention.cs +++ b/src/EFCore/Metadata/Conventions/NotMappedMemberAttributeConvention.cs @@ -46,7 +46,7 @@ public virtual void ProcessEntityTypeAdded( Check.NotNull(entityTypeBuilder, nameof(entityTypeBuilder)); var entityType = entityTypeBuilder.Metadata; - var members = entityType.GetRuntimeProperties()!.Values.Cast() + var members = entityType.GetRuntimeProperties().Values.Cast() .Concat(entityType.GetRuntimeFields()!.Values); foreach (var member in members) diff --git a/src/EFCore/Metadata/Conventions/PropertyDiscoveryConvention.cs b/src/EFCore/Metadata/Conventions/PropertyDiscoveryConvention.cs index 76daf11b263..af12584fbe3 100644 --- a/src/EFCore/Metadata/Conventions/PropertyDiscoveryConvention.cs +++ b/src/EFCore/Metadata/Conventions/PropertyDiscoveryConvention.cs @@ -65,7 +65,7 @@ public virtual void ProcessEntityTypeBaseTypeChanged( private void Process(IConventionEntityTypeBuilder entityTypeBuilder) { - foreach (var propertyInfo in entityTypeBuilder.Metadata.GetRuntimeProperties()!.Values) + foreach (var propertyInfo in entityTypeBuilder.Metadata.GetRuntimeProperties().Values) { if (IsCandidatePrimitiveProperty(propertyInfo)) { diff --git a/src/EFCore/Metadata/Conventions/RelationshipDiscoveryConvention.cs b/src/EFCore/Metadata/Conventions/RelationshipDiscoveryConvention.cs index e3cbaa922db..8394b783106 100644 --- a/src/EFCore/Metadata/Conventions/RelationshipDiscoveryConvention.cs +++ b/src/EFCore/Metadata/Conventions/RelationshipDiscoveryConvention.cs @@ -982,7 +982,7 @@ private ImmutableSortedDictionary GetNavigationCandidates(IC } var dictionaryBuilder = ImmutableSortedDictionary.CreateBuilder(MemberInfoNameComparer.Instance); - foreach (var propertyInfo in entityType.GetRuntimeProperties()!.Values.OrderBy(p => p.Name)) + foreach (var propertyInfo in entityType.GetRuntimeProperties().Values.OrderBy(p => p.Name)) { var targetType = FindCandidateNavigationPropertyType(propertyInfo); if (targetType != null) diff --git a/src/EFCore/Metadata/Conventions/ServicePropertyDiscoveryConvention.cs b/src/EFCore/Metadata/Conventions/ServicePropertyDiscoveryConvention.cs index 3d83f171aa5..9a5ce788620 100644 --- a/src/EFCore/Metadata/Conventions/ServicePropertyDiscoveryConvention.cs +++ b/src/EFCore/Metadata/Conventions/ServicePropertyDiscoveryConvention.cs @@ -72,7 +72,7 @@ public virtual void ProcessEntityTypeBaseTypeChanged( private void Process(IConventionEntityTypeBuilder entityTypeBuilder) { var entityType = entityTypeBuilder.Metadata; - var candidates = entityType.GetRuntimeProperties()!.Values; + var candidates = entityType.GetRuntimeProperties().Values; foreach (var propertyInfo in candidates) { diff --git a/src/EFCore/Metadata/IConventionSkipNavigation.cs b/src/EFCore/Metadata/IConventionSkipNavigation.cs index 09166e8f67d..d7a154304e1 100644 --- a/src/EFCore/Metadata/IConventionSkipNavigation.cs +++ b/src/EFCore/Metadata/IConventionSkipNavigation.cs @@ -40,7 +40,6 @@ public interface IConventionSkipNavigation : ISkipNavigation, IConventionNavigat /// /// Gets the entity type that this navigation property will hold an instance(s) of. /// - // TODO-NULLABLE: I can see conventions testing this for null, but in SkipNavigation that doesn't seem possible... new IConventionEntityType TargetEntityType { [DebuggerStepThrough] diff --git a/src/EFCore/Metadata/Internal/InternalEntityTypeBuilder.cs b/src/EFCore/Metadata/Internal/InternalEntityTypeBuilder.cs index b6cacd9caa6..51337263242 100644 --- a/src/EFCore/Metadata/Internal/InternalEntityTypeBuilder.cs +++ b/src/EFCore/Metadata/Internal/InternalEntityTypeBuilder.cs @@ -1838,7 +1838,6 @@ public virtual bool CanSetDefiningQuery([CanBeNull] LambdaExpression? query, Con /// 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. /// - // TODO-NULLABLE: Corrected annotation to nullable public virtual bool CanSetBaseType([CanBeNull] EntityType? baseEntityType, ConfigurationSource configurationSource) { if (Metadata.BaseType == baseEntityType @@ -3350,11 +3349,11 @@ private bool Contains(IForeignKey? inheritedFk, IForeignKey derivedFk) if (navigation.MemberInfo == null) { - if (Metadata.GetRuntimeProperties()!.TryGetValue(navigation.Name!, out var propertyInfo)) + if (Metadata.GetRuntimeProperties().TryGetValue(navigation.Name!, out var propertyInfo)) { navigation = new MemberIdentity(propertyInfo); } - else if (Metadata.GetRuntimeFields()!.TryGetValue(navigation.Name!, out var fieldInfo)) + else if (Metadata.GetRuntimeFields().TryGetValue(navigation.Name!, out var fieldInfo)) { navigation = new MemberIdentity(fieldInfo); } @@ -3507,16 +3506,15 @@ private bool Contains(IForeignKey? inheritedFk, IForeignKey derivedFk) using var batch = ModelBuilder.Metadata.DelayConventions(); var foreignKey = SetOrAddForeignKey( foreignKey: null, principalEntityTypeBuilder, dependentProperties, principalKey, - propertyBaseName, required, configurationSource); + propertyBaseName, required, configurationSource)!; if (required.HasValue - && foreignKey?.IsRequired == required.Value) + && foreignKey.IsRequired == required.Value) { foreignKey.SetIsRequired(required.Value, configurationSource); } - // TODO-NULLABLE: can foreignKey be null from SetOrAddForeignKey above? - return (InternalForeignKeyBuilder?)batch.Run(foreignKey!)?.Builder; + return (InternalForeignKeyBuilder?)batch.Run(foreignKey)?.Builder; } /// @@ -3536,10 +3534,9 @@ private bool Contains(IForeignKey? inheritedFk, IForeignKey derivedFk) using var batch = ModelBuilder.Metadata.DelayConventions(); var updatedForeignKey = SetOrAddForeignKey( foreignKey, foreignKey.PrincipalEntityType.Builder, dependentProperties, principalKey, - propertyBaseName, isRequired, configurationSource); + propertyBaseName, isRequired, configurationSource)!; - // TODO-NULLABLE: can updatedForeignKey be null from SetOrAddForeignKey above? - return (InternalForeignKeyBuilder?)batch.Run(updatedForeignKey!)?.Builder; + return (InternalForeignKeyBuilder?)batch.Run(updatedForeignKey)?.Builder; } private ForeignKey? SetOrAddForeignKey( diff --git a/src/EFCore/Metadata/Internal/InternalForeignKeyBuilder.cs b/src/EFCore/Metadata/Internal/InternalForeignKeyBuilder.cs index b4635cb3953..64bd7adc2bb 100644 --- a/src/EFCore/Metadata/Internal/InternalForeignKeyBuilder.cs +++ b/src/EFCore/Metadata/Internal/InternalForeignKeyBuilder.cs @@ -1963,7 +1963,7 @@ private bool CanSetForeignKey( /// doing so can result in application failures when updating to a new Entity Framework Core release. /// public virtual InternalForeignKeyBuilder? HasPrincipalKey( - [NotNull] IReadOnlyList members, + [CanBeNull] IReadOnlyList? members, ConfigurationSource configurationSource) { using (var batch = Metadata.DeclaringEntityType.Model.DelayConventions()) diff --git a/src/EFCore/Metadata/Internal/InternalModelBuilder.cs b/src/EFCore/Metadata/Internal/InternalModelBuilder.cs index 172e8c6cd25..16d22b004f4 100644 --- a/src/EFCore/Metadata/Internal/InternalModelBuilder.cs +++ b/src/EFCore/Metadata/Internal/InternalModelBuilder.cs @@ -125,16 +125,15 @@ public override InternalModelBuilder ModelBuilder } else { - // TODO-NULLABLE: is it actually possible to have an unnamed TypeIdentity here without a CLR type? - clrType = type.Type ?? Metadata.FindClrType(type.Name); - if (Metadata.IsShared(clrType!)) + clrType = type.Type!; + if (Metadata.IsShared(clrType)) { return configurationSource == ConfigurationSource.Explicit ? throw new InvalidOperationException(CoreStrings.ClashingSharedType(clrType.ShortDisplayName())) : (InternalEntityTypeBuilder?)null; } - entityType = Metadata.FindEntityType(clrType!); + entityType = Metadata.FindEntityType(clrType); } if (shouldBeOwned == false diff --git a/src/EFCore/Metadata/Internal/InternalPropertyBuilder.cs b/src/EFCore/Metadata/Internal/InternalPropertyBuilder.cs index 62db8cdf9bd..747db2cf288 100644 --- a/src/EFCore/Metadata/Internal/InternalPropertyBuilder.cs +++ b/src/EFCore/Metadata/Internal/InternalPropertyBuilder.cs @@ -587,7 +587,6 @@ public virtual InternalPropertyBuilder Attach([NotNull] InternalEntityTypeBuilde var configurationSource = Metadata.GetConfigurationSource(); var typeConfigurationSource = Metadata.GetTypeConfigurationSource(); if (newProperty != null - && newProperty.IsInModel && (newProperty.GetConfigurationSource().Overrides(configurationSource) || newProperty.GetTypeConfigurationSource().Overrides(typeConfigurationSource) || (Metadata.ClrType == newProperty.ClrType diff --git a/src/EFCore/Metadata/Internal/Property.cs b/src/EFCore/Metadata/Internal/Property.cs index 50389e2e519..73dd36caa98 100644 --- a/src/EFCore/Metadata/Internal/Property.cs +++ b/src/EFCore/Metadata/Internal/Property.cs @@ -517,11 +517,12 @@ public virtual CoreTypeMapping? TypeMapping /// 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. /// - // [return: CA.NotNullIfNotNull("typeMapping")] public virtual CoreTypeMapping? SetTypeMapping([CanBeNull] CoreTypeMapping? typeMapping, ConfigurationSource configurationSource) { _typeMapping = typeMapping; - _typeMappingConfigurationSource = configurationSource.Max(_typeMappingConfigurationSource); + _typeMappingConfigurationSource = typeMapping is null + ? null + : configurationSource.Max(_typeMappingConfigurationSource); return typeMapping; } @@ -670,9 +671,9 @@ public static bool AreCompatible([NotNull] IReadOnlyList properties, [ property => property.IsShadowProperty() || ((property.PropertyInfo != null - && entityType.GetRuntimeProperties()!.ContainsKey(property.Name)) + && entityType.GetRuntimeProperties().ContainsKey(property.Name)) || (property.FieldInfo != null - && entityType.GetRuntimeFields()!.ContainsKey(property.Name)))); + && entityType.GetRuntimeFields().ContainsKey(property.Name)))); } /// diff --git a/src/EFCore/Metadata/Internal/PropertyBase.cs b/src/EFCore/Metadata/Internal/PropertyBase.cs index 28fc000f473..040c5f4a68d 100644 --- a/src/EFCore/Metadata/Internal/PropertyBase.cs +++ b/src/EFCore/Metadata/Internal/PropertyBase.cs @@ -165,7 +165,7 @@ public virtual void SetConfigurationSource(ConfigurationSource configurationSour [NotNull] string propertyName, bool shouldThrow) { - if (!type.GetRuntimeFields()!.TryGetValue(fieldName, out var fieldInfo) + if (!type.GetRuntimeFields().TryGetValue(fieldName, out var fieldInfo) && shouldThrow) { throw new InvalidOperationException( diff --git a/src/EFCore/Metadata/Internal/SkipNavigation.cs b/src/EFCore/Metadata/Internal/SkipNavigation.cs index 8cc6ba3e36a..3e0174063fd 100644 --- a/src/EFCore/Metadata/Internal/SkipNavigation.cs +++ b/src/EFCore/Metadata/Internal/SkipNavigation.cs @@ -202,10 +202,9 @@ public virtual EntityType? JoinEntityType ForeignKey = null; _foreignKeyConfigurationSource = null; - // TODO-NULLABLE: should OnSkipNavigationForeignKeyChanged be changed to support nullable foreignKey/oldForeignKey? return isChanging ? (ForeignKey?)DeclaringEntityType.Model.ConventionDispatcher - .OnSkipNavigationForeignKeyChanged(Builder, foreignKey!, oldForeignKey!) + .OnSkipNavigationForeignKeyChanged(Builder, foreignKey, oldForeignKey) : foreignKey; } @@ -274,7 +273,6 @@ public virtual void UpdateForeignKeyConfigurationSource(ConfigurationSource conf Inverse = null; _inverseConfigurationSource = null; - // TODO-NULLABLE: should OnSkipNavigationInverseChanged be changed to support nullable inverse/oldInverse? return isChanging ? (SkipNavigation?)DeclaringEntityType.Model.ConventionDispatcher .OnSkipNavigationInverseChanged(Builder, inverse!, oldInverse!) diff --git a/src/EFCore/Metadata/Internal/TypeBase.cs b/src/EFCore/Metadata/Internal/TypeBase.cs index eacd464d169..1ad0e442dab 100644 --- a/src/EFCore/Metadata/Internal/TypeBase.cs +++ b/src/EFCore/Metadata/Internal/TypeBase.cs @@ -159,11 +159,11 @@ public virtual void UpdateConfigurationSource(ConfigurationSource configurationS /// 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. /// - public virtual IReadOnlyDictionary? GetRuntimeProperties() + public virtual IReadOnlyDictionary GetRuntimeProperties() { if (ClrType == null) { - return null; + return null!; } if (_runtimeProperties == null) @@ -190,11 +190,11 @@ public virtual void UpdateConfigurationSource(ConfigurationSource configurationS /// 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. /// - public virtual IReadOnlyDictionary? GetRuntimeFields() + public virtual IReadOnlyDictionary GetRuntimeFields() { if (ClrType == null) { - return null; + return null!; } if (_runtimeFields == null) diff --git a/src/EFCore/Metadata/Internal/TypeBaseExtensions.cs b/src/EFCore/Metadata/Internal/TypeBaseExtensions.cs index aa1d5e42eed..0ea1ed8b815 100644 --- a/src/EFCore/Metadata/Internal/TypeBaseExtensions.cs +++ b/src/EFCore/Metadata/Internal/TypeBaseExtensions.cs @@ -24,7 +24,7 @@ public static class TypeBaseExtensions /// 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. /// - public static IReadOnlyDictionary? GetRuntimeProperties([NotNull] this ITypeBase type) + public static IReadOnlyDictionary GetRuntimeProperties([NotNull] this ITypeBase type) => ((TypeBase)type).GetRuntimeProperties(); /// @@ -33,7 +33,7 @@ public static class TypeBaseExtensions /// 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. /// - public static IReadOnlyDictionary? GetRuntimeFields([NotNull] this ITypeBase type) + public static IReadOnlyDictionary GetRuntimeFields([NotNull] this ITypeBase type) => ((TypeBase)type).GetRuntimeFields(); /// From 296ebe58f40685fa1a91cfd0ae10f00f5aa5041f Mon Sep 17 00:00:00 2001 From: Shay Rojansky Date: Thu, 21 Jan 2021 20:34:49 +0100 Subject: [PATCH 5/8] Remove all null checks on EntityType.ClrType --- .../Internal/CosmosModelValidator.cs | 2 +- .../Internal/EntityProjectionExpression.cs | 2 +- ...yExpressionTranslatingExpressionVisitor.cs | 5 +- ....CustomShaperCompilingExpressionVisitor.cs | 4 +- ...erExpressionProcessingExpressionVisitor.cs | 2 +- .../TableNameFromDbSetConvention.cs | 2 - .../Query/EntityProjectionExpression.cs | 2 +- ...sitor.ShaperProcessingExpressionVisitor.cs | 8 +-- ...lationalSqlTranslatingExpressionVisitor.cs | 4 +- .../Internal/InternalMixedEntityEntry.cs | 5 -- src/EFCore/Extensions/EntityTypeExtensions.cs | 5 +- .../Infrastructure/ExpressionExtensions.cs | 2 +- src/EFCore/Infrastructure/ModelValidator.cs | 17 ++---- .../Metadata/Builders/DiscriminatorBuilder.cs | 4 +- .../Metadata/Builders/EntityTypeBuilder.cs | 5 -- .../Builders/OwnedNavigationBuilder.cs | 2 +- .../Conventions/BackingFieldConvention.cs | 2 +- .../EntityTypeAttributeConventionBase.cs | 3 +- .../ForeignKeyAttributeConvention.cs | 4 +- .../Conventions/IndexAttributeConvention.cs | 5 -- .../NavigationAttributeConventionBase.cs | 6 +- .../NotMappedMemberAttributeConvention.cs | 2 +- .../RelationshipDiscoveryConvention.cs | 5 +- src/EFCore/Metadata/Internal/EntityType.cs | 60 +++++++++---------- .../Metadata/Internal/EntityTypeExtensions.cs | 2 +- .../Internal/InternalEntityTypeBuilder.cs | 11 +--- .../Internal/InternalForeignKeyBuilder.cs | 15 ++--- .../Metadata/Internal/InternalModelBuilder.cs | 2 +- src/EFCore/Metadata/Internal/Model.cs | 6 +- src/EFCore/Metadata/Internal/TypeBase.cs | 35 +---------- src/EFCore/Query/EntityShaperExpression.cs | 3 +- ...ingExpressionVisitor.ExpressionVisitors.cs | 2 +- ...nExpandingExpressionVisitor.Expressions.cs | 3 +- .../NavigationExpandingExpressionVisitor.cs | 2 +- src/EFCore/Query/QueryRootExpression.cs | 4 +- .../ShapedQueryCompilingExpressionVisitor.cs | 9 ++- 36 files changed, 85 insertions(+), 167 deletions(-) diff --git a/src/EFCore.Cosmos/Infrastructure/Internal/CosmosModelValidator.cs b/src/EFCore.Cosmos/Infrastructure/Internal/CosmosModelValidator.cs index de494eb5868..94f4a0be63a 100644 --- a/src/EFCore.Cosmos/Infrastructure/Internal/CosmosModelValidator.cs +++ b/src/EFCore.Cosmos/Infrastructure/Internal/CosmosModelValidator.cs @@ -139,7 +139,7 @@ protected virtual void ValidateSharedContainerCompatibility( firstEntityType = entityType; } - if (entityType.ClrType?.IsInstantiable() == true + if (entityType.ClrType.IsInstantiable() && entityType.GetContainingPropertyName() == null) { if (entityType.GetDiscriminatorProperty() == null) diff --git a/src/EFCore.InMemory/Query/Internal/EntityProjectionExpression.cs b/src/EFCore.InMemory/Query/Internal/EntityProjectionExpression.cs index f72a15f02cb..198ecb25e38 100644 --- a/src/EFCore.InMemory/Query/Internal/EntityProjectionExpression.cs +++ b/src/EFCore.InMemory/Query/Internal/EntityProjectionExpression.cs @@ -57,7 +57,7 @@ public EntityProjectionExpression( /// doing so can result in application failures when updating to a new Entity Framework Core release. /// public override Type Type - => EntityType.ClrType!; + => EntityType.ClrType; /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to diff --git a/src/EFCore.InMemory/Query/Internal/InMemoryExpressionTranslatingExpressionVisitor.cs b/src/EFCore.InMemory/Query/Internal/InMemoryExpressionTranslatingExpressionVisitor.cs index 56699d24a69..eedee36d22a 100644 --- a/src/EFCore.InMemory/Query/Internal/InMemoryExpressionTranslatingExpressionVisitor.cs +++ b/src/EFCore.InMemory/Query/Internal/InMemoryExpressionTranslatingExpressionVisitor.cs @@ -1335,7 +1335,7 @@ when methodCallExpression.Method.IsGenericMethod var parameterName = methodCallExpression.Arguments[1].GetConstantValue(); var lambda = Expression.Lambda( Expression.Call( - _parameterListValueExtractor.MakeGenericMethod(entityType.ClrType!, property.ClrType.MakeNullable()), + _parameterListValueExtractor.MakeGenericMethod(entityType.ClrType, property.ClrType.MakeNullable()), QueryCompilationContext.QueryContextParameter, Expression.Constant(parameterName, typeof(string)), Expression.Constant(property, typeof(IProperty))), @@ -1728,8 +1728,7 @@ private EntityReferenceExpression(EntityReferenceExpression entityReferenceExpre public IEntityType EntityType { get; } public override Type Type - // No shadow entities at runtime - => EntityType.ClrType!; + => EntityType.ClrType; public override ExpressionType NodeType => ExpressionType.Extension; diff --git a/src/EFCore.InMemory/Query/Internal/InMemoryShapedQueryCompilingExpressionVisitor.CustomShaperCompilingExpressionVisitor.cs b/src/EFCore.InMemory/Query/Internal/InMemoryShapedQueryCompilingExpressionVisitor.CustomShaperCompilingExpressionVisitor.cs index a380edbd329..5135e4c3472 100644 --- a/src/EFCore.InMemory/Query/Internal/InMemoryShapedQueryCompilingExpressionVisitor.CustomShaperCompilingExpressionVisitor.cs +++ b/src/EFCore.InMemory/Query/Internal/InMemoryShapedQueryCompilingExpressionVisitor.CustomShaperCompilingExpressionVisitor.cs @@ -157,9 +157,9 @@ protected override Expression VisitExtension(Expression extensionExpression) if (extensionExpression is IncludeExpression includeExpression) { var entityClrType = includeExpression.EntityExpression.Type; - var includingClrType = includeExpression.Navigation.DeclaringEntityType.ClrType!; + var includingClrType = includeExpression.Navigation.DeclaringEntityType.ClrType; var inverseNavigation = includeExpression.Navigation.Inverse; - var relatedEntityClrType = includeExpression.Navigation.TargetEntityType.ClrType!; + var relatedEntityClrType = includeExpression.Navigation.TargetEntityType.ClrType; if (includingClrType != entityClrType && includingClrType.IsAssignableFrom(entityClrType)) { diff --git a/src/EFCore.InMemory/Query/Internal/ShaperExpressionProcessingExpressionVisitor.cs b/src/EFCore.InMemory/Query/Internal/ShaperExpressionProcessingExpressionVisitor.cs index ecf886590f6..48423552517 100644 --- a/src/EFCore.InMemory/Query/Internal/ShaperExpressionProcessingExpressionVisitor.cs +++ b/src/EFCore.InMemory/Query/Internal/ShaperExpressionProcessingExpressionVisitor.cs @@ -78,7 +78,7 @@ protected override Expression VisitExtension(Expression extensionExpression) var key = GenerateKey((ProjectionBindingExpression)entityShaperExpression.ValueBufferExpression); if (!_mapping.TryGetValue(key, out var variable)) { - variable = Expression.Parameter(entityShaperExpression.EntityType.ClrType!); + variable = Expression.Parameter(entityShaperExpression.EntityType.ClrType); _variables.Add(variable); _expressions.Add(Expression.Assign(variable, entityShaperExpression)); _mapping[key] = variable; diff --git a/src/EFCore.Relational/Metadata/Conventions/TableNameFromDbSetConvention.cs b/src/EFCore.Relational/Metadata/Conventions/TableNameFromDbSetConvention.cs index e2f3d586fa0..fd9fab069f2 100644 --- a/src/EFCore.Relational/Metadata/Conventions/TableNameFromDbSetConvention.cs +++ b/src/EFCore.Relational/Metadata/Conventions/TableNameFromDbSetConvention.cs @@ -84,7 +84,6 @@ public virtual void ProcessEntityTypeBaseTypeChanged( } else if (oldBaseType != null && newBaseType == null - && entityType.ClrType != null && !entityType.HasSharedClrType && _sets.TryGetValue(entityType.ClrType, out var setName)) { @@ -103,7 +102,6 @@ public virtual void ProcessEntityTypeAdded( { var entityType = entityTypeBuilder.Metadata; if (entityType.BaseType == null - && entityType.ClrType != null && !entityType.HasSharedClrType && _sets.TryGetValue(entityType.ClrType, out var setName)) { diff --git a/src/EFCore.Relational/Query/EntityProjectionExpression.cs b/src/EFCore.Relational/Query/EntityProjectionExpression.cs index 88d1cf7f1c4..c9183afdbbe 100644 --- a/src/EFCore.Relational/Query/EntityProjectionExpression.cs +++ b/src/EFCore.Relational/Query/EntityProjectionExpression.cs @@ -79,7 +79,7 @@ public sealed override ExpressionType NodeType /// public override Type Type - => EntityType.ClrType!; + => EntityType.ClrType; /// protected override Expression VisitChildren(ExpressionVisitor visitor) diff --git a/src/EFCore.Relational/Query/RelationalShapedQueryCompilingExpressionVisitor.ShaperProcessingExpressionVisitor.cs b/src/EFCore.Relational/Query/RelationalShapedQueryCompilingExpressionVisitor.ShaperProcessingExpressionVisitor.cs index d984a9418e5..34ce8d558a4 100644 --- a/src/EFCore.Relational/Query/RelationalShapedQueryCompilingExpressionVisitor.ShaperProcessingExpressionVisitor.cs +++ b/src/EFCore.Relational/Query/RelationalShapedQueryCompilingExpressionVisitor.ShaperProcessingExpressionVisitor.cs @@ -508,7 +508,7 @@ protected override Expression VisitExtension(Expression extensionExpression) var entityType = entity.Type; var navigation = includeExpression.Navigation; - var includingEntityType = navigation.DeclaringEntityType.ClrType!; + var includingEntityType = navigation.DeclaringEntityType.ClrType; if (includingEntityType != entityType && includingEntityType.IsAssignableFrom(entityType)) { @@ -595,7 +595,7 @@ protected override Expression VisitExtension(Expression extensionExpression) var entityType = entity.Type; var navigation = includeExpression.Navigation; - var includingEntityType = navigation.DeclaringEntityType.ClrType!; + var includingEntityType = navigation.DeclaringEntityType.ClrType; if (includingEntityType != entityType && includingEntityType.IsAssignableFrom(entityType)) { @@ -672,9 +672,9 @@ protected override Expression VisitExtension(Expression extensionExpression) var navigationExpression = Visit(includeExpression.NavigationExpression); var entityType = entity.Type; var navigation = includeExpression.Navigation; - var includingType = navigation.DeclaringEntityType.ClrType!; + var includingType = navigation.DeclaringEntityType.ClrType; var inverseNavigation = navigation.Inverse; - var relatedEntityType = navigation.TargetEntityType.ClrType!; + var relatedEntityType = navigation.TargetEntityType.ClrType; if (includingType != entityType && includingType.IsAssignableFrom(entityType)) { diff --git a/src/EFCore.Relational/Query/RelationalSqlTranslatingExpressionVisitor.cs b/src/EFCore.Relational/Query/RelationalSqlTranslatingExpressionVisitor.cs index 926821b9293..1dc0e3d85b6 100644 --- a/src/EFCore.Relational/Query/RelationalSqlTranslatingExpressionVisitor.cs +++ b/src/EFCore.Relational/Query/RelationalSqlTranslatingExpressionVisitor.cs @@ -1237,7 +1237,7 @@ private bool TryRewriteContainsEntity(Expression source, Expression item, [CA.No when sqlParameterExpression.Name.StartsWith(QueryCompilationContext.QueryParameterPrefix, StringComparison.Ordinal): var lambda = Expression.Lambda( Expression.Call( - _parameterListValueExtractor.MakeGenericMethod(entityType.ClrType!, property.ClrType.MakeNullable()), + _parameterListValueExtractor.MakeGenericMethod(entityType.ClrType, property.ClrType.MakeNullable()), QueryCompilationContext.QueryContextParameter, Expression.Constant(sqlParameterExpression.Name, typeof(string)), Expression.Constant(property, typeof(IProperty))), @@ -1537,7 +1537,7 @@ private EntityReferenceExpression(EntityReferenceExpression entityReferenceExpre public IEntityType EntityType { get; } public override Type Type - => EntityType.ClrType!; + => EntityType.ClrType; public override ExpressionType NodeType => ExpressionType.Extension; diff --git a/src/EFCore/ChangeTracking/Internal/InternalMixedEntityEntry.cs b/src/EFCore/ChangeTracking/Internal/InternalMixedEntityEntry.cs index b50cf49da5e..19f0042c7bf 100644 --- a/src/EFCore/ChangeTracking/Internal/InternalMixedEntityEntry.cs +++ b/src/EFCore/ChangeTracking/Internal/InternalMixedEntityEntry.cs @@ -159,11 +159,6 @@ public override bool AddToCollection(INavigationBase navigationBase, InternalEnt return base.AddToCollection(navigationBase, value, forMaterialization); } - if (navigationBase.TargetEntityType.ClrType == null) - { - return false; - } - var collection = GetOrCreateCollectionTyped(navigationBase); if (!collection.Contains(value.Entity)) { diff --git a/src/EFCore/Extensions/EntityTypeExtensions.cs b/src/EFCore/Extensions/EntityTypeExtensions.cs index b65be11cd93..d63174ae5a0 100644 --- a/src/EFCore/Extensions/EntityTypeExtensions.cs +++ b/src/EFCore/Extensions/EntityTypeExtensions.cs @@ -42,7 +42,7 @@ public static IEnumerable GetConcreteDerivedTypesInclusive([NotNull /// if the type is abstract, otherwise. [DebuggerStepThrough] public static bool IsAbstract([NotNull] this ITypeBase type) - => type.ClrType?.IsAbstract ?? false; + => type.ClrType.IsAbstract; /// /// Gets the root base type for a given entity type. @@ -382,8 +382,7 @@ public static string DisplayName([NotNull] this ITypeBase type) [DebuggerStepThrough] public static string ShortName([NotNull] this ITypeBase type) { - if (type.ClrType != null - && !type.HasSharedClrType) + if (!type.HasSharedClrType) { return type.ClrType.ShortDisplayName(); } diff --git a/src/EFCore/Infrastructure/ExpressionExtensions.cs b/src/EFCore/Infrastructure/ExpressionExtensions.cs index d8bf102d6ad..24a19b321f8 100644 --- a/src/EFCore/Infrastructure/ExpressionExtensions.cs +++ b/src/EFCore/Infrastructure/ExpressionExtensions.cs @@ -370,7 +370,7 @@ public static Expression CreateEFPropertyExpression( [NotNull] IPropertyBase property, bool makeNullable = true) // No shadow entities in runtime - => CreateEFPropertyExpression(target, property.DeclaringType.ClrType!, property.ClrType, property.Name, makeNullable); + => CreateEFPropertyExpression(target, property.DeclaringType.ClrType, property.ClrType, property.Name, makeNullable); private static Expression CreateEFPropertyExpression( Expression target, diff --git a/src/EFCore/Infrastructure/ModelValidator.cs b/src/EFCore/Infrastructure/ModelValidator.cs index 63a5992b596..3bf6c273ffb 100644 --- a/src/EFCore/Infrastructure/ModelValidator.cs +++ b/src/EFCore/Infrastructure/ModelValidator.cs @@ -390,7 +390,7 @@ protected virtual void ValidateNoShadowKeys( { Check.NotNull(model, nameof(model)); - foreach (IConventionEntityType entityType in model.GetEntityTypes().Where(t => t.ClrType != null)) + foreach (IConventionEntityType entityType in model.GetEntityTypes()) { foreach (var key in entityType.GetDeclaredKeys()) { @@ -549,7 +549,7 @@ private void ValidateClrInheritance( if (entityType.FindDeclaredOwnership() == null && entityType.BaseType != null) { - var baseClrType = entityType.ClrType?.BaseType; + var baseClrType = entityType.ClrType.BaseType; while (baseClrType != null) { var baseEntityType = model.FindEntityType(baseClrType); @@ -569,7 +569,7 @@ private void ValidateClrInheritance( } } - if (entityType.ClrType?.IsInstantiable() == false + if (!entityType.ClrType.IsInstantiable() && !entityType.GetDerivedTypes().Any()) { throw new InvalidOperationException( @@ -632,7 +632,7 @@ protected virtual void ValidateDiscriminatorValues([NotNull] IEntityType rootEnt foreach (var derivedType in derivedTypes) { - if (derivedType.ClrType?.IsInstantiable() != true) + if (!derivedType.ClrType.IsInstantiable()) { continue; } @@ -805,8 +805,8 @@ protected virtual void ValidateForeignKeys( } static bool ContainedInForeignKeyForAllConcreteTypes(IEntityType entityType, IProperty property) - => entityType.ClrType?.IsAbstract == true - && entityType.GetDerivedTypes().Where(t => t.ClrType?.IsAbstract != true) + => entityType.ClrType.IsAbstract + && entityType.GetDerivedTypes().Where(t => !t.ClrType.IsAbstract) .All(d => d.GetForeignKeys() .Any(fk => fk.Properties.Contains(property))); } @@ -1120,11 +1120,6 @@ protected virtual void LogShadowProperties( foreach (IConventionEntityType entityType in model.GetEntityTypes()) { - if (entityType.ClrType == null) - { - continue; - } - foreach (var property in entityType.GetDeclaredProperties()) { if (property.IsImplicitlyCreated()) diff --git a/src/EFCore/Metadata/Builders/DiscriminatorBuilder.cs b/src/EFCore/Metadata/Builders/DiscriminatorBuilder.cs index 432b6d92c6d..b5c4a9b74f7 100644 --- a/src/EFCore/Metadata/Builders/DiscriminatorBuilder.cs +++ b/src/EFCore/Metadata/Builders/DiscriminatorBuilder.cs @@ -124,9 +124,7 @@ public DiscriminatorBuilder([NotNull] IMutableEntityType entityType) var baseEntityTypeBuilder = EntityTypeBuilder; if (!baseEntityTypeBuilder.Metadata.IsAssignableFrom(entityTypeBuilder.Metadata) - && ((baseEntityTypeBuilder.Metadata.ClrType != null - && entityTypeBuilder.Metadata.ClrType != null - && !baseEntityTypeBuilder.Metadata.ClrType.IsAssignableFrom(entityTypeBuilder.Metadata.ClrType)) + && (!baseEntityTypeBuilder.Metadata.ClrType.IsAssignableFrom(entityTypeBuilder.Metadata.ClrType) || entityTypeBuilder.HasBaseType(baseEntityTypeBuilder.Metadata, configurationSource) == null)) { throw new InvalidOperationException( diff --git a/src/EFCore/Metadata/Builders/EntityTypeBuilder.cs b/src/EFCore/Metadata/Builders/EntityTypeBuilder.cs index 5a9b79c70e0..4fb77edc657 100644 --- a/src/EFCore/Metadata/Builders/EntityTypeBuilder.cs +++ b/src/EFCore/Metadata/Builders/EntityTypeBuilder.cs @@ -906,11 +906,6 @@ public virtual CollectionNavigationBuilder HasMany([NotNull] string navigationNa { Check.NotEmpty(navigationName, nameof(navigationName)); - if (Metadata.ClrType == null) - { - return HasMany(navigationName, (string?)null); - } - var memberType = Metadata.GetNavigationMemberInfo(navigationName).GetMemberType(); var elementType = memberType.TryGetElementType(typeof(IEnumerable<>)); diff --git a/src/EFCore/Metadata/Builders/OwnedNavigationBuilder.cs b/src/EFCore/Metadata/Builders/OwnedNavigationBuilder.cs index ee741be4fab..40709273feb 100644 --- a/src/EFCore/Metadata/Builders/OwnedNavigationBuilder.cs +++ b/src/EFCore/Metadata/Builders/OwnedNavigationBuilder.cs @@ -827,7 +827,7 @@ public virtual ReferenceNavigationBuilder HasOne([NotNull] string navigationName { Check.NotEmpty(navigationName, nameof(navigationName)); - return OwnedEntityType.ClrType == null || OwnedEntityType.ClrType == Model.DefaultPropertyBagType + return OwnedEntityType.ClrType == Model.DefaultPropertyBagType ? HasOne(navigationName, null) // Path only used by pre 3.0 snapshots : HasOne(OwnedEntityType.GetNavigationMemberInfo(navigationName).GetMemberType(), navigationName); } diff --git a/src/EFCore/Metadata/Conventions/BackingFieldConvention.cs b/src/EFCore/Metadata/Conventions/BackingFieldConvention.cs index 9a5e7d459dd..e003c949d61 100644 --- a/src/EFCore/Metadata/Conventions/BackingFieldConvention.cs +++ b/src/EFCore/Metadata/Conventions/BackingFieldConvention.cs @@ -166,7 +166,7 @@ private void DiscoverField(IConventionPropertyBaseBuilder conventionPropertyBase } else { - fields = entityType.GetRuntimeFields()!; + fields = entityType.GetRuntimeFields(); } var sortedFields = fields.OrderBy(p => p.Key, StringComparer.Ordinal).ToArray(); diff --git a/src/EFCore/Metadata/Conventions/EntityTypeAttributeConventionBase.cs b/src/EFCore/Metadata/Conventions/EntityTypeAttributeConventionBase.cs index 50afe796f4a..1ab32538967 100644 --- a/src/EFCore/Metadata/Conventions/EntityTypeAttributeConventionBase.cs +++ b/src/EFCore/Metadata/Conventions/EntityTypeAttributeConventionBase.cs @@ -46,8 +46,7 @@ public virtual void ProcessEntityTypeAdded( Check.NotNull(entityTypeBuilder, nameof(entityTypeBuilder)); var type = entityTypeBuilder.Metadata.ClrType; - if (type == null - || !Attribute.IsDefined(type, typeof(TAttribute), inherit: true)) + if (!Attribute.IsDefined(type, typeof(TAttribute), inherit: true)) { return; } diff --git a/src/EFCore/Metadata/Conventions/ForeignKeyAttributeConvention.cs b/src/EFCore/Metadata/Conventions/ForeignKeyAttributeConvention.cs index aa4f8639461..f3ecbb69954 100644 --- a/src/EFCore/Metadata/Conventions/ForeignKeyAttributeConvention.cs +++ b/src/EFCore/Metadata/Conventions/ForeignKeyAttributeConvention.cs @@ -297,7 +297,7 @@ var fkPropertiesOnDependentToPrincipal } private static ForeignKeyAttribute? GetForeignKeyAttribute(IConventionTypeBase entityType, string propertyName) - => entityType.GetRuntimeProperties()?.Values + => entityType.GetRuntimeProperties().Values .FirstOrDefault( p => string.Equals(p.GetSimpleMemberName(), propertyName, StringComparison.OrdinalIgnoreCase) && Attribute.IsDefined(p, typeof(ForeignKeyAttribute), inherit: true)) @@ -332,7 +332,7 @@ var fkPropertiesOnDependentToPrincipal MemberInfo? candidateProperty = null; foreach (var memberInfo in entityType.GetRuntimeProperties().Values.Cast() - .Concat(entityType.GetRuntimeFields()!.Values)) + .Concat(entityType.GetRuntimeFields().Values)) { if (entityType.Builder.IsIgnored(memberInfo.GetSimpleMemberName()) || !Attribute.IsDefined(memberInfo, typeof(ForeignKeyAttribute), inherit: true)) diff --git a/src/EFCore/Metadata/Conventions/IndexAttributeConvention.cs b/src/EFCore/Metadata/Conventions/IndexAttributeConvention.cs index 57f407605f4..3da304a40b7 100644 --- a/src/EFCore/Metadata/Conventions/IndexAttributeConvention.cs +++ b/src/EFCore/Metadata/Conventions/IndexAttributeConvention.cs @@ -69,11 +69,6 @@ private static void CheckIndexAttributesAndEnsureIndex( IConventionEntityType entityType, bool shouldThrow) { - if (entityType.ClrType == null) - { - return; - } - foreach (var indexAttribute in entityType.ClrType.GetCustomAttributes(true)) { diff --git a/src/EFCore/Metadata/Conventions/NavigationAttributeConventionBase.cs b/src/EFCore/Metadata/Conventions/NavigationAttributeConventionBase.cs index d11bff80b9a..276e9026308 100644 --- a/src/EFCore/Metadata/Conventions/NavigationAttributeConventionBase.cs +++ b/src/EFCore/Metadata/Conventions/NavigationAttributeConventionBase.cs @@ -124,10 +124,6 @@ public virtual void ProcessEntityTypeRemoved( IConventionContext context) { var type = entityType.ClrType; - if (type == null) - { - return; - } var navigations = GetNavigationsWithAttribute(entityType); if (navigations == null) @@ -268,7 +264,7 @@ public virtual void ProcessEntityTypeMemberIgnored( string name, IConventionContext context) { - var navigationPropertyInfo = entityTypeBuilder.Metadata.GetRuntimeProperties()?.Find(name); + var navigationPropertyInfo = entityTypeBuilder.Metadata.GetRuntimeProperties().Find(name); if (navigationPropertyInfo == null) { return; diff --git a/src/EFCore/Metadata/Conventions/NotMappedMemberAttributeConvention.cs b/src/EFCore/Metadata/Conventions/NotMappedMemberAttributeConvention.cs index 6a6b70dd9c6..0ad987c7f94 100644 --- a/src/EFCore/Metadata/Conventions/NotMappedMemberAttributeConvention.cs +++ b/src/EFCore/Metadata/Conventions/NotMappedMemberAttributeConvention.cs @@ -47,7 +47,7 @@ public virtual void ProcessEntityTypeAdded( var entityType = entityTypeBuilder.Metadata; var members = entityType.GetRuntimeProperties().Values.Cast() - .Concat(entityType.GetRuntimeFields()!.Values); + .Concat(entityType.GetRuntimeFields().Values); foreach (var member in members) { diff --git a/src/EFCore/Metadata/Conventions/RelationshipDiscoveryConvention.cs b/src/EFCore/Metadata/Conventions/RelationshipDiscoveryConvention.cs index 8394b783106..84659e676ed 100644 --- a/src/EFCore/Metadata/Conventions/RelationshipDiscoveryConvention.cs +++ b/src/EFCore/Metadata/Conventions/RelationshipDiscoveryConvention.cs @@ -200,7 +200,7 @@ private IReadOnlyList FindRelationshipCandidates(IConvent // The entity type might have been converted to a weak entity type var actualTargetEntityTypeBuilder = ((InternalEntityTypeBuilder)entityTypeBuilder).GetTargetEntityTypeBuilder( - relationshipCandidate.TargetTypeBuilder.Metadata.ClrType!, + relationshipCandidate.TargetTypeBuilder.Metadata.ClrType, relationshipCandidate.NavigationProperties.Single(), ConfigurationSource.Convention); @@ -391,8 +391,7 @@ private static bool IsCompatibleInverse( } var otherEntityType = existingInverse.TargetEntityType; - if (!entityType.ClrType! - .IsAssignableFrom(otherEntityType.ClrType)) + if (!entityType.ClrType.IsAssignableFrom(otherEntityType.ClrType)) { return false; } diff --git a/src/EFCore/Metadata/Internal/EntityType.cs b/src/EFCore/Metadata/Internal/EntityType.cs index 95cac334c3a..86726e0ec08 100644 --- a/src/EFCore/Metadata/Internal/EntityType.cs +++ b/src/EFCore/Metadata/Internal/EntityType.cs @@ -1476,7 +1476,7 @@ private Navigation AddNavigation(MemberIdentity navigationMember, ForeignKey for } else { - memberInfo = ClrType?.GetMembersInHierarchy(name).FirstOrDefault(); + memberInfo = ClrType.GetMembersInHierarchy(name).FirstOrDefault(); } if (memberInfo != null) @@ -1641,7 +1641,7 @@ public virtual IEnumerable GetNavigations() } else { - memberInfo = ClrType?.GetMembersInHierarchy(name).FirstOrDefault(); + memberInfo = ClrType.GetMembersInHierarchy(name).FirstOrDefault(); } if (memberInfo != null) @@ -1699,7 +1699,7 @@ public virtual IEnumerable GetNavigations() return memberInfo.GetMemberType(); } - var clashingMemberInfo = ClrType?.GetMembersInHierarchy(name).FirstOrDefault(); + var clashingMemberInfo = ClrType.GetMembersInHierarchy(name).FirstOrDefault(); if (clashingMemberInfo != null) { throw new InvalidOperationException( @@ -2279,7 +2279,7 @@ public virtual IEnumerable GetIndexes() return AddProperty( name, propertyType, - ClrType?.GetMembersInHierarchy(name).FirstOrDefault(), + ClrType.GetMembersInHierarchy(name).FirstOrDefault(), typeConfigurationSource, configurationSource); } @@ -2310,7 +2310,7 @@ public virtual IEnumerable GetIndexes() [NotNull] string name, ConfigurationSource configurationSource) { - var clrMember = ClrType?.GetMembersInHierarchy(name).FirstOrDefault(); + var clrMember = ClrType.GetMembersInHierarchy(name).FirstOrDefault(); if (clrMember == null) { throw new InvalidOperationException(CoreStrings.NoPropertyType(name, this.DisplayName())); @@ -2364,7 +2364,7 @@ public virtual IEnumerable GetIndexes() else { Check.DebugAssert( - ClrType?.GetMembersInHierarchy(name).FirstOrDefault() == null, + ClrType.GetMembersInHierarchy(name).FirstOrDefault() == null, "MemberInfo not supplied for non-shadow property"); } @@ -2915,7 +2915,7 @@ public virtual IEnumerable GetDeclaredServiceProperties() data.Add(seed); var type = rawSeed.GetType(); - if (ClrType?.IsAssignableFrom(type) == true) + if (ClrType.IsAssignableFrom(type) == true) { // non-anonymous type foreach (var propertyBase in properties.Values) @@ -3011,8 +3011,7 @@ public virtual void AddData([NotNull] IEnumerable data) foreach (var entity in data) { - if (ClrType != null - && ClrType != entity.GetType() + if (ClrType != entity.GetType() && ClrType.IsAssignableFrom(entity.GetType())) { throw new InvalidOperationException( @@ -3077,32 +3076,29 @@ public virtual ChangeTrackingStrategy GetChangeTrackingStrategy() /// public virtual string? CheckChangeTrackingStrategy(ChangeTrackingStrategy value, bool requireFullNotifications) { - if (ClrType != null) + if (requireFullNotifications) { - if (requireFullNotifications) + if (value != ChangeTrackingStrategy.ChangingAndChangedNotifications + && value != ChangeTrackingStrategy.ChangingAndChangedNotificationsWithOriginalValues) { - if (value != ChangeTrackingStrategy.ChangingAndChangedNotifications - && value != ChangeTrackingStrategy.ChangingAndChangedNotificationsWithOriginalValues) - { - return CoreStrings.FullChangeTrackingRequired( - this.DisplayName(), value, nameof(ChangeTrackingStrategy.ChangingAndChangedNotifications), - nameof(ChangeTrackingStrategy.ChangingAndChangedNotificationsWithOriginalValues)); - } + return CoreStrings.FullChangeTrackingRequired( + this.DisplayName(), value, nameof(ChangeTrackingStrategy.ChangingAndChangedNotifications), + nameof(ChangeTrackingStrategy.ChangingAndChangedNotificationsWithOriginalValues)); } - else + } + else + { + if (value != ChangeTrackingStrategy.Snapshot + && !typeof(INotifyPropertyChanged).IsAssignableFrom(ClrType)) { - if (value != ChangeTrackingStrategy.Snapshot - && !typeof(INotifyPropertyChanged).IsAssignableFrom(ClrType)) - { - return CoreStrings.ChangeTrackingInterfaceMissing(this.DisplayName(), value, nameof(INotifyPropertyChanged)); - } + return CoreStrings.ChangeTrackingInterfaceMissing(this.DisplayName(), value, nameof(INotifyPropertyChanged)); + } - if ((value == ChangeTrackingStrategy.ChangingAndChangedNotifications - || value == ChangeTrackingStrategy.ChangingAndChangedNotificationsWithOriginalValues) - && !typeof(INotifyPropertyChanging).IsAssignableFrom(ClrType)) - { - return CoreStrings.ChangeTrackingInterfaceMissing(this.DisplayName(), value, nameof(INotifyPropertyChanging)); - } + if ((value == ChangeTrackingStrategy.ChangingAndChangedNotifications + || value == ChangeTrackingStrategy.ChangingAndChangedNotificationsWithOriginalValues) + && !typeof(INotifyPropertyChanging).IsAssignableFrom(ClrType)) + { + return CoreStrings.ChangeTrackingInterfaceMissing(this.DisplayName(), value, nameof(INotifyPropertyChanging)); } } @@ -3978,7 +3974,7 @@ IEnumerable IConventionEntityType.GetIndexes() [DebuggerStepThrough] IMutableProperty IMutableEntityType.AddProperty(string name, Type propertyType, MemberInfo? memberInfo) => AddProperty( - name, propertyType, memberInfo ?? ClrType?.GetMembersInHierarchy(name).FirstOrDefault(), + name, propertyType, memberInfo ?? ClrType.GetMembersInHierarchy(name).FirstOrDefault(), ConfigurationSource.Explicit, ConfigurationSource.Explicit)!; /// @@ -3997,7 +3993,7 @@ IMutableProperty IMutableEntityType.AddProperty(string name, Type propertyType, => AddProperty( name, propertyType, - memberInfo ?? ClrType?.GetMembersInHierarchy(name).FirstOrDefault(), + memberInfo ?? ClrType.GetMembersInHierarchy(name).FirstOrDefault(), setTypeConfigurationSource ? fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention : (ConfigurationSource?)null, diff --git a/src/EFCore/Metadata/Internal/EntityTypeExtensions.cs b/src/EFCore/Metadata/Internal/EntityTypeExtensions.cs index 1a4544b10bd..4d71f4fd145 100644 --- a/src/EFCore/Metadata/Internal/EntityTypeExtensions.cs +++ b/src/EFCore/Metadata/Internal/EntityTypeExtensions.cs @@ -80,7 +80,7 @@ public static MemberInfo GetNavigationMemberInfo( } owner = ownership.PrincipalEntityType; - if (owner.ClrType?.IsAssignableFrom(targetType) == true) + if (owner.ClrType.IsAssignableFrom(targetType)) { return owner; } diff --git a/src/EFCore/Metadata/Internal/InternalEntityTypeBuilder.cs b/src/EFCore/Metadata/Internal/InternalEntityTypeBuilder.cs index 51337263242..d2fad8f4310 100644 --- a/src/EFCore/Metadata/Internal/InternalEntityTypeBuilder.cs +++ b/src/EFCore/Metadata/Internal/InternalEntityTypeBuilder.cs @@ -598,7 +598,7 @@ public virtual bool CanRemoveKey(ConfigurationSource configurationSource) if (memberInfo == null) { - memberInfo = Metadata.ClrType?.GetMembersInHierarchy(propertyName).FirstOrDefault(); + memberInfo = Metadata.ClrType.GetMembersInHierarchy(propertyName).FirstOrDefault(); } if (propertyType == null) @@ -4005,8 +4005,8 @@ public virtual IReadOnlyList CreateUniqueProperties( { propertyName = keyModifiedBaseName + (++index > 0 ? index.ToString(CultureInfo.InvariantCulture) : ""); if (!Metadata.FindPropertiesInHierarchy(propertyName).Any() - && clrProperties?.ContainsKey(propertyName) != true - && clrFields?.ContainsKey(propertyName) != true + && !clrProperties.ContainsKey(propertyName) + && !clrFields.ContainsKey(propertyName) && !IsIgnored(propertyName, ConfigurationSource.Convention)) { if (currentProperties == null) @@ -4449,11 +4449,6 @@ private bool CanAddDiscriminatorProperty( return false; } - if (Metadata.ClrType == null) - { - return true; - } - var memberInfo = Metadata.ClrType.GetMembersInHierarchy(name).FirstOrDefault(); if (memberInfo != null && propertyType != memberInfo.GetMemberType() diff --git a/src/EFCore/Metadata/Internal/InternalForeignKeyBuilder.cs b/src/EFCore/Metadata/Internal/InternalForeignKeyBuilder.cs index 64bd7adc2bb..1b449af5bf0 100644 --- a/src/EFCore/Metadata/Internal/InternalForeignKeyBuilder.cs +++ b/src/EFCore/Metadata/Internal/InternalForeignKeyBuilder.cs @@ -407,8 +407,7 @@ public InternalForeignKeyBuilder( { Metadata.DeclaringEntityType.RemoveIgnored(navigationToPrincipalName); - if (Metadata.DeclaringEntityType.ClrType != null - && Metadata.DeclaringEntityType.ClrType != Model.DefaultPropertyBagType + if (Metadata.DeclaringEntityType.ClrType != Model.DefaultPropertyBagType && navigationProperty == null) { throw new InvalidOperationException( @@ -433,8 +432,7 @@ public InternalForeignKeyBuilder( { Metadata.PrincipalEntityType.RemoveIgnored(navigationToDependentName); - if (Metadata.PrincipalEntityType.ClrType != null - && Metadata.PrincipalEntityType.ClrType != Model.DefaultPropertyBagType + if (Metadata.PrincipalEntityType.ClrType != Model.DefaultPropertyBagType && navigationProperty == null) { throw new InvalidOperationException( @@ -744,8 +742,6 @@ private bool CanSetNavigations( } if (navigationToPrincipalProperty != null - && dependentEntityType.ClrType != null - && principalEntityType.ClrType != null && !IsCompatible( navigationToPrincipalProperty, pointsToPrincipal: true, @@ -763,8 +759,6 @@ private bool CanSetNavigations( } if (navigationToDependentProperty != null - && dependentEntityType.ClrType != null - && principalEntityType.ClrType != null && !IsCompatible( navigationToDependentProperty, pointsToPrincipal: false, @@ -3649,9 +3643,8 @@ private static IReadOnlyList FindRelationships( } else { - dependentEntityType = Metadata.DeclaringEntityType.ClrType == null - ? ModelBuilder.Entity(Metadata.DeclaringEntityType.Name, configurationSource)!.Metadata - : ModelBuilder.Entity(Metadata.DeclaringEntityType.ClrType, configurationSource)!.Metadata; + dependentEntityType = + ModelBuilder.Entity(Metadata.DeclaringEntityType.ClrType, configurationSource)!.Metadata; } } } diff --git a/src/EFCore/Metadata/Internal/InternalModelBuilder.cs b/src/EFCore/Metadata/Internal/InternalModelBuilder.cs index 16d22b004f4..2de32bda4ce 100644 --- a/src/EFCore/Metadata/Internal/InternalModelBuilder.cs +++ b/src/EFCore/Metadata/Internal/InternalModelBuilder.cs @@ -185,7 +185,7 @@ public override InternalModelBuilder ModelBuilder { return configurationSource == ConfigurationSource.Explicit ? throw new InvalidOperationException( - CoreStrings.ClashingMismatchedSharedType(type.Name, entityType.ClrType?.ShortDisplayName())) + CoreStrings.ClashingMismatchedSharedType(type.Name, entityType.ClrType.ShortDisplayName())) : (InternalEntityTypeBuilder?)null; } } diff --git a/src/EFCore/Metadata/Internal/Model.cs b/src/EFCore/Metadata/Internal/Model.cs index 2947d235bf2..dd9e32c14b5 100644 --- a/src/EFCore/Metadata/Internal/Model.cs +++ b/src/EFCore/Metadata/Internal/Model.cs @@ -226,8 +226,7 @@ public virtual IEnumerable GetEntityTypes() _sharedTypes.Add(entityType.ClrType, (entityType.GetConfigurationSource(), types)); } } - else if (entityType.ClrType != null - && _sharedTypes.ContainsKey(entityType.ClrType)) + else if (_sharedTypes.ContainsKey(entityType.ClrType)) { throw new InvalidOperationException(CoreStrings.ClashingSharedType(entityType.DisplayName())); } @@ -326,8 +325,7 @@ private static void AssertCanRemove(EntityType entityType) EnsureReadonly(false); AssertCanRemove(entityType); - if (entityType.ClrType != null - && _sharedTypes.TryGetValue(entityType.ClrType, out var existingTypes)) + if (_sharedTypes.TryGetValue(entityType.ClrType, out var existingTypes)) { existingTypes.Types.Remove(entityType); } diff --git a/src/EFCore/Metadata/Internal/TypeBase.cs b/src/EFCore/Metadata/Internal/TypeBase.cs index 1ad0e442dab..e3ac7854798 100644 --- a/src/EFCore/Metadata/Internal/TypeBase.cs +++ b/src/EFCore/Metadata/Internal/TypeBase.cs @@ -24,7 +24,6 @@ namespace Microsoft.EntityFrameworkCore.Metadata.Internal /// public abstract class TypeBase : ConventionAnnotatable, IMutableTypeBase, IConventionTypeBase { - private readonly bool _hasSharedClrType; private ConfigurationSource _configurationSource; private readonly Dictionary _ignoredMembers @@ -49,7 +48,7 @@ protected TypeBase([NotNull] Type type, [NotNull] Model model, ConfigurationSour Model = model; _configurationSource = configurationSource; Name = model.GetDisplayName(type); - _hasSharedClrType = false; + HasSharedClrType = false; IsPropertyBag = type.IsPropertyBagType(); } @@ -69,7 +68,7 @@ protected TypeBase([NotNull] string name, [NotNull] Type type, [NotNull] Model m ClrType = type; Model = model; _configurationSource = configurationSource; - _hasSharedClrType = true; + HasSharedClrType = true; IsPropertyBag = type.IsPropertyBagType(); } @@ -111,20 +110,7 @@ protected TypeBase([NotNull] string name, [NotNull] Type type, [NotNull] Model m /// 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. /// - [CA.MemberNotNullWhen(true, nameof(ClrType))] - public virtual bool HasSharedClrType - { - [DebuggerStepThrough] get - { - if (_hasSharedClrType) - { - Check.DebugAssert(ClrType != null, $"{nameof(_hasSharedClrType)} is true but {nameof(ClrType)} is null"); - return true; - } - - return false; - } - } + public virtual bool HasSharedClrType { [DebuggerStepThrough] get; } /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -161,11 +147,6 @@ public virtual void UpdateConfigurationSource(ConfigurationSource configurationS /// public virtual IReadOnlyDictionary GetRuntimeProperties() { - if (ClrType == null) - { - return null!; - } - if (_runtimeProperties == null) { var runtimeProperties = new Dictionary(StringComparer.Ordinal); @@ -192,11 +173,6 @@ public virtual IReadOnlyDictionary GetRuntimeProperties() /// public virtual IReadOnlyDictionary GetRuntimeFields() { - if (ClrType == null) - { - return null!; - } - if (_runtimeFields == null) { var runtimeFields = new Dictionary(StringComparer.Ordinal); @@ -223,11 +199,6 @@ public virtual IReadOnlyDictionary GetRuntimeFields() /// public virtual PropertyInfo? FindIndexerPropertyInfo() { - if (ClrType == null) - { - return null; - } - if (!_indexerPropertyInitialized) { var indexerPropertyInfo = ClrType.FindIndexerProperty(); diff --git a/src/EFCore/Query/EntityShaperExpression.cs b/src/EFCore/Query/EntityShaperExpression.cs index 68716b5b0ce..7e3722c8121 100644 --- a/src/EFCore/Query/EntityShaperExpression.cs +++ b/src/EFCore/Query/EntityShaperExpression.cs @@ -260,8 +260,7 @@ public virtual EntityShaperExpression Update([NotNull] Expression valueBufferExp /// public override Type Type - // No shadow entities at runtime - => EntityType.ClrType!; + => EntityType.ClrType; /// public sealed override ExpressionType NodeType diff --git a/src/EFCore/Query/Internal/NavigationExpandingExpressionVisitor.ExpressionVisitors.cs b/src/EFCore/Query/Internal/NavigationExpandingExpressionVisitor.ExpressionVisitors.cs index 4912f2b5758..79266adefe3 100644 --- a/src/EFCore/Query/Internal/NavigationExpandingExpressionVisitor.ExpressionVisitors.cs +++ b/src/EFCore/Query/Internal/NavigationExpandingExpressionVisitor.ExpressionVisitors.cs @@ -715,7 +715,7 @@ private Expression ExpandIncludesHelper(Expression root, EntityReference entityR && entityReference.EntityType.IsAssignableFrom(navigationBase.DeclaringEntityType)) { converted = true; - convertedRoot = Expression.Convert(root, navigationBase.DeclaringEntityType.ClrType!); + convertedRoot = Expression.Convert(root, navigationBase.DeclaringEntityType.ClrType); } var included = navigationBase switch diff --git a/src/EFCore/Query/Internal/NavigationExpandingExpressionVisitor.Expressions.cs b/src/EFCore/Query/Internal/NavigationExpandingExpressionVisitor.Expressions.cs index 2d3ac7009a3..17bc7d728cc 100644 --- a/src/EFCore/Query/Internal/NavigationExpandingExpressionVisitor.Expressions.cs +++ b/src/EFCore/Query/Internal/NavigationExpandingExpressionVisitor.Expressions.cs @@ -36,8 +36,7 @@ public override ExpressionType NodeType => ExpressionType.Extension; public override Type Type - // No shadow entities at runtime - => EntityType.ClrType!; + => EntityType.ClrType; protected override Expression VisitChildren(ExpressionVisitor visitor) { diff --git a/src/EFCore/Query/Internal/NavigationExpandingExpressionVisitor.cs b/src/EFCore/Query/Internal/NavigationExpandingExpressionVisitor.cs index 698b01cd09e..d8c01bbd4cf 100644 --- a/src/EFCore/Query/Internal/NavigationExpandingExpressionVisitor.cs +++ b/src/EFCore/Query/Internal/NavigationExpandingExpressionVisitor.cs @@ -1427,7 +1427,7 @@ private Expression ApplyQueryFilter(IEntityType entityType, NavigationExpansionE // We need to do entity equality, but that requires a full method call on a query root to properly flow the // entity information through. Construct a MethodCall wrapper for the predicate with the proper query root. var filterWrapper = Expression.Call( - QueryableMethods.Where.MakeGenericMethod(rootEntityType.ClrType!), + QueryableMethods.Where.MakeGenericMethod(rootEntityType.ClrType), new QueryRootExpression(rootEntityType), filterPredicate); filterPredicate = filterWrapper.Arguments[1].UnwrapLambdaFromQuote(); diff --git a/src/EFCore/Query/QueryRootExpression.cs b/src/EFCore/Query/QueryRootExpression.cs index f8efa45dcc4..00fbf6201fb 100644 --- a/src/EFCore/Query/QueryRootExpression.cs +++ b/src/EFCore/Query/QueryRootExpression.cs @@ -36,7 +36,7 @@ public QueryRootExpression([NotNull] IAsyncQueryProvider asyncQueryProvider, [No QueryProvider = asyncQueryProvider; EntityType = entityType; - Type = typeof(IQueryable<>).MakeGenericType(entityType.ClrType!); + Type = typeof(IQueryable<>).MakeGenericType(entityType.ClrType); } /// @@ -49,7 +49,7 @@ public QueryRootExpression([NotNull] IEntityType entityType) EntityType = entityType; QueryProvider = null; - Type = typeof(IQueryable<>).MakeGenericType(entityType.ClrType!); + Type = typeof(IQueryable<>).MakeGenericType(entityType.ClrType); } /// diff --git a/src/EFCore/Query/ShapedQueryCompilingExpressionVisitor.cs b/src/EFCore/Query/ShapedQueryCompilingExpressionVisitor.cs index 5ccd52910d0..73adc8d3df2 100644 --- a/src/EFCore/Query/ShapedQueryCompilingExpressionVisitor.cs +++ b/src/EFCore/Query/ShapedQueryCompilingExpressionVisitor.cs @@ -399,12 +399,12 @@ private Expression ProcessEntityShaper(EntityShaperExpression entityShaperExpres "entityType" + _currentEntityIndex); variables.Add(concreteEntityTypeVariable); - var instanceVariable = Expression.Variable(entityType.ClrType!, "instance" + _currentEntityIndex); + var instanceVariable = Expression.Variable(entityType.ClrType, "instance" + _currentEntityIndex); variables.Add(instanceVariable); expressions.Add( Expression.Assign( instanceVariable, - Expression.Constant(null, entityType.ClrType!))); + Expression.Constant(null, entityType.ClrType))); if (_queryStateMananger && primaryKey != null) @@ -446,7 +446,7 @@ private Expression ProcessEntityShaper(EntityShaperExpression entityShaperExpres Expression.Assign( instanceVariable, Expression.Convert( Expression.MakeMemberAccess(entryVariable, _entityMemberInfo), - entityType.ClrType!))), + entityType.ClrType))), MaterializeEntity( entityShaperExpression, materializationContextVariable, concreteEntityTypeVariable, instanceVariable, entryVariable)))); @@ -500,8 +500,7 @@ private Expression MaterializeEntity( shadowValuesVariable, Expression.Constant(ValueBuffer.Empty))); - // No shadow entities at runtime - var returnType = entityType.ClrType!; + var returnType = entityType.ClrType; Expression materializationExpression; var valueBufferExpression = Expression.Call(materializationContextVariable, MaterializationContext.GetValueBufferMethod); var expressionContext = (returnType, materializationContextVariable, concreteEntityTypeVariable, shadowValuesVariable); From b67757d913bdbff97dde046e2f069ef0803e232f Mon Sep 17 00:00:00 2001 From: Shay Rojansky Date: Thu, 21 Jan 2021 20:52:34 +0100 Subject: [PATCH 6/8] Address other comments --- .../Metadata/IConventionDbFunction.cs | 5 ----- .../Metadata/IConventionSequence.cs | 5 ----- .../Builders/CollectionNavigationBuilder.cs | 9 ++++----- .../Builders/CollectionNavigationBuilder`.cs | 12 ++++++++++-- .../Metadata/Conventions/IConventionBatch.cs | 5 ++--- .../Metadata/Internal/InternalPropertyBuilder.cs | 15 ++++++++++----- 6 files changed, 26 insertions(+), 25 deletions(-) diff --git a/src/EFCore.Relational/Metadata/IConventionDbFunction.cs b/src/EFCore.Relational/Metadata/IConventionDbFunction.cs index 586fe1f31e9..3d44c873c4c 100644 --- a/src/EFCore.Relational/Metadata/IConventionDbFunction.cs +++ b/src/EFCore.Relational/Metadata/IConventionDbFunction.cs @@ -29,11 +29,6 @@ public interface IConventionDbFunction : IConventionAnnotatable, IDbFunction /// If the function has been removed from the model. new IConventionDbFunctionBuilder Builder { get; } - /// - /// Indicates whether this function is in a model, i.e. hasn't been removed from one. - /// - new bool IsInModel { get; } - /// /// Gets the configuration source for this function. /// diff --git a/src/EFCore.Relational/Metadata/IConventionSequence.cs b/src/EFCore.Relational/Metadata/IConventionSequence.cs index e1ed31e3681..cb93b138d8c 100644 --- a/src/EFCore.Relational/Metadata/IConventionSequence.cs +++ b/src/EFCore.Relational/Metadata/IConventionSequence.cs @@ -26,11 +26,6 @@ public interface IConventionSequence : ISequence, IConventionAnnotatable /// If the sequence has been removed from the model. new IConventionSequenceBuilder Builder { get; } - /// - /// Indicates whether this sequence is in a model, i.e. hasn't been removed from one. - /// - new bool IsInModel { get; } - /// /// Gets the configuration source for this . /// diff --git a/src/EFCore/Metadata/Builders/CollectionNavigationBuilder.cs b/src/EFCore/Metadata/Builders/CollectionNavigationBuilder.cs index 54032b04b71..13a4d8ffd58 100644 --- a/src/EFCore/Metadata/Builders/CollectionNavigationBuilder.cs +++ b/src/EFCore/Metadata/Builders/CollectionNavigationBuilder.cs @@ -225,13 +225,12 @@ private InternalForeignKeyBuilder WithOneBuilder(MemberIdentity reference) /// An object to further configure the relationship. public virtual CollectionCollectionBuilder WithMany([NotNull] string navigationName) { - if (Builder != null - && Builder.Metadata.PrincipalToDependent == null) + if (Builder?.Metadata.PrincipalToDependent == null) { throw new InvalidOperationException( CoreStrings.MissingInverseManyToManyNavigation( - Builder.Metadata.PrincipalEntityType.DisplayName(), - Builder.Metadata.DeclaringEntityType.DisplayName())); + Builder?.Metadata.PrincipalEntityType.DisplayName(), + Builder?.Metadata.DeclaringEntityType.DisplayName())); } var leftName = Builder?.Metadata.PrincipalToDependent!.Name; @@ -322,7 +321,7 @@ protected virtual IMutableSkipNavigation WithLeftManyNavigation([NotNull] string /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [EntityFrameworkInternal] - protected virtual IMutableSkipNavigation WithRightManyNavigation([NotNull] string navigationName, [CanBeNull] string? inverseName) + protected virtual IMutableSkipNavigation WithRightManyNavigation([NotNull] string navigationName, [NotNull] string inverseName) => WithRightManyNavigation(MemberIdentity.Create(navigationName), inverseName); /// diff --git a/src/EFCore/Metadata/Builders/CollectionNavigationBuilder`.cs b/src/EFCore/Metadata/Builders/CollectionNavigationBuilder`.cs index c6e318fb2c8..2b432ccb99a 100644 --- a/src/EFCore/Metadata/Builders/CollectionNavigationBuilder`.cs +++ b/src/EFCore/Metadata/Builders/CollectionNavigationBuilder`.cs @@ -94,9 +94,17 @@ public virtual ReferenceCollectionBuilder WithOne( /// The name of the collection navigation property on the other end of this relationship. /// /// An object to further configure the relationship. - public new virtual CollectionCollectionBuilder WithMany([NotNull] string navigationName) + public new virtual CollectionCollectionBuilder? WithMany([NotNull] string navigationName) { - var leftName = Builder?.Metadata.PrincipalToDependent!.Name; + if (Builder?.Metadata.PrincipalToDependent == null) + { + throw new InvalidOperationException( + CoreStrings.MissingInverseManyToManyNavigation( + Builder?.Metadata.PrincipalEntityType.DisplayName(), + Builder?.Metadata.DeclaringEntityType.DisplayName())); + } + + var leftName = Builder.Metadata.PrincipalToDependent.Name; var collectionCollectionBuilder = new CollectionCollectionBuilder( RelatedEntityType, diff --git a/src/EFCore/Metadata/Conventions/IConventionBatch.cs b/src/EFCore/Metadata/Conventions/IConventionBatch.cs index 6cdb6fa08c2..b5e7d99e242 100644 --- a/src/EFCore/Metadata/Conventions/IConventionBatch.cs +++ b/src/EFCore/Metadata/Conventions/IConventionBatch.cs @@ -25,10 +25,9 @@ public interface IConventionBatch : IDisposable /// /// The foreign key to track. /// - /// An object that will contain the reference to the new foreign key instance - /// if the given one was replaced by a convention. + /// An object that will contain the reference to the new foreign key instance if the given one was replaced by a convention. + /// Otherwise, returns the original foreign key. /// - // TODO-NULLABLE: does this ever refer null (as is implied by the comment?) IMetadataReference Track([NotNull] IConventionForeignKey foreignKey); } } diff --git a/src/EFCore/Metadata/Internal/InternalPropertyBuilder.cs b/src/EFCore/Metadata/Internal/InternalPropertyBuilder.cs index 747db2cf288..39508db1351 100644 --- a/src/EFCore/Metadata/Internal/InternalPropertyBuilder.cs +++ b/src/EFCore/Metadata/Internal/InternalPropertyBuilder.cs @@ -580,10 +580,10 @@ public virtual bool CanSetKeyValueComparer([CanBeNull] ValueComparer? comparer, /// 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. /// - public virtual InternalPropertyBuilder Attach([NotNull] InternalEntityTypeBuilder entityTypeBuilder) + public virtual InternalPropertyBuilder? Attach([NotNull] InternalEntityTypeBuilder entityTypeBuilder) { var newProperty = entityTypeBuilder.Metadata.FindProperty(Metadata.Name); - InternalPropertyBuilder newPropertyBuilder; + InternalPropertyBuilder? newPropertyBuilder; var configurationSource = Metadata.GetConfigurationSource(); var typeConfigurationSource = Metadata.GetTypeConfigurationSource(); if (newProperty != null @@ -605,10 +605,15 @@ public virtual InternalPropertyBuilder Attach([NotNull] InternalEntityTypeBuilde newPropertyBuilder = identifyingMemberInfo == null ? entityTypeBuilder.Property( - Metadata.ClrType, Metadata.Name, Metadata.GetTypeConfigurationSource(), configurationSource)! + Metadata.ClrType, Metadata.Name, Metadata.GetTypeConfigurationSource(), configurationSource) : (identifyingMemberInfo as PropertyInfo)?.IsIndexerProperty() == true - ? entityTypeBuilder.IndexerProperty(Metadata.ClrType, Metadata.Name, configurationSource)! - : entityTypeBuilder.Property(identifyingMemberInfo, configurationSource!)!; + ? entityTypeBuilder.IndexerProperty(Metadata.ClrType, Metadata.Name, configurationSource) + : entityTypeBuilder.Property(identifyingMemberInfo, configurationSource!); + + if (newPropertyBuilder is null) + { + return null; + } } if (newProperty == Metadata) From 63db9ae81ba4920e707e27aad0703c7c74b0a1f1 Mon Sep 17 00:00:00 2001 From: Shay Rojansky Date: Thu, 21 Jan 2021 21:22:45 +0100 Subject: [PATCH 7/8] And some more --- .../RelationalEntityTypeBuilderExtensions.cs | 5 ++++- .../Metadata/Builders/CollectionNavigationBuilder.cs | 9 +++++---- .../Builders/CollectionNavigationBuilder`.cs | 12 ++---------- .../Metadata/Builders/ReferenceReferenceBuilder.cs | 12 ++++++------ .../Metadata/Builders/ReferenceReferenceBuilder`.cs | 8 ++++---- 5 files changed, 21 insertions(+), 25 deletions(-) diff --git a/src/EFCore.Relational/Extensions/RelationalEntityTypeBuilderExtensions.cs b/src/EFCore.Relational/Extensions/RelationalEntityTypeBuilderExtensions.cs index d4229fcd57f..c6120b98439 100644 --- a/src/EFCore.Relational/Extensions/RelationalEntityTypeBuilderExtensions.cs +++ b/src/EFCore.Relational/Extensions/RelationalEntityTypeBuilderExtensions.cs @@ -894,7 +894,10 @@ public static OwnedNavigationBuilder ToFunction).MakeGenericType(entityType.ClrType), fromDataAnnotation); + if (name is null) + { + entityType.Model.Builder.HasDbFunction(name, typeof(IQueryable<>).MakeGenericType(entityType.ClrType), fromDataAnnotation); + } return entityTypeBuilder; } diff --git a/src/EFCore/Metadata/Builders/CollectionNavigationBuilder.cs b/src/EFCore/Metadata/Builders/CollectionNavigationBuilder.cs index 13a4d8ffd58..c42f8150abf 100644 --- a/src/EFCore/Metadata/Builders/CollectionNavigationBuilder.cs +++ b/src/EFCore/Metadata/Builders/CollectionNavigationBuilder.cs @@ -225,12 +225,13 @@ private InternalForeignKeyBuilder WithOneBuilder(MemberIdentity reference) /// An object to further configure the relationship. public virtual CollectionCollectionBuilder WithMany([NotNull] string navigationName) { - if (Builder?.Metadata.PrincipalToDependent == null) + if (Builder != null + && Builder.Metadata.PrincipalToDependent == null) { throw new InvalidOperationException( CoreStrings.MissingInverseManyToManyNavigation( - Builder?.Metadata.PrincipalEntityType.DisplayName(), - Builder?.Metadata.DeclaringEntityType.DisplayName())); + Builder.Metadata.PrincipalEntityType.DisplayName(), + Builder.Metadata.DeclaringEntityType.DisplayName())); } var leftName = Builder?.Metadata.PrincipalToDependent!.Name; @@ -239,7 +240,7 @@ public virtual CollectionCollectionBuilder WithMany([NotNull] string navigationN RelatedEntityType, DeclaringEntityType, WithLeftManyNavigation(navigationName), - WithRightManyNavigation(navigationName, leftName)); + WithRightManyNavigation(navigationName, leftName!)); Configure(collectionCollectionBuilder); diff --git a/src/EFCore/Metadata/Builders/CollectionNavigationBuilder`.cs b/src/EFCore/Metadata/Builders/CollectionNavigationBuilder`.cs index 2b432ccb99a..b0544c94372 100644 --- a/src/EFCore/Metadata/Builders/CollectionNavigationBuilder`.cs +++ b/src/EFCore/Metadata/Builders/CollectionNavigationBuilder`.cs @@ -96,21 +96,13 @@ public virtual ReferenceCollectionBuilder WithOne( /// An object to further configure the relationship. public new virtual CollectionCollectionBuilder? WithMany([NotNull] string navigationName) { - if (Builder?.Metadata.PrincipalToDependent == null) - { - throw new InvalidOperationException( - CoreStrings.MissingInverseManyToManyNavigation( - Builder?.Metadata.PrincipalEntityType.DisplayName(), - Builder?.Metadata.DeclaringEntityType.DisplayName())); - } - - var leftName = Builder.Metadata.PrincipalToDependent.Name; + var leftName = Builder?.Metadata.PrincipalToDependent!.Name; var collectionCollectionBuilder = new CollectionCollectionBuilder( RelatedEntityType, DeclaringEntityType, WithLeftManyNavigation(navigationName), - WithRightManyNavigation(navigationName, leftName)); + WithRightManyNavigation(navigationName, leftName!)); Configure(collectionCollectionBuilder); diff --git a/src/EFCore/Metadata/Builders/ReferenceReferenceBuilder.cs b/src/EFCore/Metadata/Builders/ReferenceReferenceBuilder.cs index 36b9113426e..390af61a808 100644 --- a/src/EFCore/Metadata/Builders/ReferenceReferenceBuilder.cs +++ b/src/EFCore/Metadata/Builders/ReferenceReferenceBuilder.cs @@ -104,7 +104,7 @@ public virtual ReferenceReferenceBuilder HasForeignKey( [NotNull] params string[] foreignKeyPropertyNames) => new( HasForeignKeyBuilder( - ResolveEntityType(Check.NotNull(dependentEntityTypeName, nameof(dependentEntityTypeName))), + ResolveEntityType(Check.NotNull(dependentEntityTypeName, nameof(dependentEntityTypeName)))!, dependentEntityTypeName, Check.NotNull(foreignKeyPropertyNames, nameof(foreignKeyPropertyNames))), this, @@ -142,7 +142,7 @@ public virtual ReferenceReferenceBuilder HasForeignKey( [NotNull] params string[] foreignKeyPropertyNames) => new( HasForeignKeyBuilder( - ResolveEntityType(Check.NotNull(dependentEntityType, nameof(dependentEntityType))), + ResolveEntityType(Check.NotNull(dependentEntityType, nameof(dependentEntityType)))!, dependentEntityType.ShortDisplayName(), Check.NotNull(foreignKeyPropertyNames, nameof(foreignKeyPropertyNames))), this, @@ -157,7 +157,7 @@ public virtual ReferenceReferenceBuilder HasForeignKey( /// [EntityFrameworkInternal] protected virtual InternalForeignKeyBuilder HasForeignKeyBuilder( - [CanBeNull] EntityType? dependentEntityType, + [NotNull] EntityType dependentEntityType, [NotNull] string dependentEntityTypeName, [NotNull] IReadOnlyList foreignKeyPropertyNames) => HasForeignKeyBuilder( @@ -223,7 +223,7 @@ public virtual ReferenceReferenceBuilder HasPrincipalKey( [NotNull] params string[] keyPropertyNames) => new( HasPrincipalKeyBuilder( - ResolveEntityType(Check.NotEmpty(principalEntityTypeName, nameof(principalEntityTypeName))), + ResolveEntityType(Check.NotEmpty(principalEntityTypeName, nameof(principalEntityTypeName)))!, principalEntityTypeName, Check.NotNull(keyPropertyNames, nameof(keyPropertyNames))), this, @@ -252,7 +252,7 @@ public virtual ReferenceReferenceBuilder HasPrincipalKey( [NotNull] params string[] keyPropertyNames) => new( HasPrincipalKeyBuilder( - ResolveEntityType(Check.NotNull(principalEntityType, nameof(principalEntityType))), + ResolveEntityType(Check.NotNull(principalEntityType, nameof(principalEntityType)))!, principalEntityType.ShortDisplayName(), Check.NotNull(keyPropertyNames, nameof(keyPropertyNames))), this, @@ -267,7 +267,7 @@ public virtual ReferenceReferenceBuilder HasPrincipalKey( /// [EntityFrameworkInternal] protected virtual InternalForeignKeyBuilder HasPrincipalKeyBuilder( - [CanBeNull] EntityType? principalEntityType, + [NotNull] EntityType principalEntityType, [NotNull] string principalEntityTypeName, [NotNull] IReadOnlyList foreignKeyPropertyNames) => HasPrincipalKeyBuilder( diff --git a/src/EFCore/Metadata/Builders/ReferenceReferenceBuilder`.cs b/src/EFCore/Metadata/Builders/ReferenceReferenceBuilder`.cs index 0056f7e8208..1379b85e44d 100644 --- a/src/EFCore/Metadata/Builders/ReferenceReferenceBuilder`.cs +++ b/src/EFCore/Metadata/Builders/ReferenceReferenceBuilder`.cs @@ -98,7 +98,7 @@ protected ReferenceReferenceBuilder( [NotNull] params string[] foreignKeyPropertyNames) => new( HasForeignKeyBuilder( - ResolveEntityType(Check.NotNull(dependentEntityTypeName, nameof(dependentEntityTypeName))), + ResolveEntityType(Check.NotNull(dependentEntityTypeName, nameof(dependentEntityTypeName)))!, dependentEntityTypeName, Check.NotNull(foreignKeyPropertyNames, nameof(foreignKeyPropertyNames))), this, @@ -136,7 +136,7 @@ protected ReferenceReferenceBuilder( [NotNull] params string[] foreignKeyPropertyNames) => new( HasForeignKeyBuilder( - ResolveEntityType(Check.NotNull(dependentEntityType, nameof(dependentEntityType))), + ResolveEntityType(Check.NotNull(dependentEntityType, nameof(dependentEntityType)))!, dependentEntityType.ShortDisplayName(), Check.NotNull(foreignKeyPropertyNames, nameof(foreignKeyPropertyNames))), this, @@ -236,7 +236,7 @@ public virtual ReferenceReferenceBuilder HasForeignKey< [NotNull] params string[] keyPropertyNames) => new( HasPrincipalKeyBuilder( - ResolveEntityType(Check.NotEmpty(principalEntityTypeName, nameof(principalEntityTypeName))), + ResolveEntityType(Check.NotEmpty(principalEntityTypeName, nameof(principalEntityTypeName)))!, principalEntityTypeName, Check.NotNull(keyPropertyNames, nameof(keyPropertyNames))), this, @@ -260,7 +260,7 @@ public virtual ReferenceReferenceBuilder HasForeignKey< [NotNull] params string[] keyPropertyNames) => new( HasPrincipalKeyBuilder( - ResolveEntityType(Check.NotNull(principalEntityType, nameof(principalEntityType))), + ResolveEntityType(Check.NotNull(principalEntityType, nameof(principalEntityType)))!, principalEntityType.ShortDisplayName(), Check.NotNull(keyPropertyNames, nameof(keyPropertyNames))), this, From 17135dd4feb27869c3a421e01c406c1909654f53 Mon Sep 17 00:00:00 2001 From: Shay Rojansky Date: Thu, 21 Jan 2021 21:24:09 +0100 Subject: [PATCH 8/8] And another --- src/EFCore/Metadata/Builders/CollectionNavigationBuilder`.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/EFCore/Metadata/Builders/CollectionNavigationBuilder`.cs b/src/EFCore/Metadata/Builders/CollectionNavigationBuilder`.cs index b0544c94372..eb74c1015ea 100644 --- a/src/EFCore/Metadata/Builders/CollectionNavigationBuilder`.cs +++ b/src/EFCore/Metadata/Builders/CollectionNavigationBuilder`.cs @@ -94,7 +94,7 @@ public virtual ReferenceCollectionBuilder WithOne( /// The name of the collection navigation property on the other end of this relationship. /// /// An object to further configure the relationship. - public new virtual CollectionCollectionBuilder? WithMany([NotNull] string navigationName) + public new virtual CollectionCollectionBuilder WithMany([NotNull] string navigationName) { var leftName = Builder?.Metadata.PrincipalToDependent!.Name; var collectionCollectionBuilder =