diff --git a/src/EFCore.Cosmos/Metadata/Internal/CosmosAnnotationNames.cs b/src/EFCore.Cosmos/Metadata/Internal/CosmosAnnotationNames.cs index 85beca4067c..c0b2328f4d5 100644 --- a/src/EFCore.Cosmos/Metadata/Internal/CosmosAnnotationNames.cs +++ b/src/EFCore.Cosmos/Metadata/Internal/CosmosAnnotationNames.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.Cosmos.Metadata.Internal { /// diff --git a/src/EFCore.Cosmos/Metadata/Internal/CosmosEntityTypeExtensions.cs b/src/EFCore.Cosmos/Metadata/Internal/CosmosEntityTypeExtensions.cs index 348c0f3bddf..e901135d272 100644 --- a/src/EFCore.Cosmos/Metadata/Internal/CosmosEntityTypeExtensions.cs +++ b/src/EFCore.Cosmos/Metadata/Internal/CosmosEntityTypeExtensions.cs @@ -4,6 +4,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Metadata; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Cosmos.Metadata.Internal { /// diff --git a/src/EFCore.Cosmos/Metadata/Internal/CosmosNavigationExtensions.cs b/src/EFCore.Cosmos/Metadata/Internal/CosmosNavigationExtensions.cs index 6448b9a1c0d..18f8de69351 100644 --- a/src/EFCore.Cosmos/Metadata/Internal/CosmosNavigationExtensions.cs +++ b/src/EFCore.Cosmos/Metadata/Internal/CosmosNavigationExtensions.cs @@ -4,6 +4,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Metadata; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Cosmos.Metadata.Internal { /// diff --git a/src/EFCore.Cosmos/Metadata/Internal/CosmosPropertyExtensions.cs b/src/EFCore.Cosmos/Metadata/Internal/CosmosPropertyExtensions.cs index 3462afb7b6c..c6c696422d8 100644 --- a/src/EFCore.Cosmos/Metadata/Internal/CosmosPropertyExtensions.cs +++ b/src/EFCore.Cosmos/Metadata/Internal/CosmosPropertyExtensions.cs @@ -5,6 +5,8 @@ using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Cosmos.Metadata.Internal { /// @@ -27,11 +29,11 @@ public static bool IsOrdinalKeyProperty([NotNull] this IProperty property) property.DeclaringEntityType.IsOwned(), $"Expected {property.DeclaringEntityType.DisplayName()} to be owned."); Check.DebugAssert(property.GetJsonPropertyName().Length == 0, $"Expected {property.Name} to be non-persisted."); - return property.IsPrimaryKey() + return property.FindContainingPrimaryKey() is IKey key + && key.Properties.Count > 1 && !property.IsForeignKey() && property.ClrType == typeof(int) - && property.ValueGenerated == ValueGenerated.OnAdd - && property.DeclaringEntityType.FindPrimaryKey().Properties.Count > 1; + && property.ValueGenerated == ValueGenerated.OnAdd; } } } diff --git a/src/EFCore.InMemory/Query/Internal/InMemoryExpressionTranslatingExpressionVisitor.cs b/src/EFCore.InMemory/Query/Internal/InMemoryExpressionTranslatingExpressionVisitor.cs index 97274768353..b7af450dcd2 100644 --- a/src/EFCore.InMemory/Query/Internal/InMemoryExpressionTranslatingExpressionVisitor.cs +++ b/src/EFCore.InMemory/Query/Internal/InMemoryExpressionTranslatingExpressionVisitor.cs @@ -1117,7 +1117,7 @@ protected override Expression VisitUnary(UnaryExpression unaryExpression) var property = member.MemberInfo != null ? entityType.FindProperty(member.MemberInfo) - : entityType.FindProperty(member.Name); + : entityType.FindProperty(member.Name!); if (property != null) { @@ -1424,7 +1424,10 @@ private Expression CreatePropertyAccessExpression(Expression target, IProperty p { case ConstantExpression constantExpression: return Expression.Constant( - property.GetGetter().GetClrValue(constantExpression.Value), property.ClrType.MakeNullable()); + constantExpression.Value is null + ? null + : property.GetGetter().GetClrValue(constantExpression.Value), + property.ClrType.MakeNullable()); case MethodCallExpression methodCallExpression when methodCallExpression.Method.IsGenericMethod diff --git a/src/EFCore.InMemory/Query/Internal/InMemoryQueryableMethodTranslatingExpressionVisitor.cs b/src/EFCore.InMemory/Query/Internal/InMemoryQueryableMethodTranslatingExpressionVisitor.cs index 0d0f8d92f6a..cdb74e950bd 100644 --- a/src/EFCore.InMemory/Query/Internal/InMemoryQueryableMethodTranslatingExpressionVisitor.cs +++ b/src/EFCore.InMemory/Query/Internal/InMemoryQueryableMethodTranslatingExpressionVisitor.cs @@ -1390,7 +1390,7 @@ protected override Expression VisitExtension(Expression extensionExpression) var navigation = member.MemberInfo != null ? entityType.FindNavigation(member.MemberInfo) - : entityType.FindNavigation(member.Name); + : entityType.FindNavigation(member.Name!); if (navigation == null) { diff --git a/src/EFCore.InMemory/Query/Internal/InMemoryShapedQueryCompilingExpressionVisitor.CustomShaperCompilingExpressionVisitor.cs b/src/EFCore.InMemory/Query/Internal/InMemoryShapedQueryCompilingExpressionVisitor.CustomShaperCompilingExpressionVisitor.cs index 2c999dd5c37..009e1250062 100644 --- a/src/EFCore.InMemory/Query/Internal/InMemoryShapedQueryCompilingExpressionVisitor.CustomShaperCompilingExpressionVisitor.cs +++ b/src/EFCore.InMemory/Query/Internal/InMemoryShapedQueryCompilingExpressionVisitor.CustomShaperCompilingExpressionVisitor.cs @@ -225,7 +225,7 @@ private static LambdaExpression GenerateFixup( Type entityType, Type relatedEntityType, INavigationBase navigation, - INavigationBase inverseNavigation) + INavigationBase? inverseNavigation) { var entityParameter = Expression.Parameter(entityType); var relatedEntityParameter = Expression.Parameter(relatedEntityType); diff --git a/src/EFCore.Relational/Extensions/RelationalModelExtensions.cs b/src/EFCore.Relational/Extensions/RelationalModelExtensions.cs index aa07995f82f..45f0fa3696b 100644 --- a/src/EFCore.Relational/Extensions/RelationalModelExtensions.cs +++ b/src/EFCore.Relational/Extensions/RelationalModelExtensions.cs @@ -12,6 +12,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Internal; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + // ReSharper disable once CheckNamespace namespace Microsoft.EntityFrameworkCore { @@ -86,15 +88,15 @@ public static string ToDebugString( /// /// The model to get the default schema for. /// The default schema. - public static string GetDefaultSchema([NotNull] this IModel model) - => (string)Check.NotNull(model, nameof(model))[RelationalAnnotationNames.DefaultSchema]; + public static string? GetDefaultSchema([NotNull] this IModel model) + => (string?)Check.NotNull(model, nameof(model))[RelationalAnnotationNames.DefaultSchema]; /// /// Sets the default schema. /// /// The model to set the default schema for. /// The value to set. - public static void SetDefaultSchema([NotNull] this IMutableModel model, [CanBeNull] string value) + public static void SetDefaultSchema([NotNull] this IMutableModel model, [CanBeNull] string? value) => model.SetOrRemoveAnnotation( RelationalAnnotationNames.DefaultSchema, Check.NullButNotEmpty(value, nameof(value))); @@ -106,9 +108,9 @@ public static void SetDefaultSchema([NotNull] this IMutableModel model, [CanBeNu /// The value to set. /// Indicates whether the configuration was specified using a data annotation. /// The configured schema. - public static string SetDefaultSchema( + public static string? SetDefaultSchema( [NotNull] this IConventionModel model, - [CanBeNull] string value, + [CanBeNull] string? value, bool fromDataAnnotation = false) { model.SetOrRemoveAnnotation( @@ -132,7 +134,7 @@ public static string SetDefaultSchema( /// The database model. public static IRelationalModel GetRelationalModel([NotNull] this IModel model) { - var databaseModel = (IRelationalModel)model[RelationalAnnotationNames.RelationalModel]; + var databaseModel = (IRelationalModel?)model[RelationalAnnotationNames.RelationalModel]; if (databaseModel == null) { throw new InvalidOperationException(RelationalStrings.DatabaseModelMissing); @@ -189,7 +191,7 @@ public static void SetMaxIdentifierLength([NotNull] this IMutableModel model, in /// The or if no sequence with the given name in /// the given schema was found. /// - public static ISequence FindSequence([NotNull] this IModel model, [NotNull] string name, [CanBeNull] string schema = null) + public static ISequence? FindSequence([NotNull] this IModel model, [NotNull] string name, [CanBeNull] string? schema = null) => Sequence.FindSequence( Check.NotNull(model, nameof(model)), Check.NotEmpty(name, nameof(name)), Check.NullButNotEmpty(schema, nameof(schema))); @@ -203,11 +205,11 @@ public static ISequence FindSequence([NotNull] this IModel model, [NotNull] stri /// The or if no sequence with the given name in /// the given schema was found. /// - public static IMutableSequence FindSequence( + public static IMutableSequence? FindSequence( [NotNull] this IMutableModel model, [NotNull] string name, - [CanBeNull] string schema = null) - => (IMutableSequence)((IModel)model).FindSequence(name, schema); + [CanBeNull] string? schema = null) + => (IMutableSequence?)((IModel)model).FindSequence(name, schema); /// /// Finds an with the given name. @@ -219,11 +221,11 @@ public static IMutableSequence FindSequence( /// The or if no sequence with the given name in /// the given schema was found. /// - public static IConventionSequence FindSequence( + public static IConventionSequence? FindSequence( [NotNull] this IConventionModel model, [NotNull] string name, - [CanBeNull] string schema = null) - => (IConventionSequence)((IModel)model).FindSequence(name, schema); + [CanBeNull] string? schema = null) + => (IConventionSequence?)((IModel)model).FindSequence(name, schema); /// /// Either returns the existing with the given name in the given schema @@ -233,10 +235,10 @@ public static IConventionSequence FindSequence( /// 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) + [CanBeNull] string? schema = null) => Sequence.AddSequence(model, name, schema, ConfigurationSource.Explicit); /// @@ -248,10 +250,10 @@ public static IMutableSequence AddSequence( /// The schema name, or to use the default schema. /// Indicates whether the configuration was specified using a data annotation. /// The sequence. - public static IConventionSequence AddSequence( + public static IConventionSequence? AddSequence( [NotNull] this IConventionModel model, [NotNull] string name, - [CanBeNull] string schema = null, + [CanBeNull] string? schema = null, bool fromDataAnnotation = false) => Sequence.AddSequence( (IMutableModel)model, name, schema, @@ -267,10 +269,10 @@ public static IConventionSequence AddSequence( /// The removed or if no sequence with the given name in /// the given schema was found. /// - public static IMutableSequence RemoveSequence( + public static IMutableSequence? RemoveSequence( [NotNull] this IMutableModel model, [NotNull] string name, - [CanBeNull] string schema = null) + [CanBeNull] string? schema = null) => Sequence.RemoveSequence(Check.NotNull(model, nameof(model)), name, schema); /// @@ -283,10 +285,10 @@ public static IMutableSequence RemoveSequence( /// The removed or if no sequence with the given name in /// the given schema was found. /// - public static IConventionSequence RemoveSequence( + public static IConventionSequence? RemoveSequence( [NotNull] this IConventionModel model, [NotNull] string name, - [CanBeNull] string schema = null) + [CanBeNull] string? schema = null) => Sequence.RemoveSequence((IMutableModel)Check.NotNull(model, nameof(model)), name, schema); /// @@ -316,7 +318,7 @@ public static IEnumerable GetSequences([NotNull] this IConv /// The model to find the function in. /// The for the method that is mapped to the function. /// The or if the method is not mapped. - public static IDbFunction FindDbFunction([NotNull] this IModel model, [NotNull] MethodInfo method) + public static IDbFunction? FindDbFunction([NotNull] this IModel model, [NotNull] MethodInfo method) => DbFunction.FindDbFunction( Check.NotNull(model, nameof(model)), Check.NotNull(method, nameof(method))); @@ -327,8 +329,8 @@ public static IDbFunction FindDbFunction([NotNull] this IModel model, [NotNull] /// The model to find the function in. /// The for the method that is mapped to the function. /// The or if the method is not mapped. - public static IMutableDbFunction FindDbFunction([NotNull] this IMutableModel model, [NotNull] MethodInfo method) - => (IMutableDbFunction)((IModel)model).FindDbFunction(method); + public static IMutableDbFunction? FindDbFunction([NotNull] this IMutableModel model, [NotNull] MethodInfo method) + => (IMutableDbFunction?)((IModel)model).FindDbFunction(method); /// /// Finds a that is mapped to the method represented by the given . @@ -336,8 +338,8 @@ public static IMutableDbFunction FindDbFunction([NotNull] this IMutableModel mod /// The model to find the function in. /// The for the method that is mapped to the function. /// The or if the method is not mapped. - public static IConventionDbFunction FindDbFunction([NotNull] this IConventionModel model, [NotNull] MethodInfo method) - => (IConventionDbFunction)((IModel)model).FindDbFunction(method); + public static IConventionDbFunction? FindDbFunction([NotNull] this IConventionModel model, [NotNull] MethodInfo method) + => (IConventionDbFunction?)((IModel)model).FindDbFunction(method); /// /// Finds an that is mapped to the method represented by the given name. @@ -345,7 +347,7 @@ public static IConventionDbFunction FindDbFunction([NotNull] this IConventionMod /// The model to find the function in. /// The model name of the function. /// The or if the method is not mapped. - public static IDbFunction FindDbFunction([NotNull] this IModel model, [NotNull] string name) + public static IDbFunction? FindDbFunction([NotNull] this IModel model, [NotNull] string name) => DbFunction.FindDbFunction( Check.NotNull(model, nameof(model)), Check.NotNull(name, nameof(name))); @@ -356,8 +358,8 @@ public static IDbFunction FindDbFunction([NotNull] this IModel model, [NotNull] /// The model to find the function in. /// The model name of the function. /// The or if the method is not mapped. - public static IMutableDbFunction FindDbFunction([NotNull] this IMutableModel model, [NotNull] string name) - => (IMutableDbFunction)((IModel)model).FindDbFunction(name); + public static IMutableDbFunction? FindDbFunction([NotNull] this IMutableModel model, [NotNull] string name) + => (IMutableDbFunction?)((IModel)model).FindDbFunction(name); /// /// Finds an that is mapped to the method represented by the given name. @@ -365,8 +367,8 @@ public static IMutableDbFunction FindDbFunction([NotNull] this IMutableModel mod /// The model to find the function in. /// The model name of the function. /// The or if the method is not mapped. - public static IConventionDbFunction FindDbFunction([NotNull] this IConventionModel model, [NotNull] string name) - => (IConventionDbFunction)((IModel)model).FindDbFunction(name); + public static IConventionDbFunction? FindDbFunction([NotNull] this IConventionModel model, [NotNull] string name) + => (IConventionDbFunction?)((IModel)model).FindDbFunction(name); /// /// Creates an mapped to the given method. @@ -374,7 +376,7 @@ public static IConventionDbFunction FindDbFunction([NotNull] this IConventionMod /// 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); @@ -385,7 +387,7 @@ public static IMutableDbFunction AddDbFunction([NotNull] this IMutableModel mode /// 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) @@ -400,7 +402,7 @@ public static IConventionDbFunction AddDbFunction( /// 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) @@ -415,7 +417,7 @@ public static IMutableDbFunction AddDbFunction( /// 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, @@ -433,7 +435,7 @@ public static IConventionDbFunction AddDbFunction( /// The model to find the function in. /// The for the method that is mapped to the function. /// The removed or if the method is not mapped. - public static IMutableDbFunction RemoveDbFunction([NotNull] this IMutableModel model, [NotNull] MethodInfo method) + public static IMutableDbFunction? RemoveDbFunction([NotNull] this IMutableModel model, [NotNull] MethodInfo method) => DbFunction.RemoveDbFunction( Check.NotNull(model, nameof(model)), Check.NotNull(method, nameof(method))); @@ -445,8 +447,8 @@ public static IMutableDbFunction RemoveDbFunction([NotNull] this IMutableModel m /// The model to find the function in. /// The for the method that is mapped to the function. /// The removed or if the method is not mapped. - public static IConventionDbFunction RemoveDbFunction([NotNull] this IConventionModel model, [NotNull] MethodInfo method) - => (IConventionDbFunction)((IMutableModel)model).RemoveDbFunction(method); + public static IConventionDbFunction? RemoveDbFunction([NotNull] this IConventionModel model, [NotNull] MethodInfo method) + => (IConventionDbFunction?)((IMutableModel)model).RemoveDbFunction(method); /// /// Removes the that is mapped to the method represented by the given @@ -455,7 +457,7 @@ public static IConventionDbFunction RemoveDbFunction([NotNull] this IConventionM /// The model to find the function in. /// The model name of the function. /// The removed or if the method is not mapped. - public static IMutableDbFunction RemoveDbFunction([NotNull] this IMutableModel model, [NotNull] string name) + public static IMutableDbFunction? RemoveDbFunction([NotNull] this IMutableModel model, [NotNull] string name) => DbFunction.RemoveDbFunction( Check.NotNull(model, nameof(model)), Check.NotNull(name, nameof(name))); @@ -467,8 +469,8 @@ public static IMutableDbFunction RemoveDbFunction([NotNull] this IMutableModel m /// The model to find the function in. /// The model name of the function. /// The removed or if the method is not mapped. - public static IConventionDbFunction RemoveDbFunction([NotNull] this IConventionModel model, [NotNull] string name) - => (IConventionDbFunction)((IMutableModel)model).RemoveDbFunction(name); + public static IConventionDbFunction? RemoveDbFunction([NotNull] this IConventionModel model, [NotNull] string name) + => (IConventionDbFunction?)((IMutableModel)model).RemoveDbFunction(name); /// /// Returns all s contained in the model. @@ -496,15 +498,15 @@ public static IEnumerable GetDbFunctions([NotNull] this I /// /// The model to get the collation for. /// The collation. - public static string GetCollation([NotNull] this IModel model) - => (string)model[RelationalAnnotationNames.Collation]; + public static string? GetCollation([NotNull] this IModel model) + => (string?)model[RelationalAnnotationNames.Collation]; /// /// Sets the database collation. /// /// The model to set the collation for. /// The value to set. - public static void SetCollation([NotNull] this IMutableModel model, [CanBeNull] string value) + public static void SetCollation([NotNull] this IMutableModel model, [CanBeNull] string? value) => model.SetOrRemoveAnnotation( RelationalAnnotationNames.Collation, Check.NullButNotEmpty(value, nameof(value))); @@ -516,7 +518,7 @@ public static void SetCollation([NotNull] this IMutableModel model, [CanBeNull] /// The value to set. /// Indicates whether the configuration was specified using a data annotation. /// The configured collation. - public static string SetCollation([NotNull] this IConventionModel model, [CanBeNull] string value, bool fromDataAnnotation = false) + public static string? SetCollation([NotNull] this IConventionModel model, [CanBeNull] string? value, bool fromDataAnnotation = false) { model.SetOrRemoveAnnotation( RelationalAnnotationNames.Collation, diff --git a/src/EFCore.Relational/Infrastructure/RelationalPropertyExtensions.cs b/src/EFCore.Relational/Infrastructure/RelationalPropertyExtensions.cs index c93460e06d5..d0a35964017 100644 --- a/src/EFCore.Relational/Infrastructure/RelationalPropertyExtensions.cs +++ b/src/EFCore.Relational/Infrastructure/RelationalPropertyExtensions.cs @@ -6,6 +6,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Metadata; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Infrastructure { /// @@ -30,7 +32,7 @@ public static string FormatColumns( /// The properties to format. /// The identifier of the table-like store object containing the column. /// A list of column names. - public static IReadOnlyList GetColumnNames( + public static IReadOnlyList? GetColumnNames( [NotNull] this IEnumerable properties, in StoreObjectIdentifier storeObject) { diff --git a/src/EFCore.Relational/Metadata/CheckConstraintExtensions.cs b/src/EFCore.Relational/Metadata/CheckConstraintExtensions.cs index 380cc9b770f..785ec902d1e 100644 --- a/src/EFCore.Relational/Metadata/CheckConstraintExtensions.cs +++ b/src/EFCore.Relational/Metadata/CheckConstraintExtensions.cs @@ -5,6 +5,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Infrastructure; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata { /// diff --git a/src/EFCore.Relational/Metadata/ColumnExtensions.cs b/src/EFCore.Relational/Metadata/ColumnExtensions.cs index 1bba5d6f83d..15e18e48b56 100644 --- a/src/EFCore.Relational/Metadata/ColumnExtensions.cs +++ b/src/EFCore.Relational/Metadata/ColumnExtensions.cs @@ -5,6 +5,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Infrastructure; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata { /// diff --git a/src/EFCore.Relational/Metadata/ColumnMappingExtensions.cs b/src/EFCore.Relational/Metadata/ColumnMappingExtensions.cs index 94e81833b57..e120d606211 100644 --- a/src/EFCore.Relational/Metadata/ColumnMappingExtensions.cs +++ b/src/EFCore.Relational/Metadata/ColumnMappingExtensions.cs @@ -5,6 +5,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Infrastructure; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata { /// diff --git a/src/EFCore.Relational/Metadata/DbFunctionExtensions.cs b/src/EFCore.Relational/Metadata/DbFunctionExtensions.cs index 5fc504f7af0..d0fee4979f8 100644 --- a/src/EFCore.Relational/Metadata/DbFunctionExtensions.cs +++ b/src/EFCore.Relational/Metadata/DbFunctionExtensions.cs @@ -6,6 +6,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Infrastructure; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata { /// diff --git a/src/EFCore.Relational/Metadata/DbFunctionParameterExtensions.cs b/src/EFCore.Relational/Metadata/DbFunctionParameterExtensions.cs index 151422cd6e0..32a47ff3e65 100644 --- a/src/EFCore.Relational/Metadata/DbFunctionParameterExtensions.cs +++ b/src/EFCore.Relational/Metadata/DbFunctionParameterExtensions.cs @@ -5,6 +5,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Infrastructure; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata { /// diff --git a/src/EFCore.Relational/Metadata/ForeignKeyConstraintExtensions.cs b/src/EFCore.Relational/Metadata/ForeignKeyConstraintExtensions.cs index ac57e10eea6..a082864fdbe 100644 --- a/src/EFCore.Relational/Metadata/ForeignKeyConstraintExtensions.cs +++ b/src/EFCore.Relational/Metadata/ForeignKeyConstraintExtensions.cs @@ -7,6 +7,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Internal; using Microsoft.EntityFrameworkCore.Migrations; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata { /// diff --git a/src/EFCore.Relational/Metadata/FunctionColumnExtensions.cs b/src/EFCore.Relational/Metadata/FunctionColumnExtensions.cs index d744ccc1d6b..81414d4f50d 100644 --- a/src/EFCore.Relational/Metadata/FunctionColumnExtensions.cs +++ b/src/EFCore.Relational/Metadata/FunctionColumnExtensions.cs @@ -5,6 +5,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Infrastructure; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata { /// diff --git a/src/EFCore.Relational/Metadata/FunctionColumnMappingExtensions.cs b/src/EFCore.Relational/Metadata/FunctionColumnMappingExtensions.cs index 95f0b75107b..d2212aa5bac 100644 --- a/src/EFCore.Relational/Metadata/FunctionColumnMappingExtensions.cs +++ b/src/EFCore.Relational/Metadata/FunctionColumnMappingExtensions.cs @@ -5,6 +5,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Infrastructure; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata { /// diff --git a/src/EFCore.Relational/Metadata/FunctionMappingExtensions.cs b/src/EFCore.Relational/Metadata/FunctionMappingExtensions.cs index ef30b7cfb8c..0b5e077c046 100644 --- a/src/EFCore.Relational/Metadata/FunctionMappingExtensions.cs +++ b/src/EFCore.Relational/Metadata/FunctionMappingExtensions.cs @@ -5,6 +5,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Infrastructure; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata { /// diff --git a/src/EFCore.Relational/Metadata/ICheckConstraint.cs b/src/EFCore.Relational/Metadata/ICheckConstraint.cs index fb65f02beb5..ec161778d92 100644 --- a/src/EFCore.Relational/Metadata/ICheckConstraint.cs +++ b/src/EFCore.Relational/Metadata/ICheckConstraint.cs @@ -3,6 +3,8 @@ using Microsoft.EntityFrameworkCore.Infrastructure; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata { /// diff --git a/src/EFCore.Relational/Metadata/IColumn.cs b/src/EFCore.Relational/Metadata/IColumn.cs index 2b1ce9297a5..e9c5a9ded7a 100644 --- a/src/EFCore.Relational/Metadata/IColumn.cs +++ b/src/EFCore.Relational/Metadata/IColumn.cs @@ -4,6 +4,8 @@ using System.Collections.Generic; using System.Linq; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata { /// @@ -65,7 +67,7 @@ bool IsRowVersion /// /// Returns the object that is used as the default value for this column. /// - public virtual object DefaultValue + public virtual object? DefaultValue { get { @@ -82,14 +84,14 @@ public virtual object DefaultValue /// /// Returns the SQL expression that is used as the default value for this column. /// - public virtual string DefaultValueSql + public virtual string? DefaultValueSql => PropertyMappings.First().Property .GetDefaultValueSql(StoreObjectIdentifier.Table(Table.Name, Table.Schema)); /// /// Returns the SQL expression that is used as the computed value for this column. /// - public virtual string ComputedColumnSql + public virtual string? ComputedColumnSql => PropertyMappings.First().Property .GetComputedColumnSql(StoreObjectIdentifier.Table(Table.Name, Table.Schema)); @@ -104,14 +106,14 @@ public virtual bool? IsStored /// /// Comment for this column /// - public virtual string Comment + public virtual string? Comment => PropertyMappings.First().Property .GetComment(StoreObjectIdentifier.Table(Table.Name, Table.Schema)); /// /// Collation for this column /// - public virtual string Collation + public virtual string? Collation => PropertyMappings.First().Property .GetCollation(StoreObjectIdentifier.Table(Table.Name, Table.Schema)); } diff --git a/src/EFCore.Relational/Metadata/IColumnBase.cs b/src/EFCore.Relational/Metadata/IColumnBase.cs index 6473a857f9e..c52b97ba7ef 100644 --- a/src/EFCore.Relational/Metadata/IColumnBase.cs +++ b/src/EFCore.Relational/Metadata/IColumnBase.cs @@ -4,6 +4,8 @@ using System.Collections.Generic; using Microsoft.EntityFrameworkCore.Infrastructure; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata { /// diff --git a/src/EFCore.Relational/Metadata/IColumnMapping.cs b/src/EFCore.Relational/Metadata/IColumnMapping.cs index bf2ceab9e4f..f8a08348061 100644 --- a/src/EFCore.Relational/Metadata/IColumnMapping.cs +++ b/src/EFCore.Relational/Metadata/IColumnMapping.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.Relational/Metadata/IColumnMappingBase.cs b/src/EFCore.Relational/Metadata/IColumnMappingBase.cs index 255c8a62ef2..50ea0ee7904 100644 --- a/src/EFCore.Relational/Metadata/IColumnMappingBase.cs +++ b/src/EFCore.Relational/Metadata/IColumnMappingBase.cs @@ -4,6 +4,8 @@ using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Storage; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata { /// diff --git a/src/EFCore.Relational/Metadata/IConventionCheckConstraint.cs b/src/EFCore.Relational/Metadata/IConventionCheckConstraint.cs index 5abe78eb7a7..25d148648fc 100644 --- a/src/EFCore.Relational/Metadata/IConventionCheckConstraint.cs +++ b/src/EFCore.Relational/Metadata/IConventionCheckConstraint.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.Relational/Metadata/IConventionDbFunction.cs b/src/EFCore.Relational/Metadata/IConventionDbFunction.cs index a7bc0aa59f3..3f4b0f54961 100644 --- a/src/EFCore.Relational/Metadata/IConventionDbFunction.cs +++ b/src/EFCore.Relational/Metadata/IConventionDbFunction.cs @@ -8,6 +8,8 @@ using Microsoft.EntityFrameworkCore.Query.SqlExpressions; using Microsoft.EntityFrameworkCore.Storage; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata { /// @@ -24,7 +26,7 @@ public interface IConventionDbFunction : IConventionAnnotatable, IDbFunction /// /// Gets the builder that can be used to configure this function. /// - new IConventionDbFunctionBuilder Builder { get; } + new IConventionDbFunctionBuilder? Builder { get; } /// /// Gets the configuration source for this function. @@ -38,7 +40,7 @@ public interface IConventionDbFunction : IConventionAnnotatable, IDbFunction /// The name of the function in the database. /// Indicates whether the configuration was specified using a data annotation. /// The configured value. - string SetName([CanBeNull] string name, bool fromDataAnnotation = false); + string? SetName([CanBeNull] string? name, bool fromDataAnnotation = false); /// /// Gets the configuration source for . @@ -52,7 +54,7 @@ public interface IConventionDbFunction : IConventionAnnotatable, IDbFunction /// The schema of the function in the database. /// Indicates whether the configuration was specified using a data annotation. /// The configured value. - string SetSchema([CanBeNull] string schema, bool fromDataAnnotation = false); + string? SetSchema([CanBeNull] string? schema, bool fromDataAnnotation = false); /// /// Gets the configuration source for . @@ -94,7 +96,7 @@ public interface IConventionDbFunction : IConventionAnnotatable, IDbFunction /// The store type of the function in the database. /// Indicates whether the configuration was specified using a data annotation. /// The configured value. - string SetStoreType([CanBeNull] string storeType, bool fromDataAnnotation = false); + string? SetStoreType([CanBeNull] string? storeType, bool fromDataAnnotation = false); /// /// Gets the configuration source for . @@ -108,7 +110,7 @@ public interface IConventionDbFunction : IConventionAnnotatable, IDbFunction /// The type mapping of the function in the database. /// Indicates whether the configuration was specified using a data annotation. /// The configured value. - RelationalTypeMapping SetTypeMapping([CanBeNull] RelationalTypeMapping typeMapping, bool fromDataAnnotation = false); + RelationalTypeMapping? SetTypeMapping([CanBeNull] RelationalTypeMapping? typeMapping, bool fromDataAnnotation = false); /// /// Gets the configuration source for . @@ -124,8 +126,8 @@ public interface IConventionDbFunction : IConventionAnnotatable, IDbFunction /// /// Indicates whether the configuration was specified using a data annotation. /// The configured value. - Func, SqlExpression> SetTranslation( - [CanBeNull] Func, SqlExpression> translation, + Func, SqlExpression>? SetTranslation( + [CanBeNull] Func, SqlExpression>? translation, bool fromDataAnnotation = false); /// diff --git a/src/EFCore.Relational/Metadata/IConventionDbFunctionParameter.cs b/src/EFCore.Relational/Metadata/IConventionDbFunctionParameter.cs index 79a374f5956..f101c6210fe 100644 --- a/src/EFCore.Relational/Metadata/IConventionDbFunctionParameter.cs +++ b/src/EFCore.Relational/Metadata/IConventionDbFunctionParameter.cs @@ -5,6 +5,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Storage; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata { /// @@ -20,7 +22,7 @@ public interface IConventionDbFunctionParameter : IConventionAnnotatable, IDbFun /// /// The for configuring this function parameter. /// - new IConventionDbFunctionParameterBuilder Builder { get; } + new IConventionDbFunctionParameterBuilder? Builder { get; } /// /// Returns the configuration source for the parameter. @@ -33,7 +35,7 @@ public interface IConventionDbFunctionParameter : IConventionAnnotatable, IDbFun /// /// The store type of the parameter. /// Indicates whether the configuration was specified using a data annotation. - string SetStoreType([CanBeNull] string storeType, bool fromDataAnnotation = false); + string? SetStoreType([CanBeNull] string? storeType, bool fromDataAnnotation = false); /// /// Returns the configuration source for . @@ -46,7 +48,7 @@ public interface IConventionDbFunctionParameter : IConventionAnnotatable, IDbFun /// /// The type mapping of the parameter in the database. /// Indicates whether the configuration was specified using a data annotation. - RelationalTypeMapping SetTypeMapping([CanBeNull] RelationalTypeMapping typeMapping, bool fromDataAnnotation = false); + RelationalTypeMapping? SetTypeMapping([CanBeNull] RelationalTypeMapping? typeMapping, bool fromDataAnnotation = false); /// /// Returns the configuration source for . diff --git a/src/EFCore.Relational/Metadata/IConventionSequence.cs b/src/EFCore.Relational/Metadata/IConventionSequence.cs index 593f6e6c4a4..d257b9e2da3 100644 --- a/src/EFCore.Relational/Metadata/IConventionSequence.cs +++ b/src/EFCore.Relational/Metadata/IConventionSequence.cs @@ -5,6 +5,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Metadata.Builders; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata { /// @@ -21,7 +23,7 @@ public interface IConventionSequence : ISequence, IConventionAnnotatable /// /// Gets the builder that can be used to configure this sequence. /// - new IConventionSequenceBuilder Builder { get; } + new IConventionSequenceBuilder? Builder { get; } /// /// Gets the configuration source for this . @@ -91,7 +93,7 @@ public interface IConventionSequence : ISequence, IConventionAnnotatable /// The of values returned by the sequence. /// Indicates whether the configuration was specified using a data annotation. /// The configured value. - Type SetType([CanBeNull] Type type, bool fromDataAnnotation = false); + Type? SetType([CanBeNull] Type? type, bool fromDataAnnotation = false); /// /// Gets the configuration source for . @@ -106,7 +108,7 @@ public interface IConventionSequence : ISequence, IConventionAnnotatable /// Indicates whether the configuration was specified using a data annotation. /// The configured value. [Obsolete("Use SetType")] - Type SetClrType([CanBeNull] Type type, bool fromDataAnnotation = false); + Type? SetClrType([CanBeNull] Type? type, bool fromDataAnnotation = false); /// /// Gets the configuration source for . diff --git a/src/EFCore.Relational/Metadata/IDbFunction.cs b/src/EFCore.Relational/Metadata/IDbFunction.cs index df018c20b9a..e561bf553a3 100644 --- a/src/EFCore.Relational/Metadata/IDbFunction.cs +++ b/src/EFCore.Relational/Metadata/IDbFunction.cs @@ -7,6 +7,9 @@ using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Query.SqlExpressions; using Microsoft.EntityFrameworkCore.Storage; +using CA = System.Diagnostics.CodeAnalysis; + +#nullable enable namespace Microsoft.EntityFrameworkCore.Metadata { @@ -23,7 +26,7 @@ public interface IDbFunction : IAnnotatable /// /// Gets the schema of the function in the database. /// - string Schema { get; } + string? Schema { get; } /// /// Gets the name of the function in the model. @@ -38,7 +41,7 @@ public interface IDbFunction : IAnnotatable /// /// Gets the CLR method which maps to the function in the database. /// - MethodInfo MethodInfo { get; } + MethodInfo? MethodInfo { get; } /// /// Gets the value indicating whether the database function is built-in. @@ -48,6 +51,7 @@ public interface IDbFunction : IAnnotatable /// /// Gets the value indicating whether this function returns scalar value. /// + [CA.MemberNotNullWhen(true, nameof(TypeMapping))] bool IsScalar { get; } /// @@ -63,7 +67,7 @@ public interface IDbFunction : IAnnotatable /// /// Gets the configured store type string. /// - string StoreType { get; } + string? StoreType { get; } /// /// Gets the returned CLR type. @@ -73,7 +77,7 @@ public interface IDbFunction : IAnnotatable /// /// Gets the type mapping for the function's return type. /// - RelationalTypeMapping TypeMapping { get; } + RelationalTypeMapping? TypeMapping { get; } /// /// Gets the parameters for this function. @@ -83,7 +87,7 @@ public interface IDbFunction : IAnnotatable /// /// Gets the translation callback for performing custom translation of the method call into a SQL expression fragment. /// - Func, SqlExpression> Translation { get; } + Func, SqlExpression>? Translation { get; } /// /// Gets the associated . diff --git a/src/EFCore.Relational/Metadata/IDbFunctionParameter.cs b/src/EFCore.Relational/Metadata/IDbFunctionParameter.cs index 792316c36e7..2c1b7c22adb 100644 --- a/src/EFCore.Relational/Metadata/IDbFunctionParameter.cs +++ b/src/EFCore.Relational/Metadata/IDbFunctionParameter.cs @@ -5,6 +5,8 @@ using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Storage; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata { /// @@ -46,6 +48,7 @@ public interface IDbFunctionParameter : IAnnotatable /// /// Gets the associated . /// - IStoreFunctionParameter StoreFunctionParameter { get; } + // TODO-NULLABLE: Not sure about what this is for or if it should be nullable + IStoreFunctionParameter? StoreFunctionParameter { get; } } } diff --git a/src/EFCore.Relational/Metadata/IForeignKeyConstraint.cs b/src/EFCore.Relational/Metadata/IForeignKeyConstraint.cs index 95202dc7e57..0895dc59863 100644 --- a/src/EFCore.Relational/Metadata/IForeignKeyConstraint.cs +++ b/src/EFCore.Relational/Metadata/IForeignKeyConstraint.cs @@ -5,6 +5,8 @@ using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Migrations; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata { /// diff --git a/src/EFCore.Relational/Metadata/IFunctionColumn.cs b/src/EFCore.Relational/Metadata/IFunctionColumn.cs index ba70843c1c7..4ef13a823a6 100644 --- a/src/EFCore.Relational/Metadata/IFunctionColumn.cs +++ b/src/EFCore.Relational/Metadata/IFunctionColumn.cs @@ -3,6 +3,8 @@ using System.Collections.Generic; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata { /// diff --git a/src/EFCore.Relational/Metadata/IFunctionColumnMapping.cs b/src/EFCore.Relational/Metadata/IFunctionColumnMapping.cs index c5a1ef46f6f..9c6d7c66a5a 100644 --- a/src/EFCore.Relational/Metadata/IFunctionColumnMapping.cs +++ b/src/EFCore.Relational/Metadata/IFunctionColumnMapping.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.Relational/Metadata/IFunctionMapping.cs b/src/EFCore.Relational/Metadata/IFunctionMapping.cs index ff67a0ff433..8e4531ef0a3 100644 --- a/src/EFCore.Relational/Metadata/IFunctionMapping.cs +++ b/src/EFCore.Relational/Metadata/IFunctionMapping.cs @@ -3,6 +3,8 @@ using System.Collections.Generic; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata { /// diff --git a/src/EFCore.Relational/Metadata/IMutableCheckConstraint.cs b/src/EFCore.Relational/Metadata/IMutableCheckConstraint.cs index ecf8a55fa1f..79a750207b8 100644 --- a/src/EFCore.Relational/Metadata/IMutableCheckConstraint.cs +++ b/src/EFCore.Relational/Metadata/IMutableCheckConstraint.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.Relational/Metadata/IMutableDbFunction.cs b/src/EFCore.Relational/Metadata/IMutableDbFunction.cs index 8b4e6b96938..cc0410f573f 100644 --- a/src/EFCore.Relational/Metadata/IMutableDbFunction.cs +++ b/src/EFCore.Relational/Metadata/IMutableDbFunction.cs @@ -7,6 +7,8 @@ using Microsoft.EntityFrameworkCore.Query.SqlExpressions; using Microsoft.EntityFrameworkCore.Storage; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata { /// @@ -23,7 +25,7 @@ public interface IMutableDbFunction : IMutableAnnotatable, IDbFunction /// /// Gets or sets the schema of the function in the database. /// - new string Schema { get; [param: CanBeNull] set; } + new string? Schema { get; [param: CanBeNull] set; } /// /// Gets or sets the value indicating whether the database function is built-in or not. @@ -38,12 +40,12 @@ public interface IMutableDbFunction : IMutableAnnotatable, IDbFunction /// /// Gets or sets the store type of the function in the database. /// - new string StoreType { get; [param: CanBeNull] set; } + new string? StoreType { get; [param: CanBeNull] set; } /// /// Gets or sets the type mapping of the function in the database. /// - new RelationalTypeMapping TypeMapping { get; [param: CanBeNull] set; } + new RelationalTypeMapping? TypeMapping { get; [param: CanBeNull] set; } /// /// Gets the in which this function is defined. @@ -58,6 +60,6 @@ public interface IMutableDbFunction : IMutableAnnotatable, IDbFunction /// /// Gets or sets the translation callback for performing custom translation of the method call into a SQL expression fragment. /// - new Func, SqlExpression> Translation { get; [param: CanBeNull] set; } + new Func, SqlExpression>? Translation { get; [param: CanBeNull] set; } } } diff --git a/src/EFCore.Relational/Metadata/IMutableDbFunctionParameter.cs b/src/EFCore.Relational/Metadata/IMutableDbFunctionParameter.cs index 05a5bb071b5..69327cc0018 100644 --- a/src/EFCore.Relational/Metadata/IMutableDbFunctionParameter.cs +++ b/src/EFCore.Relational/Metadata/IMutableDbFunctionParameter.cs @@ -4,6 +4,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Storage; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata { /// @@ -19,11 +21,11 @@ public interface IMutableDbFunctionParameter : IMutableAnnotatable, IDbFunctionP /// /// Gets or sets the store type of this parameter. /// - new string StoreType { get; [param: CanBeNull] set; } + new string? StoreType { get; [param: CanBeNull] set; } /// /// Gets or sets the for this parameter. /// - new RelationalTypeMapping TypeMapping { get; [param: CanBeNull] set; } + new RelationalTypeMapping? TypeMapping { get; [param: CanBeNull] set; } } } diff --git a/src/EFCore.Relational/Metadata/IMutableSequence.cs b/src/EFCore.Relational/Metadata/IMutableSequence.cs index 44027a312d2..a979201fbd0 100644 --- a/src/EFCore.Relational/Metadata/IMutableSequence.cs +++ b/src/EFCore.Relational/Metadata/IMutableSequence.cs @@ -4,6 +4,8 @@ using System; using JetBrains.Annotations; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata { /// diff --git a/src/EFCore.Relational/Metadata/IPrimaryKeyConstraint.cs b/src/EFCore.Relational/Metadata/IPrimaryKeyConstraint.cs index 0bc62d2f8ce..ffe4fea9466 100644 --- a/src/EFCore.Relational/Metadata/IPrimaryKeyConstraint.cs +++ b/src/EFCore.Relational/Metadata/IPrimaryKeyConstraint.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.Relational/Metadata/IRelationalAnnotationProvider.cs b/src/EFCore.Relational/Metadata/IRelationalAnnotationProvider.cs index feb9e1b5f44..820f8fa1e96 100644 --- a/src/EFCore.Relational/Metadata/IRelationalAnnotationProvider.cs +++ b/src/EFCore.Relational/Metadata/IRelationalAnnotationProvider.cs @@ -6,6 +6,8 @@ using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.Extensions.DependencyInjection; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata { /// diff --git a/src/EFCore.Relational/Metadata/IRelationalModel.cs b/src/EFCore.Relational/Metadata/IRelationalModel.cs index f9c984a5401..714536baefe 100644 --- a/src/EFCore.Relational/Metadata/IRelationalModel.cs +++ b/src/EFCore.Relational/Metadata/IRelationalModel.cs @@ -5,6 +5,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Infrastructure; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata { /// @@ -48,7 +50,7 @@ IEnumerable Sequences /// /// Returns the database collation. /// - string Collation + string? Collation => Model.GetCollation(); /// @@ -57,7 +59,7 @@ string Collation /// The name of the table. /// The schema of the table. /// The table with a given name or if no table with the given name is defined. - ITable FindTable([NotNull] string name, [CanBeNull] string schema); + ITable? FindTable([NotNull] string name, [CanBeNull] string? schema); /// /// Gets the view with the given name. Returns if no view with the given name is defined. @@ -65,14 +67,14 @@ string Collation /// The name of the view. /// The schema of the view. /// The view with a given name or if no view with the given name is defined. - IView FindView([NotNull] string name, [CanBeNull] string schema); + IView? FindView([NotNull] string name, [CanBeNull] string? schema); /// /// Gets the SQL query with the given name. Returns if no SQL query with the given name is defined. /// /// The name of the SQL query. /// The SQL query with a given name or if no SQL query with the given name is defined. - ISqlQuery FindQuery([NotNull] string name); + ISqlQuery? FindQuery([NotNull] string name); /// /// Finds an with the given name. @@ -83,7 +85,7 @@ string Collation /// The or if no sequence with the given name in /// the given schema was found. /// - ISequence FindSequence([NotNull] string name, [CanBeNull] string schema) + ISequence? FindSequence([NotNull] string name, [CanBeNull] string? schema) => Model.FindSequence(name, schema); /// @@ -93,6 +95,6 @@ ISequence FindSequence([NotNull] string name, [CanBeNull] string schema) /// The schema of the function. /// A list of parameter types. /// The or if no function with the given name was defined. - IStoreFunction FindFunction([NotNull] string name, [CanBeNull] string schema, [NotNull] IReadOnlyList parameters); + IStoreFunction? FindFunction([NotNull] string name, [CanBeNull] string? schema, [NotNull] IReadOnlyList parameters); } } diff --git a/src/EFCore.Relational/Metadata/ISequence.cs b/src/EFCore.Relational/Metadata/ISequence.cs index 05a1d51c114..cab2584afb5 100644 --- a/src/EFCore.Relational/Metadata/ISequence.cs +++ b/src/EFCore.Relational/Metadata/ISequence.cs @@ -4,6 +4,8 @@ using System; using Microsoft.EntityFrameworkCore.Infrastructure; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata { /// @@ -19,7 +21,7 @@ public interface ISequence : IAnnotatable /// /// Gets the database schema that contains the sequence. /// - string Schema { get; } + string? Schema { get; } /// /// Gets the in which this sequence is defined. diff --git a/src/EFCore.Relational/Metadata/ISqlQuery.cs b/src/EFCore.Relational/Metadata/ISqlQuery.cs index 048903291a3..1f4edc95c20 100644 --- a/src/EFCore.Relational/Metadata/ISqlQuery.cs +++ b/src/EFCore.Relational/Metadata/ISqlQuery.cs @@ -4,6 +4,8 @@ using System.Collections.Generic; using JetBrains.Annotations; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata { /// @@ -24,12 +26,12 @@ public interface ISqlQuery : ITableBase /// /// Gets the column with the given name. Returns if no column with the given name is defined. /// - new ISqlQueryColumn FindColumn([NotNull] string name); + new ISqlQueryColumn? FindColumn([NotNull] string name); /// /// Gets the column mapped to the given property. Returns if no column is mapped to the given property. /// - new ISqlQueryColumn FindColumn([NotNull] IProperty property); + new ISqlQueryColumn? FindColumn([NotNull] IProperty property); /// /// Gets the SQL query string. diff --git a/src/EFCore.Relational/Metadata/ISqlQueryColumn.cs b/src/EFCore.Relational/Metadata/ISqlQueryColumn.cs index bc8575859e9..a7e447b5006 100644 --- a/src/EFCore.Relational/Metadata/ISqlQueryColumn.cs +++ b/src/EFCore.Relational/Metadata/ISqlQueryColumn.cs @@ -3,6 +3,8 @@ using System.Collections.Generic; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata { /// diff --git a/src/EFCore.Relational/Metadata/ISqlQueryColumnMapping.cs b/src/EFCore.Relational/Metadata/ISqlQueryColumnMapping.cs index 8f18ff4ca94..041156f854b 100644 --- a/src/EFCore.Relational/Metadata/ISqlQueryColumnMapping.cs +++ b/src/EFCore.Relational/Metadata/ISqlQueryColumnMapping.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.Relational/Metadata/ISqlQueryMapping.cs b/src/EFCore.Relational/Metadata/ISqlQueryMapping.cs index 68809bd904c..7382420136c 100644 --- a/src/EFCore.Relational/Metadata/ISqlQueryMapping.cs +++ b/src/EFCore.Relational/Metadata/ISqlQueryMapping.cs @@ -3,6 +3,8 @@ using System.Collections.Generic; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata { /// diff --git a/src/EFCore.Relational/Metadata/IStoreFunction.cs b/src/EFCore.Relational/Metadata/IStoreFunction.cs index 433a05008e2..c8a543b70ce 100644 --- a/src/EFCore.Relational/Metadata/IStoreFunction.cs +++ b/src/EFCore.Relational/Metadata/IStoreFunction.cs @@ -4,6 +4,8 @@ using System.Collections.Generic; using JetBrains.Annotations; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata { /// @@ -29,7 +31,7 @@ public interface IStoreFunction : ITableBase /// /// Gets the scalar return type. /// - string ReturnType { get; } + string? ReturnType { get; } /// /// Gets the entity type mappings for the returned row set. @@ -45,11 +47,11 @@ public interface IStoreFunction : ITableBase /// Gets the column with the given name. Returns /// if no column with the given name is defined for the returned row set. /// - new IFunctionColumn FindColumn([NotNull] string name); + new IFunctionColumn? FindColumn([NotNull] string name); /// /// Gets the column mapped to the given property. Returns if no column is mapped to the given property. /// - new IFunctionColumn FindColumn([NotNull] IProperty property); + new IFunctionColumn? FindColumn([NotNull] IProperty property); } } diff --git a/src/EFCore.Relational/Metadata/IStoreFunctionParameter.cs b/src/EFCore.Relational/Metadata/IStoreFunctionParameter.cs index 062df759837..514dfa10b18 100644 --- a/src/EFCore.Relational/Metadata/IStoreFunctionParameter.cs +++ b/src/EFCore.Relational/Metadata/IStoreFunctionParameter.cs @@ -4,6 +4,8 @@ using System.Collections.Generic; using Microsoft.EntityFrameworkCore.Infrastructure; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata { /// diff --git a/src/EFCore.Relational/Metadata/ITable.cs b/src/EFCore.Relational/Metadata/ITable.cs index b65851825f9..d17329d5b82 100644 --- a/src/EFCore.Relational/Metadata/ITable.cs +++ b/src/EFCore.Relational/Metadata/ITable.cs @@ -7,6 +7,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Internal; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata { /// @@ -42,7 +44,7 @@ public interface ITable : ITableBase /// /// Gets the primary key for this table. /// - IPrimaryKeyConstraint PrimaryKey { get; } + IPrimaryKeyConstraint? PrimaryKey { get; } /// /// Gets the indexes for this table. @@ -59,17 +61,17 @@ IEnumerable CheckConstraints /// /// Gets the comment for this table. /// - public virtual string Comment + public virtual string? Comment => EntityTypeMappings.Select(e => e.EntityType.GetComment()).FirstOrDefault(c => c != null); /// /// Gets the column with a given name. Returns if no column with the given name is defined. /// - new IColumn FindColumn([NotNull] string name); + new IColumn? FindColumn([NotNull] string name); /// /// Gets the column mapped to the given property. Returns if no column is mapped to the given property. /// - new IColumn FindColumn([NotNull] IProperty property); + new IColumn? FindColumn([NotNull] IProperty property); } } diff --git a/src/EFCore.Relational/Metadata/ITableBase.cs b/src/EFCore.Relational/Metadata/ITableBase.cs index 4cea9741284..ad07d734a58 100644 --- a/src/EFCore.Relational/Metadata/ITableBase.cs +++ b/src/EFCore.Relational/Metadata/ITableBase.cs @@ -5,6 +5,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Infrastructure; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata { /// @@ -20,7 +22,7 @@ public interface ITableBase : IAnnotatable /// /// Gets the schema of the table in the database. /// - string Schema { get; } + string? Schema { get; } /// /// Gets the database model. @@ -45,12 +47,12 @@ public interface ITableBase : IAnnotatable /// /// Gets the column with the given name. Returns if no column with the given name is defined. /// - IColumnBase FindColumn([NotNull] string name); + IColumnBase? FindColumn([NotNull] string name); /// /// Gets the column mapped to the given property. Returns if no column is mapped to the given property. /// - IColumnBase FindColumn([NotNull] IProperty property); + IColumnBase? FindColumn([NotNull] IProperty property); /// /// Gets the foreign keys for the given entity type that point to other entity types sharing this table. diff --git a/src/EFCore.Relational/Metadata/ITableIndex.cs b/src/EFCore.Relational/Metadata/ITableIndex.cs index 87a7c329bd7..1e0dfe339a3 100644 --- a/src/EFCore.Relational/Metadata/ITableIndex.cs +++ b/src/EFCore.Relational/Metadata/ITableIndex.cs @@ -4,6 +4,8 @@ using System.Collections.Generic; using Microsoft.EntityFrameworkCore.Infrastructure; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata { /// @@ -39,6 +41,6 @@ public interface ITableIndex : IAnnotatable /// /// Gets the expression used as the index filter. /// - string Filter { get; } + string? Filter { get; } } } diff --git a/src/EFCore.Relational/Metadata/ITableMapping.cs b/src/EFCore.Relational/Metadata/ITableMapping.cs index f7e10f5267e..d70d514894a 100644 --- a/src/EFCore.Relational/Metadata/ITableMapping.cs +++ b/src/EFCore.Relational/Metadata/ITableMapping.cs @@ -3,6 +3,8 @@ using System.Collections.Generic; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata { /// diff --git a/src/EFCore.Relational/Metadata/ITableMappingBase.cs b/src/EFCore.Relational/Metadata/ITableMappingBase.cs index 9e414654aa1..6a55a65a384 100644 --- a/src/EFCore.Relational/Metadata/ITableMappingBase.cs +++ b/src/EFCore.Relational/Metadata/ITableMappingBase.cs @@ -4,6 +4,8 @@ using System.Collections.Generic; using Microsoft.EntityFrameworkCore.Infrastructure; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata { /// diff --git a/src/EFCore.Relational/Metadata/IUniqueConstraint.cs b/src/EFCore.Relational/Metadata/IUniqueConstraint.cs index f3aafd748d7..27bbf27b6af 100644 --- a/src/EFCore.Relational/Metadata/IUniqueConstraint.cs +++ b/src/EFCore.Relational/Metadata/IUniqueConstraint.cs @@ -4,6 +4,8 @@ using System.Collections.Generic; using Microsoft.EntityFrameworkCore.Infrastructure; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata { /// diff --git a/src/EFCore.Relational/Metadata/IView.cs b/src/EFCore.Relational/Metadata/IView.cs index 884231487b1..a555cd78329 100644 --- a/src/EFCore.Relational/Metadata/IView.cs +++ b/src/EFCore.Relational/Metadata/IView.cs @@ -4,6 +4,8 @@ using System.Collections.Generic; using JetBrains.Annotations; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata { /// @@ -24,16 +26,16 @@ public interface IView : ITableBase /// /// Gets the column with the given name. Returns if no column with the given name is defined. /// - new IViewColumn FindColumn([NotNull] string name); + new IViewColumn? FindColumn([NotNull] string name); /// /// Gets the column mapped to the given property. Returns if no column is mapped to the given property. /// - new IViewColumn FindColumn([NotNull] IProperty property); + new IViewColumn? FindColumn([NotNull] IProperty property); /// /// Gets the view definition or if this view is not managed by migrations. /// - public string ViewDefinitionSql { get; } + public string? ViewDefinitionSql { get; } } } diff --git a/src/EFCore.Relational/Metadata/IViewColumn.cs b/src/EFCore.Relational/Metadata/IViewColumn.cs index 074aa9f337d..3703fec5065 100644 --- a/src/EFCore.Relational/Metadata/IViewColumn.cs +++ b/src/EFCore.Relational/Metadata/IViewColumn.cs @@ -3,6 +3,8 @@ using System.Collections.Generic; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata { /// diff --git a/src/EFCore.Relational/Metadata/IViewColumnMapping.cs b/src/EFCore.Relational/Metadata/IViewColumnMapping.cs index 1b03c756d33..6c0cc50123e 100644 --- a/src/EFCore.Relational/Metadata/IViewColumnMapping.cs +++ b/src/EFCore.Relational/Metadata/IViewColumnMapping.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.Relational/Metadata/IViewMapping.cs b/src/EFCore.Relational/Metadata/IViewMapping.cs index ab1db88bd90..890efe1259d 100644 --- a/src/EFCore.Relational/Metadata/IViewMapping.cs +++ b/src/EFCore.Relational/Metadata/IViewMapping.cs @@ -3,6 +3,8 @@ using System.Collections.Generic; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata { /// diff --git a/src/EFCore.Relational/Metadata/Internal/CheckConstraint.cs b/src/EFCore.Relational/Metadata/Internal/CheckConstraint.cs index 6bc5e55b558..441976dd09c 100644 --- a/src/EFCore.Relational/Metadata/Internal/CheckConstraint.cs +++ b/src/EFCore.Relational/Metadata/Internal/CheckConstraint.cs @@ -9,6 +9,8 @@ using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Internal { /// @@ -76,7 +78,7 @@ public static IEnumerable GetCheckConstraints([NotNull] IEntity /// any release. You should only use it directly in your 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 ICheckConstraint FindCheckConstraint( + public static ICheckConstraint? FindCheckConstraint( [NotNull] IEntityType entityType, [NotNull] string name) { @@ -95,7 +97,7 @@ public static ICheckConstraint FindCheckConstraint( /// any release. You should only use it directly in your 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 CheckConstraint RemoveCheckConstraint( + public static CheckConstraint? RemoveCheckConstraint( [NotNull] IMutableEntityType entityType, [NotNull] string name) { @@ -155,8 +157,8 @@ public virtual void UpdateConfigurationSource(ConfigurationSource configurationS _configurationSource = configurationSource.Max(_configurationSource); } - private static Dictionary GetConstraintsDictionary(IEntityType entityType) - => (Dictionary)entityType[RelationalAnnotationNames.CheckConstraints]; + private static Dictionary? GetConstraintsDictionary(IEntityType entityType) + => (Dictionary?)entityType[RelationalAnnotationNames.CheckConstraints]; /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to diff --git a/src/EFCore.Relational/Metadata/Internal/Column.cs b/src/EFCore.Relational/Metadata/Internal/Column.cs index 8a5f49019fe..e2742ec5cd3 100644 --- a/src/EFCore.Relational/Metadata/Internal/Column.cs +++ b/src/EFCore.Relational/Metadata/Internal/Column.cs @@ -7,6 +7,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Infrastructure; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Internal { /// @@ -23,7 +25,7 @@ public class Column : ColumnBase, IColumn /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public Column([NotNull] string name, [CanBeNull] string type, [NotNull] Table table) + public Column([NotNull] string name, [NotNull] string type, [NotNull] Table table) : base(name, type, table) { } diff --git a/src/EFCore.Relational/Metadata/Internal/ColumnBase.cs b/src/EFCore.Relational/Metadata/Internal/ColumnBase.cs index 8e5936e6c96..b2d8a174fc8 100644 --- a/src/EFCore.Relational/Metadata/Internal/ColumnBase.cs +++ b/src/EFCore.Relational/Metadata/Internal/ColumnBase.cs @@ -7,6 +7,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Infrastructure; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Internal { /// diff --git a/src/EFCore.Relational/Metadata/Internal/ColumnListComparer.cs b/src/EFCore.Relational/Metadata/Internal/ColumnListComparer.cs index 5817aa1542d..6f40d4c3c90 100644 --- a/src/EFCore.Relational/Metadata/Internal/ColumnListComparer.cs +++ b/src/EFCore.Relational/Metadata/Internal/ColumnListComparer.cs @@ -4,6 +4,8 @@ using System; using System.Collections.Generic; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Internal { /// @@ -33,8 +35,23 @@ private ColumnListComparer() /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public int Compare(IReadOnlyList x, IReadOnlyList y) + public int Compare(IReadOnlyList? x, IReadOnlyList? y) { + if (ReferenceEquals(x, y)) + { + return 0; + } + + if (x is null) + { + return -1; + } + + if (y is null) + { + return 1; + } + var result = x.Count - y.Count; if (result != 0) { @@ -58,7 +75,7 @@ public int Compare(IReadOnlyList x, IReadOnlyList y) /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public bool Equals(IReadOnlyList x, IReadOnlyList y) + public bool Equals(IReadOnlyList? x, IReadOnlyList? y) => Compare(x, y) == 0; /// diff --git a/src/EFCore.Relational/Metadata/Internal/ColumnMapping.cs b/src/EFCore.Relational/Metadata/Internal/ColumnMapping.cs index be9e1da9f42..6a5553d9cdc 100644 --- a/src/EFCore.Relational/Metadata/Internal/ColumnMapping.cs +++ b/src/EFCore.Relational/Metadata/Internal/ColumnMapping.cs @@ -6,6 +6,8 @@ using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Storage; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Internal { /// @@ -25,7 +27,7 @@ public class ColumnMapping : ColumnMappingBase, IColumnMapping public ColumnMapping( [NotNull] IProperty property, [NotNull] Column column, - [CanBeNull] RelationalTypeMapping typeMapping, + [NotNull] RelationalTypeMapping typeMapping, [NotNull] TableMapping tableMapping) : base(property, column, typeMapping, tableMapping) { diff --git a/src/EFCore.Relational/Metadata/Internal/ColumnMappingBase.cs b/src/EFCore.Relational/Metadata/Internal/ColumnMappingBase.cs index b3048933aa8..28ef0d57a68 100644 --- a/src/EFCore.Relational/Metadata/Internal/ColumnMappingBase.cs +++ b/src/EFCore.Relational/Metadata/Internal/ColumnMappingBase.cs @@ -5,6 +5,8 @@ using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Storage; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Internal { /// diff --git a/src/EFCore.Relational/Metadata/Internal/ColumnMappingBaseComparer.cs b/src/EFCore.Relational/Metadata/Internal/ColumnMappingBaseComparer.cs index e3e42802fd9..a88e0c7365b 100644 --- a/src/EFCore.Relational/Metadata/Internal/ColumnMappingBaseComparer.cs +++ b/src/EFCore.Relational/Metadata/Internal/ColumnMappingBaseComparer.cs @@ -4,6 +4,8 @@ using System; using System.Collections.Generic; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Internal { /// @@ -32,8 +34,23 @@ private ColumnMappingBaseComparer() /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public int Compare(IColumnMappingBase x, IColumnMappingBase y) + public int Compare(IColumnMappingBase? x, IColumnMappingBase? y) { + if (ReferenceEquals(x, y)) + { + return 0; + } + + if (x is null) + { + return -1; + } + + if (y is null) + { + return 1; + } + var result = y.Property.IsPrimaryKey().CompareTo(x.Property.IsPrimaryKey()); if (result != 0) { @@ -73,9 +90,8 @@ public int Compare(IColumnMappingBase x, IColumnMappingBase y) /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public bool Equals(IColumnMappingBase x, IColumnMappingBase y) - => x.Property == y.Property - && x.Column == y.Column; + public bool Equals(IColumnMappingBase? x, IColumnMappingBase? y) + => ReferenceEquals(x, y) || x is not null && y is not null && x.Property == y.Property && x.Column == y.Column; /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to diff --git a/src/EFCore.Relational/Metadata/Internal/ColumnNameComparer.cs b/src/EFCore.Relational/Metadata/Internal/ColumnNameComparer.cs index 5e8cf79e4a5..8382593ddcb 100644 --- a/src/EFCore.Relational/Metadata/Internal/ColumnNameComparer.cs +++ b/src/EFCore.Relational/Metadata/Internal/ColumnNameComparer.cs @@ -5,6 +5,8 @@ using System.Collections.Generic; using JetBrains.Annotations; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Internal { /// @@ -34,7 +36,7 @@ public ColumnNameComparer([NotNull] Table table) /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public int Compare(string x, string y) + public int Compare(string? x, string? y) { var xIndex = -1; var yIndex = -1; diff --git a/src/EFCore.Relational/Metadata/Internal/DbFunction.cs b/src/EFCore.Relational/Metadata/Internal/DbFunction.cs index c1459d8d2e0..4914e146f1a 100644 --- a/src/EFCore.Relational/Metadata/Internal/DbFunction.cs +++ b/src/EFCore.Relational/Metadata/Internal/DbFunction.cs @@ -6,6 +6,7 @@ using System.Diagnostics; using System.Linq; using System.Reflection; +using System.Text; using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Infrastructure; @@ -15,6 +16,9 @@ using Microsoft.EntityFrameworkCore.Query.SqlExpressions; using Microsoft.EntityFrameworkCore.Storage; using Microsoft.EntityFrameworkCore.Utilities; +using CA = System.Diagnostics.CodeAnalysis; + +#nullable enable namespace Microsoft.EntityFrameworkCore.Metadata.Internal { @@ -27,13 +31,13 @@ namespace Microsoft.EntityFrameworkCore.Metadata.Internal public class DbFunction : ConventionAnnotatable, IMutableDbFunction, IConventionDbFunction { private readonly List _parameters; - private string _schema; - private string _name; + private string? _schema; + private string? _name; private bool _builtIn; private bool _nullable; - private string _storeType; - private RelationalTypeMapping _typeMapping; - private Func, SqlExpression> _translation; + private string? _storeType; + private RelationalTypeMapping? _typeMapping; + private Func, SqlExpression>? _translation; private ConfigurationSource _configurationSource; private ConfigurationSource? _schemaConfigurationSource; @@ -57,7 +61,7 @@ public DbFunction( : this( methodInfo.Name, methodInfo.ReturnType, - methodInfo.GetParameters().Select(pi => (pi.Name, pi.ParameterType)), + methodInfo.GetParameters().Select(pi => (pi.Name!, pi.ParameterType)), model, configurationSource) { @@ -89,7 +93,7 @@ public DbFunction( public DbFunction( [NotNull] string name, [NotNull] Type returnType, - [CanBeNull] IEnumerable<(string Name, Type Type)> parameters, + [CanBeNull] IEnumerable<(string Name, Type Type)>? parameters, [NotNull] IMutableModel model, ConfigurationSource configurationSource) { @@ -99,7 +103,7 @@ public DbFunction( || returnType == typeof(void)) { throw new ArgumentException( - RelationalStrings.DbFunctionInvalidReturnType(name, returnType.ShortDisplayName())); + RelationalStrings.DbFunctionInvalidReturnType(name, returnType?.ShortDisplayName())); } IsScalar = !returnType.IsGenericType @@ -124,12 +128,24 @@ public DbFunction( } private static string GetFunctionName(MethodInfo methodInfo, ParameterInfo[] parameters) - => methodInfo.DeclaringType.FullName - + "." - + methodInfo.Name - + "(" - + string.Join(",", parameters.Select(p => p.ParameterType.FullName)) - + ")"; + { + var builder = new StringBuilder(); + + if (methodInfo.DeclaringType != null) + { + builder + .Append(methodInfo.DeclaringType.FullName) + .Append("."); + } + + builder + .Append(methodInfo.Name) + .Append('(') + .AppendJoin(',', parameters.Select(p => p.ParameterType.FullName)) + .Append(')'); + + return builder.ToString(); + } /// public virtual IMutableModel Model { get; } @@ -140,7 +156,7 @@ 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 { get; private set; } /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -149,7 +165,7 @@ private static string GetFunctionName(MethodInfo methodInfo, ParameterInfo[] par /// doing so can result in application failures when updating to a new Entity Framework Core release. /// public static IEnumerable GetDbFunctions([NotNull] IModel model) - => ((SortedDictionary)model[RelationalAnnotationNames.DbFunctions]) + => ((SortedDictionary?)model[RelationalAnnotationNames.DbFunctions]) ?.Values ?? Enumerable.Empty(); @@ -159,7 +175,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 FindDbFunction([NotNull] IModel model, [NotNull] MethodInfo methodInfo) + public static DbFunction? FindDbFunction([NotNull] IModel model, [NotNull] MethodInfo methodInfo) => model[RelationalAnnotationNames.DbFunctions] is SortedDictionary functions && functions.TryGetValue(GetFunctionName(methodInfo, methodInfo.GetParameters()), out var dbFunction) ? dbFunction @@ -171,7 +187,7 @@ public static DbFunction FindDbFunction([NotNull] IModel model, [NotNull] Method /// any release. You should only use it directly in your 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 FindDbFunction([NotNull] IModel model, [NotNull] string name) + public static DbFunction? FindDbFunction([NotNull] IModel model, [NotNull] string name) => model[RelationalAnnotationNames.DbFunctions] is SortedDictionary functions && functions.TryGetValue(name, out var dbFunction) ? dbFunction @@ -183,7 +199,7 @@ public static DbFunction FindDbFunction([NotNull] IModel model, [NotNull] string /// any release. You should only use it directly in your 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) @@ -200,7 +216,7 @@ public static DbFunction AddDbFunction( /// any release. You should only use it directly in your 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, @@ -222,7 +238,7 @@ private static SortedDictionary GetOrCreateFunctions(IMutabl /// any release. You should only use it directly in your 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 RemoveDbFunction( + public static DbFunction? RemoveDbFunction( [NotNull] IMutableModel model, [NotNull] MethodInfo methodInfo) { @@ -247,7 +263,7 @@ public static DbFunction RemoveDbFunction( /// any release. You should only use it directly in your 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 RemoveDbFunction( + public static DbFunction? RemoveDbFunction( [NotNull] IMutableModel model, [NotNull] string name) { @@ -265,7 +281,7 @@ public static DbFunction RemoveDbFunction( public virtual string ModelName { get; } /// - public virtual MethodInfo MethodInfo { get; } + public virtual MethodInfo? MethodInfo { get; } /// public virtual Type ReturnType { get; } @@ -297,7 +313,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 Schema + public virtual string? Schema { get => _schema ?? Model.GetDefaultSchema(); set => SetSchema(value, ConfigurationSource.Explicit); @@ -309,7 +325,7 @@ public virtual string Schema /// any release. You should only use it directly in your 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 SetSchema([CanBeNull] string schema, ConfigurationSource configurationSource) + public virtual string? SetSchema([CanBeNull] string? schema, ConfigurationSource configurationSource) { _schema = schema; @@ -347,7 +363,7 @@ public virtual 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. /// - public virtual string SetName([CanBeNull] string name, ConfigurationSource configurationSource) + public virtual string? SetName([CanBeNull] string? name, ConfigurationSource configurationSource) { Check.NullButNotEmpty(name, nameof(name)); @@ -450,7 +466,7 @@ public virtual bool SetIsNullable(bool nullable, ConfigurationSource 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 string StoreType + public virtual string? StoreType { get => _storeType ?? TypeMapping?.StoreType; set => SetStoreType(value, ConfigurationSource.Explicit); @@ -462,7 +478,7 @@ public virtual string StoreType /// any release. You should only use it directly in your 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 SetStoreType([CanBeNull] string storeType, ConfigurationSource configurationSource) + public virtual string? SetStoreType([CanBeNull] string? storeType, ConfigurationSource configurationSource) { _storeType = storeType; @@ -488,7 +504,7 @@ public virtual string SetStoreType([CanBeNull] string storeType, 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 RelationalTypeMapping TypeMapping + public virtual RelationalTypeMapping? TypeMapping { get => _typeMapping; set => SetTypeMapping(value, ConfigurationSource.Explicit); @@ -500,8 +516,8 @@ public virtual RelationalTypeMapping 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 RelationalTypeMapping SetTypeMapping( - [CanBeNull] RelationalTypeMapping typeMapping, + public virtual RelationalTypeMapping? SetTypeMapping( + [CanBeNull] RelationalTypeMapping? typeMapping, ConfigurationSource configurationSource) { _typeMapping = typeMapping; @@ -528,7 +544,7 @@ public virtual RelationalTypeMapping SetTypeMapping( /// any release. You should only use it directly in your 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 Func, SqlExpression> Translation + public virtual Func, SqlExpression>? Translation { get => _translation; set => SetTranslation(value, ConfigurationSource.Explicit); @@ -540,14 +556,14 @@ public virtual Func, SqlExpression> Translati /// any release. You should only use it directly in your 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 Func, SqlExpression> SetTranslation( - [CanBeNull] Func, SqlExpression> translation, + public virtual Func, SqlExpression>? SetTranslation( + [CanBeNull] Func, SqlExpression>? translation, ConfigurationSource configurationSource) { if (translation != null && (!IsScalar || IsAggregate)) { - throw new InvalidOperationException(RelationalStrings.DbFunctionNonScalarCustomTranslation(MethodInfo.DisplayName())); + throw new InvalidOperationException(RelationalStrings.DbFunctionNonScalarCustomTranslation(MethodInfo?.DisplayName())); } _translation = translation; @@ -574,7 +590,7 @@ public virtual Func, SqlExpression> SetTransl /// any release. You should only use it directly in your 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 IStoreFunction StoreFunction { get; [param: NotNull] set; } + public virtual IStoreFunction? StoreFunction { get; [param: NotNull] set; } /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -586,7 +602,7 @@ public override string ToString() => this.ToDebugString(MetadataDebugStringOptions.SingleLineDefault); /// - IConventionDbFunctionBuilder IConventionDbFunction.Builder + IConventionDbFunctionBuilder? IConventionDbFunction.Builder { [DebuggerStepThrough] get => Builder; @@ -645,17 +661,17 @@ IReadOnlyList IMutableDbFunction.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 virtual DbFunctionParameter FindParameter([NotNull] string name) + public virtual DbFunctionParameter? FindParameter([NotNull] string name) => Parameters.SingleOrDefault(p => p.Name == name); /// [DebuggerStepThrough] - string IConventionDbFunction.SetName(string name, bool fromDataAnnotation) + string? IConventionDbFunction.SetName(string? name, bool fromDataAnnotation) => SetName(name, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// [DebuggerStepThrough] - string IConventionDbFunction.SetSchema(string schema, bool fromDataAnnotation) + string? IConventionDbFunction.SetSchema(string? schema, bool fromDataAnnotation) => SetSchema(schema, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// @@ -670,19 +686,23 @@ bool IConventionDbFunction.SetIsNullable(bool nullable, bool fromDataAnnotation) /// [DebuggerStepThrough] - string IConventionDbFunction.SetStoreType(string storeType, bool fromDataAnnotation) + string? IConventionDbFunction.SetStoreType(string? storeType, bool fromDataAnnotation) => SetStoreType(storeType, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// [DebuggerStepThrough] - RelationalTypeMapping IConventionDbFunction.SetTypeMapping(RelationalTypeMapping returnTypeMapping, bool fromDataAnnotation) + RelationalTypeMapping? IConventionDbFunction.SetTypeMapping(RelationalTypeMapping? returnTypeMapping, bool fromDataAnnotation) => SetTypeMapping(returnTypeMapping, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// [DebuggerStepThrough] - Func, SqlExpression> IConventionDbFunction.SetTranslation( - Func, SqlExpression> translation, + Func, SqlExpression>? IConventionDbFunction.SetTranslation( + Func, SqlExpression>? translation, bool fromDataAnnotation) => SetTranslation(translation, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); + + /// + IStoreFunction IDbFunction.StoreFunction + => StoreFunction!; // Relational model creation ensures StoreFunction is populated } } diff --git a/src/EFCore.Relational/Metadata/Internal/DbFunctionParameter.cs b/src/EFCore.Relational/Metadata/Internal/DbFunctionParameter.cs index d2b66c330ac..7e59923cfdd 100644 --- a/src/EFCore.Relational/Metadata/Internal/DbFunctionParameter.cs +++ b/src/EFCore.Relational/Metadata/Internal/DbFunctionParameter.cs @@ -10,6 +10,9 @@ using Microsoft.EntityFrameworkCore.Metadata.Builders.Internal; using Microsoft.EntityFrameworkCore.Storage; using Microsoft.EntityFrameworkCore.Utilities; +using CA = System.Diagnostics.CodeAnalysis; + +#nullable enable namespace Microsoft.EntityFrameworkCore.Metadata.Internal { @@ -21,8 +24,8 @@ namespace Microsoft.EntityFrameworkCore.Metadata.Internal /// public class DbFunctionParameter : ConventionAnnotatable, IMutableDbFunctionParameter, IConventionDbFunctionParameter { - private string _storeType; - private RelationalTypeMapping _typeMapping; + private string? _storeType; + private RelationalTypeMapping? _typeMapping; private bool _propagatesNullability; private ConfigurationSource? _storeTypeConfigurationSource; @@ -47,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); } /// @@ -56,10 +59,10 @@ public DbFunctionParameter( /// any release. You should only use it directly in your 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 InternalDbFunctionParameterBuilder Builder { get; } + public virtual InternalDbFunctionParameterBuilder? Builder { get; } /// - IConventionDbFunctionParameterBuilder IConventionDbFunctionParameter.Builder + IConventionDbFunctionParameterBuilder? IConventionDbFunctionParameter.Builder => Builder; /// @@ -108,7 +111,7 @@ public virtual ConfigurationSource GetConfigurationSource() /// any release. You should only use it directly in your 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 StoreType + public virtual string? StoreType { get => _storeType ?? TypeMapping?.StoreType; set => SetStoreType(value, ConfigurationSource.Explicit); @@ -120,7 +123,7 @@ public virtual string StoreType /// any release. You should only use it directly in your 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 SetStoreType([CanBeNull] string storeType, ConfigurationSource configurationSource) + public virtual string? SetStoreType([CanBeNull] string? storeType, ConfigurationSource configurationSource) { _storeType = storeType; @@ -140,7 +143,7 @@ public virtual string SetStoreType([CanBeNull] string storeType, ConfigurationSo /// [DebuggerStepThrough] - string IConventionDbFunctionParameter.SetStoreType(string storeType, bool fromDataAnnotation) + string? IConventionDbFunctionParameter.SetStoreType(string? storeType, bool fromDataAnnotation) => SetStoreType(storeType, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// @@ -149,20 +152,24 @@ string IConventionDbFunctionParameter.SetStoreType(string storeType, 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. /// - public virtual RelationalTypeMapping TypeMapping + public virtual RelationalTypeMapping? TypeMapping { get => _typeMapping; set => SetTypeMapping(value, ConfigurationSource.Explicit); } + // Model validation ensures all parameters have a type mapping + RelationalTypeMapping IDbFunctionParameter.TypeMapping + => _typeMapping!; + /// /// 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 RelationalTypeMapping SetTypeMapping( - [NotNull] RelationalTypeMapping typeMapping, + public virtual RelationalTypeMapping? SetTypeMapping( + [CanBeNull] RelationalTypeMapping? typeMapping, ConfigurationSource configurationSource) { _typeMapping = typeMapping; @@ -222,12 +229,7 @@ public virtual bool SetPropagatesNullability(bool propagatesNullability, Configu => _typeMappingConfigurationSource; /// - [DebuggerStepThrough] - RelationalTypeMapping IConventionDbFunctionParameter.SetTypeMapping(RelationalTypeMapping typeMapping, bool fromDataAnnotation) - => SetTypeMapping(typeMapping, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); - - /// - public virtual IStoreFunctionParameter StoreFunctionParameter { get; [param: NotNull] set; } + public virtual IStoreFunctionParameter StoreFunctionParameter { get; [param: NotNull] set; } = default!; /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -237,5 +239,14 @@ RelationalTypeMapping IConventionDbFunctionParameter.SetTypeMapping(RelationalTy /// public override string ToString() => this.ToDebugString(MetadataDebugStringOptions.SingleLineDefault); + + /// + [DebuggerStepThrough] + RelationalTypeMapping? IConventionDbFunctionParameter.SetTypeMapping(RelationalTypeMapping? typeMapping, bool fromDataAnnotation) + => SetTypeMapping(typeMapping, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); + + /// + string IDbFunctionParameter.StoreType + => StoreType!; // Model validation ensures all parameters have a type mapping } } diff --git a/src/EFCore.Relational/Metadata/Internal/ForeignKeyConstraint.cs b/src/EFCore.Relational/Metadata/Internal/ForeignKeyConstraint.cs index 64709dfb89f..c1e91a86391 100644 --- a/src/EFCore.Relational/Metadata/Internal/ForeignKeyConstraint.cs +++ b/src/EFCore.Relational/Metadata/Internal/ForeignKeyConstraint.cs @@ -6,6 +6,8 @@ using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Migrations; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Internal { /// diff --git a/src/EFCore.Relational/Metadata/Internal/ForeignKeyConstraintComparer.cs b/src/EFCore.Relational/Metadata/Internal/ForeignKeyConstraintComparer.cs index a45f5f54522..ce4c6c3d82b 100644 --- a/src/EFCore.Relational/Metadata/Internal/ForeignKeyConstraintComparer.cs +++ b/src/EFCore.Relational/Metadata/Internal/ForeignKeyConstraintComparer.cs @@ -4,6 +4,8 @@ using System; using System.Collections.Generic; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Internal { /// @@ -33,8 +35,23 @@ private ForeignKeyConstraintComparer() /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public int Compare(IForeignKeyConstraint x, IForeignKeyConstraint y) + public int Compare(IForeignKeyConstraint? x, IForeignKeyConstraint? y) { + if (ReferenceEquals(x, y)) + { + return 0; + } + + if (x is null) + { + return -1; + } + + if (y is null) + { + return 1; + } + var result = StringComparer.Ordinal.Compare(x.Name, y.Name); if (result != 0) { @@ -63,7 +80,7 @@ public int Compare(IForeignKeyConstraint x, IForeignKeyConstraint y) /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public bool Equals(IForeignKeyConstraint x, IForeignKeyConstraint y) + public bool Equals(IForeignKeyConstraint? x, IForeignKeyConstraint? y) => Compare(x, y) == 0; /// diff --git a/src/EFCore.Relational/Metadata/Internal/FunctionColumn.cs b/src/EFCore.Relational/Metadata/Internal/FunctionColumn.cs index 49a5aa10740..fcbbe265bad 100644 --- a/src/EFCore.Relational/Metadata/Internal/FunctionColumn.cs +++ b/src/EFCore.Relational/Metadata/Internal/FunctionColumn.cs @@ -7,6 +7,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Infrastructure; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Internal { /// diff --git a/src/EFCore.Relational/Metadata/Internal/FunctionColumnMapping.cs b/src/EFCore.Relational/Metadata/Internal/FunctionColumnMapping.cs index eedb18126dc..8dcafbee728 100644 --- a/src/EFCore.Relational/Metadata/Internal/FunctionColumnMapping.cs +++ b/src/EFCore.Relational/Metadata/Internal/FunctionColumnMapping.cs @@ -6,6 +6,8 @@ using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Storage; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Internal { /// diff --git a/src/EFCore.Relational/Metadata/Internal/FunctionMapping.cs b/src/EFCore.Relational/Metadata/Internal/FunctionMapping.cs index 35670ece875..eb11d503d3c 100644 --- a/src/EFCore.Relational/Metadata/Internal/FunctionMapping.cs +++ b/src/EFCore.Relational/Metadata/Internal/FunctionMapping.cs @@ -7,6 +7,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Infrastructure; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Internal { /// diff --git a/src/EFCore.Relational/Metadata/Internal/InternalDbFunctionBuilder.cs b/src/EFCore.Relational/Metadata/Internal/InternalDbFunctionBuilder.cs index fd4e53fb1bb..09e6840c0d0 100644 --- a/src/EFCore.Relational/Metadata/Internal/InternalDbFunctionBuilder.cs +++ b/src/EFCore.Relational/Metadata/Internal/InternalDbFunctionBuilder.cs @@ -12,6 +12,8 @@ using Microsoft.EntityFrameworkCore.Query.SqlExpressions; using Microsoft.EntityFrameworkCore.Storage; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Builders.Internal { /// @@ -39,7 +41,7 @@ public InternalDbFunctionBuilder([NotNull] DbFunction function, [NotNull] IConve /// any release. You should only use it directly in your 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 IConventionDbFunctionBuilder HasName([CanBeNull] string name, ConfigurationSource configurationSource) + public virtual IConventionDbFunctionBuilder? HasName([CanBeNull] string? name, ConfigurationSource configurationSource) { if (CanSetName(name, configurationSource)) { @@ -56,7 +58,7 @@ public virtual IConventionDbFunctionBuilder HasName([CanBeNull] string name, 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 bool CanSetName([CanBeNull] string name, ConfigurationSource configurationSource) + public virtual bool CanSetName([CanBeNull] string? name, ConfigurationSource configurationSource) => (name != "" || configurationSource == ConfigurationSource.Explicit) && (configurationSource.Overrides(Metadata.GetNameConfigurationSource()) || Metadata.Name == name); @@ -67,7 +69,7 @@ public virtual bool CanSetName([CanBeNull] 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 virtual IConventionDbFunctionBuilder HasSchema([CanBeNull] string schema, ConfigurationSource configurationSource) + public virtual IConventionDbFunctionBuilder? HasSchema([CanBeNull] string? schema, ConfigurationSource configurationSource) { if (CanSetSchema(schema, configurationSource)) { @@ -84,7 +86,7 @@ public virtual IConventionDbFunctionBuilder HasSchema([CanBeNull] string schema, /// any release. You should only use it directly in your 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 CanSetSchema([CanBeNull] string schema, ConfigurationSource configurationSource) + public virtual bool CanSetSchema([CanBeNull] string? schema, ConfigurationSource configurationSource) => configurationSource.Overrides(Metadata.GetSchemaConfigurationSource()) || Metadata.Schema == schema; @@ -94,7 +96,7 @@ public virtual bool CanSetSchema([CanBeNull] string schema, 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 IConventionDbFunctionBuilder IsBuiltIn(bool builtIn, ConfigurationSource configurationSource) + public virtual IConventionDbFunctionBuilder? IsBuiltIn(bool builtIn, ConfigurationSource configurationSource) { if (CanSetIsBuiltIn(builtIn, configurationSource)) { @@ -121,7 +123,7 @@ public virtual bool CanSetIsBuiltIn(bool builtIn, 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 IConventionDbFunctionBuilder IsNullable(bool nullable, ConfigurationSource configurationSource) + public virtual IConventionDbFunctionBuilder? IsNullable(bool nullable, ConfigurationSource configurationSource) { if (CanSetIsNullable(nullable, configurationSource)) { @@ -148,7 +150,7 @@ public virtual bool CanSetIsNullable(bool nullable, 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 IConventionDbFunctionBuilder HasStoreType([CanBeNull] string storeType, ConfigurationSource configurationSource) + public virtual IConventionDbFunctionBuilder? HasStoreType([CanBeNull] string? storeType, ConfigurationSource configurationSource) { if (CanSetStoreType(storeType, configurationSource)) { @@ -165,7 +167,7 @@ public virtual IConventionDbFunctionBuilder HasStoreType([CanBeNull] string stor /// any release. You should only use it directly in your 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 CanSetStoreType([CanBeNull] string storeType, ConfigurationSource configurationSource) + public virtual bool CanSetStoreType([CanBeNull] string? storeType, ConfigurationSource configurationSource) => configurationSource.Overrides(Metadata.GetStoreTypeConfigurationSource()) || Metadata.StoreType == storeType; @@ -175,8 +177,8 @@ public virtual bool CanSetStoreType([CanBeNull] string storeType, 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 IConventionDbFunctionBuilder HasTypeMapping( - [CanBeNull] RelationalTypeMapping returnTypeMapping, + public virtual IConventionDbFunctionBuilder? HasTypeMapping( + [CanBeNull] RelationalTypeMapping? returnTypeMapping, ConfigurationSource configurationSource) { if (CanSetTypeMapping(returnTypeMapping, configurationSource)) @@ -194,7 +196,7 @@ public virtual IConventionDbFunctionBuilder 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] RelationalTypeMapping returnTypeMapping, ConfigurationSource configurationSource) + public virtual bool CanSetTypeMapping([CanBeNull] RelationalTypeMapping? returnTypeMapping, ConfigurationSource configurationSource) => configurationSource.Overrides(Metadata.GetTypeMappingConfigurationSource()) || Metadata.TypeMapping == returnTypeMapping; @@ -204,8 +206,8 @@ public virtual bool CanSetTypeMapping([CanBeNull] RelationalTypeMapping returnTy /// any release. You should only use it directly in your 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 IConventionDbFunctionBuilder HasTranslation( - [CanBeNull] Func, SqlExpression> translation, + public virtual IConventionDbFunctionBuilder? HasTranslation( + [CanBeNull] Func, SqlExpression>? translation, ConfigurationSource configurationSource) { if (CanSetTranslation(translation, configurationSource)) @@ -224,7 +226,7 @@ public virtual IConventionDbFunctionBuilder HasTranslation( /// doing so can result in application failures when updating to a new Entity Framework Core release. /// public virtual bool CanSetTranslation( - [CanBeNull] Func, SqlExpression> translation, + [CanBeNull] Func, SqlExpression>? translation, ConfigurationSource configurationSource) => (Metadata.IsScalar && !Metadata.IsAggregate || configurationSource == ConfigurationSource.Explicit) && (configurationSource.Overrides(Metadata.GetTranslationConfigurationSource()) @@ -242,10 +244,10 @@ public virtual InternalDbFunctionParameterBuilder HasParameter([NotNull] string if (parameter == null) { throw new ArgumentException( - RelationalStrings.DbFunctionInvalidParameterName(Metadata.MethodInfo.DisplayName(), name)); + RelationalStrings.DbFunctionInvalidParameterName(Metadata.MethodInfo?.DisplayName(), name)); } - return parameter.Builder; + return parameter.Builder!; } IConventionDbFunction IConventionDbFunctionBuilder.Metadata @@ -256,7 +258,7 @@ 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); /// @@ -266,7 +268,7 @@ bool IConventionDbFunctionBuilder.CanSetName(string name, bool fromDataAnnotatio /// [DebuggerStepThrough] - IConventionDbFunctionBuilder IConventionDbFunctionBuilder.HasSchema(string schema, bool fromDataAnnotation) + IConventionDbFunctionBuilder? IConventionDbFunctionBuilder.HasSchema(string schema, bool fromDataAnnotation) => HasSchema(schema, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// @@ -276,7 +278,7 @@ bool IConventionDbFunctionBuilder.CanSetSchema(string schema, bool fromDataAnnot /// [DebuggerStepThrough] - IConventionDbFunctionBuilder IConventionDbFunctionBuilder.IsBuiltIn(bool builtIn, bool fromDataAnnotation) + IConventionDbFunctionBuilder? IConventionDbFunctionBuilder.IsBuiltIn(bool builtIn, bool fromDataAnnotation) => IsBuiltIn(builtIn, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// @@ -286,7 +288,7 @@ bool IConventionDbFunctionBuilder.CanSetIsBuiltIn(bool builtIn, bool fromDataAnn /// [DebuggerStepThrough] - IConventionDbFunctionBuilder IConventionDbFunctionBuilder.IsNullable(bool nullable, bool fromDataAnnotation) + IConventionDbFunctionBuilder? IConventionDbFunctionBuilder.IsNullable(bool nullable, bool fromDataAnnotation) => IsNullable(nullable, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// @@ -296,7 +298,7 @@ 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); /// @@ -306,7 +308,7 @@ bool IConventionDbFunctionBuilder.CanSetStoreType(string storeType, bool fromDat /// [DebuggerStepThrough] - IConventionDbFunctionBuilder IConventionDbFunctionBuilder.HasTypeMapping(RelationalTypeMapping typeMapping, bool fromDataAnnotation) + IConventionDbFunctionBuilder? IConventionDbFunctionBuilder.HasTypeMapping(RelationalTypeMapping typeMapping, bool fromDataAnnotation) => HasTypeMapping(typeMapping, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// @@ -316,7 +318,7 @@ bool IConventionDbFunctionBuilder.CanSetTypeMapping(RelationalTypeMapping typeMa /// [DebuggerStepThrough] - IConventionDbFunctionBuilder IConventionDbFunctionBuilder.HasTranslation( + IConventionDbFunctionBuilder? IConventionDbFunctionBuilder.HasTranslation( Func, SqlExpression> translation, bool fromDataAnnotation) => HasTranslation(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 03f70ced2f9..8b517209726 100644 --- a/src/EFCore.Relational/Metadata/Internal/InternalDbFunctionParameterBuilder.cs +++ b/src/EFCore.Relational/Metadata/Internal/InternalDbFunctionParameterBuilder.cs @@ -7,6 +7,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Internal; using Microsoft.EntityFrameworkCore.Storage; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Builders.Internal { /// @@ -39,8 +41,8 @@ public InternalDbFunctionParameterBuilder([NotNull] DbFunctionParameter paramete /// any release. You should only use it directly in your 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 IConventionDbFunctionParameterBuilder HasStoreType( - [CanBeNull] string storeType, + public virtual IConventionDbFunctionParameterBuilder? HasStoreType( + [CanBeNull] string? storeType, ConfigurationSource configurationSource) { if (CanSetStoreType(storeType, configurationSource)) @@ -58,7 +60,7 @@ public virtual IConventionDbFunctionParameterBuilder HasStoreType( /// any release. You should only use it directly in your 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 CanSetStoreType([CanBeNull] string storeType, ConfigurationSource configurationSource) + public virtual bool CanSetStoreType([CanBeNull] string? storeType, ConfigurationSource configurationSource) => configurationSource.Overrides(Metadata.GetStoreTypeConfigurationSource()) || Metadata.StoreType == storeType; @@ -68,8 +70,8 @@ public virtual bool CanSetStoreType([CanBeNull] string storeType, 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 IConventionDbFunctionParameterBuilder HasTypeMapping( - [CanBeNull] RelationalTypeMapping typeMapping, + public virtual IConventionDbFunctionParameterBuilder? HasTypeMapping( + [CanBeNull] RelationalTypeMapping? typeMapping, ConfigurationSource configurationSource) { if (CanSetTypeMapping(typeMapping, configurationSource)) @@ -87,7 +89,7 @@ public virtual IConventionDbFunctionParameterBuilder 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] RelationalTypeMapping typeMapping, ConfigurationSource configurationSource) + public virtual bool CanSetTypeMapping([CanBeNull] RelationalTypeMapping? typeMapping, ConfigurationSource configurationSource) => configurationSource.Overrides(Metadata.GetTypeMappingConfigurationSource()) || Metadata.TypeMapping == typeMapping; @@ -97,7 +99,7 @@ public virtual bool CanSetTypeMapping([CanBeNull] RelationalTypeMapping typeMapp /// any release. You should only use it directly in your 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 IConventionDbFunctionParameterBuilder PropagatesNullability( + public virtual IConventionDbFunctionParameterBuilder? PropagatesNullability( bool propagatesNullability, ConfigurationSource configurationSource) { @@ -129,7 +131,7 @@ 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); /// @@ -139,7 +141,7 @@ bool IConventionDbFunctionParameterBuilder.CanSetStoreType(string storeType, boo /// [DebuggerStepThrough] - IConventionDbFunctionParameterBuilder IConventionDbFunctionParameterBuilder.HasTypeMapping( + IConventionDbFunctionParameterBuilder? IConventionDbFunctionParameterBuilder.HasTypeMapping( RelationalTypeMapping typeMapping, bool fromDataAnnotation) => HasTypeMapping(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 92eeab8ebb7..edfef805cbe 100644 --- a/src/EFCore.Relational/Metadata/Internal/InternalSequenceBuilder.cs +++ b/src/EFCore.Relational/Metadata/Internal/InternalSequenceBuilder.cs @@ -8,6 +8,8 @@ using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata.Internal; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Builders.Internal { /// @@ -35,7 +37,7 @@ public InternalSequenceBuilder([NotNull] Sequence sequence, [NotNull] IConventio /// any release. You should only use it directly in your 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 IConventionSequenceBuilder HasType([CanBeNull] Type type, ConfigurationSource configurationSource) + public virtual IConventionSequenceBuilder? HasType([CanBeNull] Type? type, ConfigurationSource configurationSource) { if (configurationSource.Overrides(Metadata.GetTypeConfigurationSource()) || Metadata.Type == type) @@ -53,7 +55,7 @@ public virtual IConventionSequenceBuilder HasType([CanBeNull] Type type, 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 bool CanSetType([CanBeNull] Type type, ConfigurationSource configurationSource) + public virtual bool CanSetType([CanBeNull] Type? type, ConfigurationSource configurationSource) => (type == null || Sequence.SupportedTypes.Contains(type)) && (configurationSource.Overrides(Metadata.GetTypeConfigurationSource()) || Metadata.Type == type); @@ -64,7 +66,7 @@ public virtual bool CanSetType([CanBeNull] Type type, 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 IConventionSequenceBuilder IncrementsBy( + public virtual IConventionSequenceBuilder? IncrementsBy( int? increment, ConfigurationSource configurationSource) { @@ -93,7 +95,7 @@ public virtual bool CanSetIncrementsBy(int? increment, ConfigurationSource confi /// any release. You should only use it directly in your 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 IConventionSequenceBuilder StartsAt(long? startValue, ConfigurationSource configurationSource) + public virtual IConventionSequenceBuilder? StartsAt(long? startValue, ConfigurationSource configurationSource) { if (CanSetStartsAt(startValue, configurationSource)) { @@ -120,7 +122,7 @@ public virtual bool CanSetStartsAt(long? startValue, 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 IConventionSequenceBuilder HasMax(long? maximum, ConfigurationSource configurationSource) + public virtual IConventionSequenceBuilder? HasMax(long? maximum, ConfigurationSource configurationSource) { if (CanSetMax(maximum, configurationSource)) { @@ -147,7 +149,7 @@ public virtual bool CanSetMax(long? maximum, 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 IConventionSequenceBuilder HasMin(long? minimum, ConfigurationSource configurationSource) + public virtual IConventionSequenceBuilder? HasMin(long? minimum, ConfigurationSource configurationSource) { if (CanSetMin(minimum, configurationSource)) { @@ -174,7 +176,7 @@ public virtual bool CanSetMin(long? minimum, 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 IConventionSequenceBuilder IsCyclic(bool? cyclic, ConfigurationSource configurationSource) + public virtual IConventionSequenceBuilder? IsCyclic(bool? cyclic, ConfigurationSource configurationSource) { if (CanSetIsCyclic(cyclic, configurationSource)) { @@ -204,7 +206,7 @@ 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); /// @@ -214,7 +216,7 @@ bool IConventionSequenceBuilder.CanSetType(Type type, bool fromDataAnnotation) /// [DebuggerStepThrough] - IConventionSequenceBuilder IConventionSequenceBuilder.IncrementsBy(int? increment, bool fromDataAnnotation) + IConventionSequenceBuilder? IConventionSequenceBuilder.IncrementsBy(int? increment, bool fromDataAnnotation) => IncrementsBy(increment, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// @@ -224,7 +226,7 @@ bool IConventionSequenceBuilder.CanSetIncrementsBy(int? increment, bool fromData /// [DebuggerStepThrough] - IConventionSequenceBuilder IConventionSequenceBuilder.StartsAt(long? startValue, bool fromDataAnnotation) + IConventionSequenceBuilder? IConventionSequenceBuilder.StartsAt(long? startValue, bool fromDataAnnotation) => StartsAt(startValue, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// @@ -234,7 +236,7 @@ bool IConventionSequenceBuilder.CanSetStartsAt(long? startValue, bool fromDataAn /// [DebuggerStepThrough] - IConventionSequenceBuilder IConventionSequenceBuilder.HasMax(long? maximum, bool fromDataAnnotation) + IConventionSequenceBuilder? IConventionSequenceBuilder.HasMax(long? maximum, bool fromDataAnnotation) => HasMax(maximum, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// @@ -244,7 +246,7 @@ bool IConventionSequenceBuilder.CanSetMax(long? maximum, bool fromDataAnnotation /// [DebuggerStepThrough] - IConventionSequenceBuilder IConventionSequenceBuilder.HasMin(long? minimum, bool fromDataAnnotation) + IConventionSequenceBuilder? IConventionSequenceBuilder.HasMin(long? minimum, bool fromDataAnnotation) => HasMin(minimum, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// @@ -254,7 +256,7 @@ bool IConventionSequenceBuilder.CanSetMin(long? minimum, bool fromDataAnnotation /// [DebuggerStepThrough] - IConventionSequenceBuilder IConventionSequenceBuilder.IsCyclic(bool? cyclic, bool fromDataAnnotation) + IConventionSequenceBuilder? IConventionSequenceBuilder.IsCyclic(bool? cyclic, bool fromDataAnnotation) => IsCyclic(cyclic, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// diff --git a/src/EFCore.Relational/Metadata/Internal/NamedListComparer.cs b/src/EFCore.Relational/Metadata/Internal/NamedListComparer.cs index 351c1bebe10..a6ceb958375 100644 --- a/src/EFCore.Relational/Metadata/Internal/NamedListComparer.cs +++ b/src/EFCore.Relational/Metadata/Internal/NamedListComparer.cs @@ -4,6 +4,8 @@ using System; using System.Collections.Generic; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Internal { /// @@ -13,8 +15,8 @@ namespace Microsoft.EntityFrameworkCore.Metadata.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// // Sealed for perf - public sealed class NamedListComparer : IComparer<(string, string, IReadOnlyList)>, - IEqualityComparer<(string, string, IReadOnlyList)> + public sealed class NamedListComparer : IComparer<(string, string?, IReadOnlyList)>, + IEqualityComparer<(string, string?, IReadOnlyList)> { /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -34,7 +36,7 @@ private NamedListComparer() /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public int Compare((string, string, IReadOnlyList) x, (string, string, IReadOnlyList) y) + public int Compare((string, string?, IReadOnlyList) x, (string, string?, IReadOnlyList) y) { var result = StringComparer.Ordinal.Compare(x.Item1, y.Item1); if (result != 0) @@ -71,7 +73,7 @@ public int Compare((string, string, IReadOnlyList) x, (string, string, 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 bool Equals((string, string, IReadOnlyList) x, (string, string, IReadOnlyList) y) + public bool Equals((string, string?, IReadOnlyList) x, (string, string?, IReadOnlyList) y) => Compare(x, y) == 0; /// @@ -80,7 +82,7 @@ public bool Equals((string, string, IReadOnlyList) x, (string, string, 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 int GetHashCode((string, string, IReadOnlyList) obj) + public int GetHashCode((string, string?, IReadOnlyList) obj) { var hash = new HashCode(); hash.Add(obj.Item1); diff --git a/src/EFCore.Relational/Metadata/Internal/RelationalEntityTypeExtensions.cs b/src/EFCore.Relational/Metadata/Internal/RelationalEntityTypeExtensions.cs index 90cc9369f8e..764254adef4 100644 --- a/src/EFCore.Relational/Metadata/Internal/RelationalEntityTypeExtensions.cs +++ b/src/EFCore.Relational/Metadata/Internal/RelationalEntityTypeExtensions.cs @@ -5,6 +5,8 @@ using System.Linq; using JetBrains.Annotations; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Internal { /// @@ -30,7 +32,7 @@ public static class RelationalEntityTypeExtensions /// doing so can result in application failures when updating to a new Entity Framework Core release. /// public static IEnumerable GetViewOrTableMappings([NotNull] this IEntityType entityType) - => (IEnumerable)(entityType[RelationalAnnotationNames.ViewMappings] + => (IEnumerable?)(entityType[RelationalAnnotationNames.ViewMappings] ?? entityType[RelationalAnnotationNames.TableMappings]) ?? Enumerable.Empty(); diff --git a/src/EFCore.Relational/Metadata/Internal/RelationalForeignKeyExtensions.cs b/src/EFCore.Relational/Metadata/Internal/RelationalForeignKeyExtensions.cs index bd9db75eaab..1f8062934f2 100644 --- a/src/EFCore.Relational/Metadata/Internal/RelationalForeignKeyExtensions.cs +++ b/src/EFCore.Relational/Metadata/Internal/RelationalForeignKeyExtensions.cs @@ -7,6 +7,8 @@ using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Infrastructure; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Internal { /// @@ -32,17 +34,19 @@ public static bool AreCompatible( var principalType = foreignKey.PrincipalKey.IsPrimaryKey() ? foreignKey.PrincipalEntityType : foreignKey.PrincipalKey.DeclaringEntityType; - var principalTable = StoreObjectIdentifier.Create(principalType, StoreObjectType.Table); + var principalTable = StoreObjectIdentifier.Create(principalType, storeObject.StoreObjectType); var duplicatePrincipalType = duplicateForeignKey.PrincipalKey.IsPrimaryKey() ? duplicateForeignKey.PrincipalEntityType : duplicateForeignKey.PrincipalKey.DeclaringEntityType; - var duplicatePrincipalTable = StoreObjectIdentifier.Create(duplicatePrincipalType, StoreObjectType.Table); + var duplicatePrincipalTable = StoreObjectIdentifier.Create(duplicatePrincipalType, storeObject.StoreObjectType); var columnNames = foreignKey.Properties.GetColumnNames(storeObject); var duplicateColumnNames = duplicateForeignKey.Properties.GetColumnNames(storeObject); - if (columnNames == null - || duplicateColumnNames == null) + if (columnNames is null + || duplicateColumnNames is null + || principalTable is null + || duplicatePrincipalTable is null) { if (shouldThrow) { @@ -52,7 +56,9 @@ public static bool AreCompatible( foreignKey.DeclaringEntityType.DisplayName(), duplicateForeignKey.Properties.Format(), duplicateForeignKey.DeclaringEntityType.DisplayName(), - foreignKey.GetConstraintName(storeObject, principalTable.Value), + principalTable.HasValue + ? foreignKey.GetConstraintName(storeObject, principalTable.Value) + : foreignKey.GetDefaultName(), foreignKey.DeclaringEntityType.GetSchemaQualifiedTableName(), duplicateForeignKey.DeclaringEntityType.GetSchemaQualifiedTableName())); } diff --git a/src/EFCore.Relational/Metadata/Internal/RelationalIndexExtensions.cs b/src/EFCore.Relational/Metadata/Internal/RelationalIndexExtensions.cs index 13b31f93e23..df8f09a8b22 100644 --- a/src/EFCore.Relational/Metadata/Internal/RelationalIndexExtensions.cs +++ b/src/EFCore.Relational/Metadata/Internal/RelationalIndexExtensions.cs @@ -7,6 +7,8 @@ using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Infrastructure; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Internal { /// diff --git a/src/EFCore.Relational/Metadata/Internal/RelationalKeyExtensions.cs b/src/EFCore.Relational/Metadata/Internal/RelationalKeyExtensions.cs index fcbd4187e91..3c0d2d11771 100644 --- a/src/EFCore.Relational/Metadata/Internal/RelationalKeyExtensions.cs +++ b/src/EFCore.Relational/Metadata/Internal/RelationalKeyExtensions.cs @@ -7,6 +7,8 @@ using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Infrastructure; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Internal { /// diff --git a/src/EFCore.Relational/Metadata/Internal/RelationalModel.cs b/src/EFCore.Relational/Metadata/Internal/RelationalModel.cs index a9aa965e667..766a03f1929 100644 --- a/src/EFCore.Relational/Metadata/Internal/RelationalModel.cs +++ b/src/EFCore.Relational/Metadata/Internal/RelationalModel.cs @@ -10,6 +10,8 @@ using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Internal { /// @@ -49,8 +51,8 @@ public RelationalModel([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 SortedDictionary<(string, string), Table> Tables { get; } - = new SortedDictionary<(string, string), Table>(); + public virtual SortedDictionary<(string, string?), Table> Tables { get; } + = new SortedDictionary<(string, string?), Table>(); /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -58,8 +60,8 @@ public RelationalModel([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 SortedDictionary<(string, string), View> Views { get; } - = new SortedDictionary<(string, string), View>(); + public virtual SortedDictionary<(string, string?), View> Views { get; } + = new SortedDictionary<(string, string?), View>(); /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -76,29 +78,29 @@ public RelationalModel([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 SortedDictionary<(string, string, IReadOnlyList), StoreFunction> Functions { get; } - = new SortedDictionary<(string, string, IReadOnlyList), StoreFunction>(NamedListComparer.Instance); + public virtual SortedDictionary<(string, string?, IReadOnlyList), StoreFunction> Functions { get; } + = new SortedDictionary<(string, string?, IReadOnlyList), StoreFunction>(NamedListComparer.Instance); /// - public virtual ITable FindTable(string name, string schema) + public virtual ITable? FindTable(string name, string? schema) => Tables.TryGetValue((name, schema), out var table) ? table : null; /// - public virtual IView FindView(string name, string schema) + public virtual IView? FindView(string name, string? schema) => Views.TryGetValue((name, schema), out var view) ? view : null; /// - public virtual ISqlQuery FindQuery(string name) + public virtual ISqlQuery? FindQuery(string name) => Queries.TryGetValue(name, out var query) ? query : null; /// - public virtual IStoreFunction FindFunction(string name, string schema, IReadOnlyList parameters) + public virtual IStoreFunction? FindFunction(string name, string? schema, IReadOnlyList parameters) => Functions.TryGetValue((name, schema, parameters), out var function) ? function : null; @@ -248,7 +250,7 @@ private static void AddDefaultMappings(RelationalModel databaseModel, IConventio continue; } - var column = (ColumnBase)defaultTable.FindColumn(columnName); + var column = (ColumnBase?)defaultTable.FindColumn(columnName); if (column == null) { column = new ColumnBase(columnName, property.GetColumnType(), defaultTable); @@ -299,7 +301,7 @@ private static void AddTables(RelationalModel databaseModel, IConventionEntityTy { var schema = entityType.GetSchema(); var mappedType = entityType; - List tableMappings = null; + List? tableMappings = null; while (mappedType != null) { var mappedTableName = mappedType.GetTableName(); @@ -342,7 +344,7 @@ private static void AddTables(RelationalModel databaseModel, IConventionEntityTy continue; } - var column = (Column)table.FindColumn(columnName); + var column = (Column?)table.FindColumn(columnName); if (column == null) { column = new Column(columnName, property.GetColumnType(mappedTable), table); @@ -386,7 +388,7 @@ private static void AddTables(RelationalModel databaseModel, IConventionEntityTy } } - tableMappings.Reverse(); + tableMappings?.Reverse(); } } @@ -399,7 +401,7 @@ private static void AddViews(RelationalModel databaseModel, IConventionEntityTyp } var schema = entityType.GetViewSchema(); - List viewMappings = null; + List? viewMappings = null; var mappedType = entityType; while (mappedType != null) { @@ -433,7 +435,7 @@ private static void AddViews(RelationalModel databaseModel, IConventionEntityTyp continue; } - var column = (ViewColumn)view.FindColumn(columnName); + var column = (ViewColumn?)view.FindColumn(columnName); if (column == null) { column = new ViewColumn(columnName, property.GetColumnType(mappedView), view); @@ -477,7 +479,7 @@ private static void AddViews(RelationalModel databaseModel, IConventionEntityTyp } } - viewMappings.Reverse(); + viewMappings?.Reverse(); } private static void AddSqlQueries(RelationalModel databaseModel, IConventionEntityType entityType) @@ -488,7 +490,7 @@ private static void AddSqlQueries(RelationalModel databaseModel, IConventionEnti return; } - List queryMappings = null; + List? queryMappings = null; var definingType = entityType; while (definingType != null) { @@ -504,6 +506,8 @@ private static void AddSqlQueries(RelationalModel databaseModel, IConventionEnti definingType = definingType.BaseType; } + Check.DebugAssert(definingType is not null, $"Could not find defining type for {entityType}"); + var mappedType = entityType; while (mappedType != null) { @@ -518,7 +522,7 @@ private static void AddSqlQueries(RelationalModel databaseModel, IConventionEnti var mappedQuery = StoreObjectIdentifier.SqlQuery(definingType); if (!databaseModel.Queries.TryGetValue(mappedQuery.Name, out var sqlQuery)) { - sqlQuery = new SqlQuery(mappedQuery.Name, databaseModel) { Sql = mappedTypeSqlQuery }; + sqlQuery = new SqlQuery(mappedQuery.Name, databaseModel, mappedTypeSqlQuery); databaseModel.Queries.Add(mappedQuery.Name, sqlQuery); } @@ -537,7 +541,7 @@ private static void AddSqlQueries(RelationalModel databaseModel, IConventionEnti continue; } - var column = (SqlQueryColumn)sqlQuery.FindColumn(columnName); + var column = (SqlQueryColumn?)sqlQuery.FindColumn(columnName); if (column == null) { column = new SqlQueryColumn(columnName, property.GetColumnType(mappedQuery), sqlQuery); @@ -581,7 +585,7 @@ private static void AddSqlQueries(RelationalModel databaseModel, IConventionEnti } } - queryMappings.Reverse(); + queryMappings?.Reverse(); } private static void AddMappedFunctions(RelationalModel databaseModel, IConventionEntityType entityType) @@ -593,7 +597,7 @@ private static void AddMappedFunctions(RelationalModel databaseModel, IConventio return; } - List functionMappings = null; + List? functionMappings = null; var mappedType = entityType; while (mappedType != null) { @@ -605,7 +609,7 @@ private static void AddMappedFunctions(RelationalModel databaseModel, IConventio break; } - var dbFunction = (DbFunction)model.FindDbFunction(mappedFunctionName); + var dbFunction = (DbFunction)model.FindDbFunction(mappedFunctionName)!; var functionMapping = CreateFunctionMapping(entityType, mappedType, dbFunction, databaseModel, @default: true); mappedType = mappedType.BaseType; @@ -625,7 +629,7 @@ private static void AddMappedFunctions(RelationalModel databaseModel, IConventio } } - functionMappings.Reverse(); + functionMappings?.Reverse(); } private static void AddTVFs(RelationalModel relationalModel) @@ -687,7 +691,7 @@ private static FunctionMapping CreateFunctionMapping( continue; } - var column = (FunctionColumn)storeFunction.FindColumn(columnName); + var column = (FunctionColumn?)storeFunction.FindColumn(columnName); if (column == null) { column = new FunctionColumn(columnName, property.GetColumnType(mappedFunction), storeFunction); @@ -719,11 +723,11 @@ private static FunctionMapping CreateFunctionMapping( private static StoreFunction GetOrCreateStoreFunction(DbFunction dbFunction, RelationalModel model) { - var storeFunction = (StoreFunction)dbFunction.StoreFunction; + var storeFunction = (StoreFunction?)dbFunction.StoreFunction; if (storeFunction == null) { - var parameterTypes = dbFunction.Parameters.Select(p => p.StoreType).ToArray(); - storeFunction = (StoreFunction)model.FindFunction(dbFunction.Name, dbFunction.Schema, parameterTypes); + var parameterTypes = dbFunction.Parameters.Select(p => p.StoreType!).ToArray(); + storeFunction = (StoreFunction?)model.FindFunction(dbFunction.Name, dbFunction.Schema, parameterTypes); if (storeFunction == null) { storeFunction = new StoreFunction(dbFunction, model); @@ -799,8 +803,11 @@ private static void PopulateConstraints(Table table) var principalColumns = new Column[foreignKey.Properties.Count]; for (var i = 0; i < principalColumns.Length; i++) { - principalColumns[i] = (Column)principalTable.FindColumn(foreignKey.PrincipalKey.Properties[i]); - if (principalColumns[i] == null) + if (principalTable.FindColumn(foreignKey.PrincipalKey.Properties[i]) is Column principalColumn) + { + principalColumns[i] = principalColumn; + } + else { principalColumns = null; break; @@ -815,8 +822,11 @@ private static void PopulateConstraints(Table table) var columns = new Column[foreignKey.Properties.Count]; for (var i = 0; i < columns.Length; i++) { - columns[i] = (Column)table.FindColumn(foreignKey.Properties[i]); - if (columns[i] == null) + if (table.FindColumn(foreignKey.Properties[i]) is Column foreignKeyColumn) + { + columns[i] = foreignKeyColumn; + } + else { columns = null; break; @@ -836,7 +846,8 @@ private static void PopulateConstraints(Table table) if (entityTypeMapping.IncludesDerivedTypes && foreignKey.DeclaringEntityType != entityType - && foreignKey.Properties.SequenceEqual(entityType.FindPrimaryKey().Properties)) + && entityType.FindPrimaryKey() is IConventionKey primaryKey + && foreignKey.Properties.SequenceEqual(primaryKey.Properties)) { // The identifying FK constraint is needed to be created only on the table that corresponds // to the declaring entity type @@ -873,8 +884,11 @@ private static void PopulateConstraints(Table table) var columns = new Column[key.Properties.Count]; for (var i = 0; i < columns.Length; i++) { - columns[i] = (Column)table.FindColumn(key.Properties[i]); - if (columns[i] == null) + if (table.FindColumn(key.Properties[i]) is Column uniqueConstraintColumn) + { + columns[i] = uniqueConstraintColumn; + } + else { columns = null; break; @@ -918,8 +932,11 @@ private static void PopulateConstraints(Table table) var columns = new Column[index.Properties.Count]; for (var i = 0; i < columns.Length; i++) { - columns[i] = (Column)table.FindColumn(index.Properties[i]); - if (columns[i] == null) + if (table.FindColumn(index.Properties[i]) is Column indexColumn) + { + columns[i] = indexColumn; + } + else { columns = null; break; @@ -950,9 +967,9 @@ private static void PopulateConstraints(Table table) private static void PopulateRowInternalForeignKeys(TableBase table) { - SortedDictionary> internalForeignKeyMap = null; - SortedDictionary> referencingInternalForeignKeyMap = null; - TableMappingBase mainMapping = null; + SortedDictionary>? internalForeignKeyMap = null; + SortedDictionary>? referencingInternalForeignKeyMap = null; + TableMappingBase? mainMapping = null; var mappedEntityTypes = new HashSet(); foreach (TableMappingBase entityTypeMapping in ((ITableBase)table).EntityTypeMappings) { @@ -970,7 +987,7 @@ private static void PopulateRowInternalForeignKeys(TableBase table) continue; } - SortedSet rowInternalForeignKeys = null; + SortedSet? rowInternalForeignKeys = null; foreach (var foreignKey in entityType.FindForeignKeys(primaryKey.Properties)) { if (foreignKey.IsUnique @@ -1033,13 +1050,16 @@ private static void PopulateRowInternalForeignKeys(TableBase table) mainMapping.IsSharedTablePrincipal = true; ((Table)mainMapping.Table).EntityTypeMappings.Add(mainTableMapping); } - else + else if (mainMapping is ViewMapping mainViewMapping) { - ((View)mainMapping.Table).EntityTypeMappings.Remove((ViewMapping)mainMapping); + ((View)mainMapping.Table).EntityTypeMappings.Remove(mainViewMapping); mainMapping.IsSharedTablePrincipal = true; - ((View)mainMapping.Table).EntityTypeMappings.Add((ViewMapping)mainMapping); + ((View)mainMapping.Table).EntityTypeMappings.Add(mainViewMapping); } + Check.DebugAssert(mainMapping is not null, + $"{nameof(mainMapping)} is neither a {nameof(TableMapping)} nor a {nameof(ViewMapping)}"); + if (referencingInternalForeignKeyMap != null) { table.ReferencingRowInternalForeignKeys = referencingInternalForeignKeyMap; diff --git a/src/EFCore.Relational/Metadata/Internal/RelationalPropertyExtensions.cs b/src/EFCore.Relational/Metadata/Internal/RelationalPropertyExtensions.cs index e3cdf226581..460b73fac53 100644 --- a/src/EFCore.Relational/Metadata/Internal/RelationalPropertyExtensions.cs +++ b/src/EFCore.Relational/Metadata/Internal/RelationalPropertyExtensions.cs @@ -4,6 +4,8 @@ using System.Diagnostics; using JetBrains.Annotations; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Internal { /// @@ -21,7 +23,7 @@ public static class RelationalPropertyExtensions /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [DebuggerStepThrough] - public static string GetConfiguredColumnType([NotNull] this IProperty property) - => (string)property[RelationalAnnotationNames.ColumnType]; + public static string? GetConfiguredColumnType([NotNull] this IProperty property) + => (string?)property[RelationalAnnotationNames.ColumnType]; } } diff --git a/src/EFCore.Relational/Metadata/Internal/RelationalPropertyOverrides.cs b/src/EFCore.Relational/Metadata/Internal/RelationalPropertyOverrides.cs index 171f2977062..50610150fb8 100644 --- a/src/EFCore.Relational/Metadata/Internal/RelationalPropertyOverrides.cs +++ b/src/EFCore.Relational/Metadata/Internal/RelationalPropertyOverrides.cs @@ -5,6 +5,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Infrastructure; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Internal { /// @@ -15,7 +17,7 @@ namespace Microsoft.EntityFrameworkCore.Metadata.Internal /// public class RelationalPropertyOverrides : ConventionAnnotatable { - private string _columnName; + private string? _columnName; private ConfigurationSource? _columnNameConfigurationSource; @@ -25,7 +27,7 @@ public class RelationalPropertyOverrides : ConventionAnnotatable /// any release. You should only use it directly in your 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 ColumnName + public virtual string? ColumnName { get => _columnName; [param: CanBeNull] @@ -38,7 +40,7 @@ public virtual string ColumnName /// any release. You should only use it directly in your 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 SetColumnName([CanBeNull] string columnName, ConfigurationSource configurationSource) + public virtual string? SetColumnName([CanBeNull] string? columnName, ConfigurationSource configurationSource) { _columnName = columnName; _columnNameConfigurationSource = configurationSource.Max(_columnNameConfigurationSource); @@ -61,9 +63,9 @@ public virtual string SetColumnName([CanBeNull] string columnName, Configuration /// any release. You should only use it directly in your 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 RelationalPropertyOverrides Find([NotNull] IProperty property, in StoreObjectIdentifier storeObject) + public static RelationalPropertyOverrides? Find([NotNull] IProperty property, in StoreObjectIdentifier storeObject) { - var tableOverrides = (SortedDictionary) + var tableOverrides = (SortedDictionary?) property[RelationalAnnotationNames.RelationalOverrides]; return tableOverrides != null && tableOverrides.TryGetValue(storeObject, out var overrides) @@ -81,7 +83,7 @@ public static RelationalPropertyOverrides GetOrCreate( [NotNull] IMutableProperty property, in StoreObjectIdentifier storeObject) { - var tableOverrides = (SortedDictionary) + var tableOverrides = (SortedDictionary?) property[RelationalAnnotationNames.RelationalOverrides]; if (tableOverrides == null) { diff --git a/src/EFCore.Relational/Metadata/Internal/Sequence.cs b/src/EFCore.Relational/Metadata/Internal/Sequence.cs index c5e6a6db270..4ba4397a891 100644 --- a/src/EFCore.Relational/Metadata/Internal/Sequence.cs +++ b/src/EFCore.Relational/Metadata/Internal/Sequence.cs @@ -13,6 +13,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Builders.Internal; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Internal { /// @@ -23,14 +25,12 @@ namespace Microsoft.EntityFrameworkCore.Metadata.Internal /// public class Sequence : ConventionAnnotatable, IMutableSequence, IConventionSequence { - private readonly IModel _model; - - private readonly string _schema; + private readonly string? _schema; private long? _startValue; private int? _incrementBy; private long? _minValue; private long? _maxValue; - private Type _type; + private Type? _type; private bool? _isCyclic; private ConfigurationSource _configurationSource; @@ -97,14 +97,14 @@ public class Sequence : ConventionAnnotatable, IMutableSequence, IConventionSequ /// public Sequence( [NotNull] string name, - [CanBeNull] string schema, + [CanBeNull] string? schema, [NotNull] IModel model, ConfigurationSource configurationSource) { Check.NotEmpty(name, nameof(name)); Check.NullButNotEmpty(schema, nameof(schema)); - _model = model; + Model = model; Name = name; _schema = schema; _configurationSource = configurationSource; @@ -123,10 +123,10 @@ public Sequence([NotNull] IModel model, [NotNull] string annotationName) Check.NotNull(model, nameof(model)); Check.NotEmpty(annotationName, nameof(annotationName)); - _model = model; + Model = model; _configurationSource = ConfigurationSource.Explicit; - var data = SequenceData.Deserialize((string)model[annotationName]); + var data = SequenceData.Deserialize((string)model[annotationName]!); Name = data.Name; _schema = data.Schema; _startValue = data.StartValue; @@ -145,7 +145,7 @@ public Sequence([NotNull] IModel model, [NotNull] string annotationName) /// doing so can result in application failures when updating to a new Entity Framework Core release. /// public static IEnumerable GetSequences([NotNull] IModel model) - => ((SortedDictionary<(string, string), Sequence>)model[RelationalAnnotationNames.Sequences]) + => ((SortedDictionary<(string, string?), Sequence>?)model[RelationalAnnotationNames.Sequences]) ?.Values ?? Enumerable.Empty(); @@ -155,9 +155,9 @@ 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 FindSequence([NotNull] IModel model, [NotNull] string name, [CanBeNull] string schema) + public static Sequence? FindSequence([NotNull] IModel model, [NotNull] string name, [CanBeNull] string? schema) { - var sequences = (SortedDictionary<(string, string), Sequence>)model[RelationalAnnotationNames.Sequences]; + var sequences = (SortedDictionary<(string, string?), Sequence>?)model[RelationalAnnotationNames.Sequences]; if (sequences == null || !sequences.TryGetValue((name, schema), out var sequence)) { @@ -173,17 +173,17 @@ public static Sequence FindSequence([NotNull] IModel model, [NotNull] string nam /// any release. You should only use it directly in your 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, + [CanBeNull] string? schema, ConfigurationSource configurationSource) { var sequence = new Sequence(name, schema, model, configurationSource); - var sequences = (SortedDictionary<(string, string), Sequence>)model[RelationalAnnotationNames.Sequences]; + var sequences = (SortedDictionary<(string, string?), Sequence>?)model[RelationalAnnotationNames.Sequences]; if (sequences == null) { - sequences = new SortedDictionary<(string, string), Sequence>(); + sequences = new SortedDictionary<(string, string?), Sequence>(); model[RelationalAnnotationNames.Sequences] = sequences; } @@ -197,7 +197,7 @@ public static Sequence AddSequence( /// any release. You should only use it directly in your 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 SetName( + public static Sequence? SetName( [NotNull] IMutableModel model, [NotNull] Sequence sequence, [NotNull] string name) @@ -206,7 +206,7 @@ public static Sequence SetName( Check.NotNull(sequence, nameof(sequence)); Check.NotEmpty(name, nameof(name)); - var sequences = (SortedDictionary<(string, string), Sequence>)model[RelationalAnnotationNames.Sequences]; + var sequences = (SortedDictionary<(string, string?), Sequence>?)model[RelationalAnnotationNames.Sequences]; var tuple = (sequence.Name, sequence.Schema); if (sequences == null || !sequences.ContainsKey(tuple)) @@ -229,9 +229,9 @@ public static Sequence SetName( /// any release. You should only use it directly in your 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 RemoveSequence([NotNull] IMutableModel model, [NotNull] string name, [CanBeNull] string schema) + public static Sequence? RemoveSequence([NotNull] IMutableModel model, [NotNull] string name, [CanBeNull] string? schema) { - var sequences = (SortedDictionary<(string, string), Sequence>)model[RelationalAnnotationNames.Sequences]; + var sequences = (SortedDictionary<(string, string?), Sequence>?)model[RelationalAnnotationNames.Sequences]; if (sequences == null || !sequences.TryGetValue((name, schema), out var sequence)) { @@ -250,7 +250,7 @@ public static Sequence RemoveSequence([NotNull] IMutableModel model, [NotNull] s /// any release. You should only use it directly in your 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 { get; private set; } /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -258,8 +258,7 @@ public static Sequence RemoveSequence([NotNull] IMutableModel model, [NotNull] s /// any release. You should only use it directly in your 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 Model - => _model; + public virtual IModel Model { get; } /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -275,7 +274,7 @@ public virtual 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 string Schema + public virtual string? Schema => _schema ?? Model.GetDefaultSchema(); /// @@ -475,7 +474,7 @@ public virtual Type Type /// any release. You should only use it directly in your 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 SetType([CanBeNull] Type type, ConfigurationSource configurationSource) + public virtual Type? SetType([CanBeNull] Type? type, ConfigurationSource configurationSource) { if (type != null && !SupportedTypes.Contains(type)) @@ -521,7 +520,7 @@ public virtual Type ClrType /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [Obsolete("Use SetType")] - public virtual Type SetClrType([CanBeNull] Type type, ConfigurationSource configurationSource) + public virtual Type? SetClrType([CanBeNull] Type? type, ConfigurationSource configurationSource) => SetType(type, configurationSource); /// @@ -587,7 +586,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; /// @@ -650,7 +649,7 @@ IConventionModel IConventionSequence.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. /// - Type IConventionSequence.SetClrType(Type type, bool fromDataAnnotation) + Type? IConventionSequence.SetClrType(Type? type, bool fromDataAnnotation) => SetType(type, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// @@ -659,7 +658,7 @@ Type IConventionSequence.SetClrType(Type type, 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. /// - Type IConventionSequence.SetType(Type type, bool fromDataAnnotation) + Type? IConventionSequence.SetType(Type? type, bool fromDataAnnotation) => SetType(type, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); /// @@ -674,9 +673,9 @@ Type IConventionSequence.SetType(Type type, bool fromDataAnnotation) [Obsolete("Don't use this in any new code")] private sealed class SequenceData { - public string Name { get; set; } + public string Name { get; set; } = default!; - public string Schema { get; set; } + public string? Schema { get; set; } public long StartValue { get; set; } @@ -686,7 +685,7 @@ private sealed class SequenceData public long? MaxValue { get; set; } - public Type ClrType { get; set; } + public Type ClrType { get; set; } = default!; public bool IsCyclic { get; set; } @@ -700,13 +699,13 @@ public static SequenceData Deserialize([NotNull] string value) // ReSharper disable PossibleInvalidOperationException var position = 0; - data.Name = ExtractValue(value, ref position); + data.Name = ExtractValue(value, ref position)!; data.Schema = ExtractValue(value, ref position); - data.StartValue = (long)AsLong(ExtractValue(value, ref position)); - data.IncrementBy = (int)AsLong(ExtractValue(value, ref position)); + data.StartValue = (long)AsLong(ExtractValue(value, ref position)!)!; + data.IncrementBy = (int)AsLong(ExtractValue(value, ref position)!)!; data.MinValue = AsLong(ExtractValue(value, ref position)); data.MaxValue = AsLong(ExtractValue(value, ref position)); - data.ClrType = AsType(ExtractValue(value, ref position)); + data.ClrType = AsType(ExtractValue(value, ref position)!); data.IsCyclic = AsBool(ExtractValue(value, ref position)); // ReSharper restore PossibleInvalidOperationException @@ -718,7 +717,7 @@ public static SequenceData Deserialize([NotNull] string value) } } - private static string ExtractValue(string value, ref int position) + private static string? ExtractValue(string value, ref int position) { position = value.IndexOf('\'', position) + 1; @@ -736,7 +735,7 @@ private static string ExtractValue(string value, ref int position) return extracted.Length == 0 ? null : extracted; } - private static long? AsLong(string value) + private static long? AsLong(string? value) => value == null ? null : (long?)long.Parse(value, CultureInfo.InvariantCulture); private static Type AsType(string value) @@ -750,16 +749,16 @@ private static Type AsType(string value) ? typeof(decimal) : typeof(byte); - private static bool AsBool(string value) + private static bool AsBool(string? value) => value != null && bool.Parse(value); - private static void EscapeAndQuote(StringBuilder builder, object value) + private static void EscapeAndQuote(StringBuilder builder, object? value) { builder.Append("'"); if (value != null) { - builder.Append(value.ToString().Replace("'", "''")); + builder.Append(value.ToString()!.Replace("'", "''")); } builder.Append("'"); diff --git a/src/EFCore.Relational/Metadata/Internal/SqlQuery.cs b/src/EFCore.Relational/Metadata/Internal/SqlQuery.cs index ecc71654d32..0f59a509c6c 100644 --- a/src/EFCore.Relational/Metadata/Internal/SqlQuery.cs +++ b/src/EFCore.Relational/Metadata/Internal/SqlQuery.cs @@ -7,6 +7,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Infrastructure; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Internal { /// @@ -23,16 +25,17 @@ public class SqlQuery : TableBase, ISqlQuery /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public SqlQuery([NotNull] string name, [NotNull] RelationalModel model) + public SqlQuery([NotNull] string name, [NotNull] RelationalModel model, [NotNull] string sql) : base(name, null, model) { + Sql = sql; } /// public virtual string Sql { get; [param: NotNull] set; } /// - public override IColumnBase FindColumn(IProperty property) + public override IColumnBase? FindColumn(IProperty property) => property.GetSqlQueryColumnMappings() .FirstOrDefault(cm => cm.TableMapping.Table == this) ?.Column; @@ -62,12 +65,12 @@ IEnumerable ISqlQuery.Columns /// [DebuggerStepThrough] - ISqlQueryColumn ISqlQuery.FindColumn(string name) - => (ISqlQueryColumn)base.FindColumn(name); + ISqlQueryColumn? ISqlQuery.FindColumn(string name) + => (ISqlQueryColumn?)base.FindColumn(name); /// [DebuggerStepThrough] - ISqlQueryColumn ISqlQuery.FindColumn(IProperty property) - => (ISqlQueryColumn)FindColumn(property); + ISqlQueryColumn? ISqlQuery.FindColumn(IProperty property) + => (ISqlQueryColumn?)FindColumn(property); } } diff --git a/src/EFCore.Relational/Metadata/Internal/SqlQueryColumn.cs b/src/EFCore.Relational/Metadata/Internal/SqlQueryColumn.cs index d54fb397b21..bcedbd595c1 100644 --- a/src/EFCore.Relational/Metadata/Internal/SqlQueryColumn.cs +++ b/src/EFCore.Relational/Metadata/Internal/SqlQueryColumn.cs @@ -7,6 +7,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Infrastructure; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Internal { /// diff --git a/src/EFCore.Relational/Metadata/Internal/SqlQueryColumnMapping.cs b/src/EFCore.Relational/Metadata/Internal/SqlQueryColumnMapping.cs index 7a84d3d937e..bb9fc36c282 100644 --- a/src/EFCore.Relational/Metadata/Internal/SqlQueryColumnMapping.cs +++ b/src/EFCore.Relational/Metadata/Internal/SqlQueryColumnMapping.cs @@ -6,6 +6,8 @@ using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Storage; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Internal { /// diff --git a/src/EFCore.Relational/Metadata/Internal/SqlQueryMapping.cs b/src/EFCore.Relational/Metadata/Internal/SqlQueryMapping.cs index a2b3107d5c8..3b5513ef6a4 100644 --- a/src/EFCore.Relational/Metadata/Internal/SqlQueryMapping.cs +++ b/src/EFCore.Relational/Metadata/Internal/SqlQueryMapping.cs @@ -7,6 +7,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Infrastructure; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Internal { /// diff --git a/src/EFCore.Relational/Metadata/Internal/StoreFunction.cs b/src/EFCore.Relational/Metadata/Internal/StoreFunction.cs index 97f5e43f41a..78a00827fc3 100644 --- a/src/EFCore.Relational/Metadata/Internal/StoreFunction.cs +++ b/src/EFCore.Relational/Metadata/Internal/StoreFunction.cs @@ -7,6 +7,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Infrastructure; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Internal { /// @@ -51,7 +53,7 @@ public StoreFunction([NotNull] DbFunction dbFunction, [NotNull] RelationalModel public virtual bool IsBuiltIn { get; } /// - public virtual string ReturnType { get; } + public virtual string? ReturnType { get; } /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -62,7 +64,7 @@ public StoreFunction([NotNull] DbFunction dbFunction, [NotNull] RelationalModel public virtual StoreFunctionParameter[] Parameters { get; } /// - public override IColumnBase FindColumn(IProperty property) + public override IColumnBase? FindColumn(IProperty property) => property.GetFunctionColumnMappings() .FirstOrDefault(cm => cm.TableMapping.Table == this) ?.Column; @@ -106,12 +108,12 @@ IEnumerable IStoreFunction.DbFunctions /// [DebuggerStepThrough] - IFunctionColumn IStoreFunction.FindColumn(string name) - => (IFunctionColumn)base.FindColumn(name); + IFunctionColumn? IStoreFunction.FindColumn(string name) + => (IFunctionColumn?)base.FindColumn(name); /// [DebuggerStepThrough] - IFunctionColumn IStoreFunction.FindColumn(IProperty property) - => (IFunctionColumn)FindColumn(property); + IFunctionColumn? IStoreFunction.FindColumn(IProperty property) + => (IFunctionColumn?)FindColumn(property); } } diff --git a/src/EFCore.Relational/Metadata/Internal/StoreFunctionParameter.cs b/src/EFCore.Relational/Metadata/Internal/StoreFunctionParameter.cs index ac1c74b394a..34761edbd30 100644 --- a/src/EFCore.Relational/Metadata/Internal/StoreFunctionParameter.cs +++ b/src/EFCore.Relational/Metadata/Internal/StoreFunctionParameter.cs @@ -6,6 +6,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Infrastructure; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Internal { /// @@ -28,7 +30,7 @@ public StoreFunctionParameter( { Function = function; Name = parameter.Name; - Type = parameter.StoreType; + Type = parameter.StoreType!; DbFunctionParameters = new List { parameter }; parameter.StoreFunctionParameter = this; } diff --git a/src/EFCore.Relational/Metadata/Internal/Table.cs b/src/EFCore.Relational/Metadata/Internal/Table.cs index cf3f0634077..fa984e07178 100644 --- a/src/EFCore.Relational/Metadata/Internal/Table.cs +++ b/src/EFCore.Relational/Metadata/Internal/Table.cs @@ -6,6 +6,9 @@ using System.Linq; using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Infrastructure; +using CA = System.Diagnostics.CodeAnalysis; + +#nullable enable namespace Microsoft.EntityFrameworkCore.Metadata.Internal { @@ -17,7 +20,7 @@ namespace Microsoft.EntityFrameworkCore.Metadata.Internal /// public class Table : TableBase, ITable { - private UniqueConstraint _primaryKey; + private UniqueConstraint? _primaryKey; /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -25,7 +28,7 @@ public class Table : TableBase, ITable /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public Table([NotNull] string name, [CanBeNull] string schema, [NotNull] RelationalModel model) + public Table([NotNull] string name, [CanBeNull] string? schema, [NotNull] RelationalModel model) : base(name, schema, model) { Columns = new SortedDictionary(new ColumnNameComparer(this)); @@ -46,10 +49,10 @@ public Table([NotNull] string name, [CanBeNull] string schema, [NotNull] Relatio /// any release. You should only use it directly in your 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 UniqueConstraint PrimaryKey + public virtual UniqueConstraint? PrimaryKey { get => _primaryKey; - [param: NotNull] + [param: CanBeNull] set { var oldPrimaryKey = _primaryKey; @@ -104,7 +107,7 @@ public virtual UniqueConstraint 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 UniqueConstraint FindUniqueConstraint([NotNull] string name) + public virtual UniqueConstraint? FindUniqueConstraint([NotNull] string name) => PrimaryKey != null && PrimaryKey.Name == name ? PrimaryKey : UniqueConstraints.TryGetValue(name, out var constraint) @@ -124,7 +127,7 @@ public virtual UniqueConstraint FindUniqueConstraint([NotNull] string name) public virtual bool IsExcludedFromMigrations { get; set; } /// - public override IColumnBase FindColumn(IProperty property) + public override IColumnBase? FindColumn(IProperty property) => property.GetTableColumnMappings() .FirstOrDefault(cm => cm.TableMapping.Table == this) ?.Column; @@ -160,7 +163,7 @@ IEnumerable ITable.ForeignKeyConstraints } /// - IPrimaryKeyConstraint ITable.PrimaryKey + IPrimaryKeyConstraint? ITable.PrimaryKey { [DebuggerStepThrough] get => PrimaryKey; @@ -182,12 +185,12 @@ IEnumerable ITable.Indexes /// [DebuggerStepThrough] - IColumn ITable.FindColumn(string name) - => (IColumn)base.FindColumn(name); + IColumn? ITable.FindColumn(string name) + => (IColumn?)base.FindColumn(name); /// [DebuggerStepThrough] - IColumn ITable.FindColumn(IProperty property) - => (IColumn)FindColumn(property); + IColumn? ITable.FindColumn(IProperty property) + => (IColumn?)FindColumn(property); } } diff --git a/src/EFCore.Relational/Metadata/Internal/TableBase.cs b/src/EFCore.Relational/Metadata/Internal/TableBase.cs index 7f865d21740..cb62f905fdf 100644 --- a/src/EFCore.Relational/Metadata/Internal/TableBase.cs +++ b/src/EFCore.Relational/Metadata/Internal/TableBase.cs @@ -8,6 +8,8 @@ using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Infrastructure; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Internal { /// @@ -24,7 +26,7 @@ public class TableBase : Annotatable, ITableBase /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public TableBase([NotNull] string name, [CanBeNull] string schema, [NotNull] RelationalModel model) + public TableBase([NotNull] string name, [CanBeNull] string? schema, [NotNull] RelationalModel model) { Schema = schema; Name = name; @@ -32,7 +34,7 @@ public TableBase([NotNull] string name, [CanBeNull] string schema, [NotNull] Rel } /// - public virtual string Schema { get; } + public virtual string? Schema { get; } /// public virtual string Name { get; } @@ -67,13 +69,13 @@ public TableBase([NotNull] string name, [CanBeNull] string schema, [NotNull] Rel = new SortedDictionary(StringComparer.Ordinal); /// - public virtual IColumnBase FindColumn(string name) + public virtual IColumnBase? FindColumn(string name) => Columns.TryGetValue(name, out var column) ? column : null; /// - public virtual IColumnBase FindColumn(IProperty property) + public virtual IColumnBase? FindColumn(IProperty property) => property.GetDefaultColumnMappings() .FirstOrDefault(cm => cm.TableMapping.Table == this) ?.Column; @@ -84,7 +86,7 @@ public virtual IColumnBase FindColumn(IProperty 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 SortedDictionary> RowInternalForeignKeys { get; [param: NotNull] set; } + public virtual SortedDictionary>? RowInternalForeignKeys { get; [param: NotNull] set; } /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -92,7 +94,7 @@ public virtual IColumnBase FindColumn(IProperty 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 SortedDictionary> ReferencingRowInternalForeignKeys + public virtual SortedDictionary>? ReferencingRowInternalForeignKeys { get; [param: NotNull] set; @@ -104,20 +106,29 @@ public virtual SortedDictionary> Referenci /// any release. You should only use it directly in your 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 Dictionary OptionalEntityTypes { get; [param: NotNull] set; } + public virtual Dictionary? OptionalEntityTypes { get; [param: NotNull] set; } /// public virtual bool IsOptional(IEntityType entityType) - => OptionalEntityTypes == null - ? GetMappedEntityType(entityType) == null - : !OptionalEntityTypes.TryGetValue(entityType, out var optional) - ? throw new InvalidOperationException(RelationalStrings.TableNotMappedEntityType(entityType.DisplayName(), Name)) - : optional; + { + if (OptionalEntityTypes == null) + { + CheckMappedEntityType(entityType); + return false; + } + + return !OptionalEntityTypes.TryGetValue(entityType, out var optional) + ? throw new InvalidOperationException(RelationalStrings.TableNotMappedEntityType(entityType.DisplayName(), Name)) + : optional; + } - private IEntityType GetMappedEntityType(IEntityType entityType) - => EntityTypeMappings.Any(m => m.EntityType == entityType) - ? entityType - : throw new InvalidOperationException(RelationalStrings.TableNotMappedEntityType(entityType.DisplayName(), Name)); + private void CheckMappedEntityType(IEntityType entityType) + { + if (EntityTypeMappings.All(m => m.EntityType != entityType)) + { + throw new InvalidOperationException(RelationalStrings.TableNotMappedEntityType(entityType.DisplayName(), Name)); + } + } /// IRelationalModel ITableBase.Model @@ -133,20 +144,28 @@ IEnumerable ITableBase.Columns /// IEnumerable ITableBase.GetRowInternalForeignKeys(IEntityType entityType) - => RowInternalForeignKeys != null - && RowInternalForeignKeys.TryGetValue(entityType, out var foreignKeys) - ? foreignKeys - : (GetMappedEntityType(entityType) == null) - ? null - : Enumerable.Empty(); + { + if (RowInternalForeignKeys != null + && RowInternalForeignKeys.TryGetValue(entityType, out var foreignKeys)) + { + return foreignKeys; + } + + CheckMappedEntityType(entityType); + return Enumerable.Empty(); + } /// IEnumerable ITableBase.GetReferencingRowInternalForeignKeys(IEntityType entityType) - => ReferencingRowInternalForeignKeys != null - && ReferencingRowInternalForeignKeys.TryGetValue(entityType, out var foreignKeys) - ? foreignKeys - : (GetMappedEntityType(entityType) == null) - ? null - : Enumerable.Empty(); + { + if (ReferencingRowInternalForeignKeys != null + && ReferencingRowInternalForeignKeys.TryGetValue(entityType, out var foreignKeys)) + { + return foreignKeys; + } + + CheckMappedEntityType(entityType); + return Enumerable.Empty(); + } } } diff --git a/src/EFCore.Relational/Metadata/Internal/TableIndex.cs b/src/EFCore.Relational/Metadata/Internal/TableIndex.cs index b58ec1de38f..b727f3fe436 100644 --- a/src/EFCore.Relational/Metadata/Internal/TableIndex.cs +++ b/src/EFCore.Relational/Metadata/Internal/TableIndex.cs @@ -5,6 +5,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Infrastructure; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Internal { /// @@ -25,7 +27,7 @@ public TableIndex( [NotNull] string name, [NotNull] Table table, [NotNull] IReadOnlyList columns, - [NotNull] string filter, + [CanBeNull] string? filter, bool unique) { Name = name; @@ -66,7 +68,7 @@ public TableIndex( public virtual bool IsUnique { get; } /// - public virtual string Filter { get; } + public virtual string? Filter { get; } /// ITable ITableIndex.Table diff --git a/src/EFCore.Relational/Metadata/Internal/TableIndexComparer.cs b/src/EFCore.Relational/Metadata/Internal/TableIndexComparer.cs index ca9a5f1ccc1..b9459d4ba60 100644 --- a/src/EFCore.Relational/Metadata/Internal/TableIndexComparer.cs +++ b/src/EFCore.Relational/Metadata/Internal/TableIndexComparer.cs @@ -4,6 +4,8 @@ using System; using System.Collections.Generic; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Internal { /// @@ -33,8 +35,23 @@ private TableIndexComparer() /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public int Compare(ITableIndex x, ITableIndex y) + public int Compare(ITableIndex? x, ITableIndex? y) { + if (ReferenceEquals(x, y)) + { + return 0; + } + + if (x is null) + { + return -1; + } + + if (y is null) + { + return 1; + } + var result = StringComparer.Ordinal.Compare(x.Name, y.Name); if (result != 0) { @@ -47,7 +64,7 @@ public int Compare(ITableIndex x, ITableIndex y) return result; } - return result != 0 ? result : StringComparer.Ordinal.Compare(x.Table.Name, y.Table.Name); + return StringComparer.Ordinal.Compare(x.Table.Name, y.Table.Name); } /// @@ -56,7 +73,7 @@ public int Compare(ITableIndex x, ITableIndex y) /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public bool Equals(ITableIndex x, ITableIndex y) + public bool Equals(ITableIndex? x, ITableIndex? y) => Compare(x, y) == 0; /// diff --git a/src/EFCore.Relational/Metadata/Internal/TableMapping.cs b/src/EFCore.Relational/Metadata/Internal/TableMapping.cs index 60ba5327263..c4ac9f99dac 100644 --- a/src/EFCore.Relational/Metadata/Internal/TableMapping.cs +++ b/src/EFCore.Relational/Metadata/Internal/TableMapping.cs @@ -7,6 +7,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Infrastructure; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Internal { /// diff --git a/src/EFCore.Relational/Metadata/Internal/TableMappingBase.cs b/src/EFCore.Relational/Metadata/Internal/TableMappingBase.cs index 31bc4ae9412..88d4b29d556 100644 --- a/src/EFCore.Relational/Metadata/Internal/TableMappingBase.cs +++ b/src/EFCore.Relational/Metadata/Internal/TableMappingBase.cs @@ -6,6 +6,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Infrastructure; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Internal { /// diff --git a/src/EFCore.Relational/Metadata/Internal/TableMappingBaseComparer.cs b/src/EFCore.Relational/Metadata/Internal/TableMappingBaseComparer.cs index f5c56acc36b..0327a0b3d3b 100644 --- a/src/EFCore.Relational/Metadata/Internal/TableMappingBaseComparer.cs +++ b/src/EFCore.Relational/Metadata/Internal/TableMappingBaseComparer.cs @@ -5,6 +5,8 @@ using System.Collections.Generic; using System.Linq; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Internal { /// @@ -34,8 +36,23 @@ private TableMappingBaseComparer() /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public int Compare(ITableMappingBase x, ITableMappingBase y) + public int Compare(ITableMappingBase? x, ITableMappingBase? y) { + if (ReferenceEquals(x, y)) + { + return 0; + } + + if (x is null) + { + return -1; + } + + if (y is null) + { + return 1; + } + var result = y.IsSharedTablePrincipal.CompareTo(x.IsSharedTablePrincipal); if (result != 0) { @@ -93,11 +110,11 @@ public int Compare(ITableMappingBase x, ITableMappingBase y) /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public bool Equals(ITableMappingBase x, ITableMappingBase y) - => x.EntityType == y.EntityType + public bool Equals(ITableMappingBase? x, ITableMappingBase? y) + => ReferenceEquals(x, y) || x is not null && y is not null && (x.EntityType == y.EntityType && x.Table == y.Table && x.IncludesDerivedTypes == y.IncludesDerivedTypes - && x.ColumnMappings.SequenceEqual(y.ColumnMappings); + && x.ColumnMappings.SequenceEqual(y.ColumnMappings)); /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to diff --git a/src/EFCore.Relational/Metadata/Internal/UniqueConstraint.cs b/src/EFCore.Relational/Metadata/Internal/UniqueConstraint.cs index fb25f3f83ff..8cb6fa0e8ab 100644 --- a/src/EFCore.Relational/Metadata/Internal/UniqueConstraint.cs +++ b/src/EFCore.Relational/Metadata/Internal/UniqueConstraint.cs @@ -5,6 +5,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Infrastructure; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Internal { /// diff --git a/src/EFCore.Relational/Metadata/Internal/UniqueConstraintComparer.cs b/src/EFCore.Relational/Metadata/Internal/UniqueConstraintComparer.cs index e1bb04edd58..27fef6bf89e 100644 --- a/src/EFCore.Relational/Metadata/Internal/UniqueConstraintComparer.cs +++ b/src/EFCore.Relational/Metadata/Internal/UniqueConstraintComparer.cs @@ -4,6 +4,8 @@ using System; using System.Collections.Generic; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Internal { /// @@ -33,8 +35,23 @@ private UniqueConstraintComparer() /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public int Compare(IUniqueConstraint x, IUniqueConstraint y) + public int Compare(IUniqueConstraint? x, IUniqueConstraint? y) { + if (ReferenceEquals(x, y)) + { + return 0; + } + + if (x is null) + { + return -1; + } + + if (y is null) + { + return 1; + } + var result = StringComparer.Ordinal.Compare(x.Name, y.Name); if (result != 0) { @@ -52,7 +69,7 @@ public int Compare(IUniqueConstraint x, IUniqueConstraint y) /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public bool Equals(IUniqueConstraint x, IUniqueConstraint y) + public bool Equals(IUniqueConstraint? x, IUniqueConstraint? y) => Compare(x, y) == 0; /// diff --git a/src/EFCore.Relational/Metadata/Internal/View.cs b/src/EFCore.Relational/Metadata/Internal/View.cs index 5d9c96d2ef2..fa93761b265 100644 --- a/src/EFCore.Relational/Metadata/Internal/View.cs +++ b/src/EFCore.Relational/Metadata/Internal/View.cs @@ -7,6 +7,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Infrastructure; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Internal { /// @@ -29,12 +31,12 @@ public View([NotNull] string name, [CanBeNull] string schema, [NotNull] Relation } /// - public virtual string ViewDefinitionSql - => (string)EntityTypeMappings.Select(m => m.EntityType[RelationalAnnotationNames.ViewDefinitionSql]) + public virtual string? ViewDefinitionSql + => (string?)EntityTypeMappings.Select(m => m.EntityType[RelationalAnnotationNames.ViewDefinitionSql]) .FirstOrDefault(d => d != null); /// - public override IColumnBase FindColumn(IProperty property) + public override IColumnBase? FindColumn(IProperty property) => property.GetViewColumnMappings() .FirstOrDefault(cm => cm.TableMapping.Table == this) ?.Column; @@ -64,12 +66,12 @@ IEnumerable IView.Columns /// [DebuggerStepThrough] - IViewColumn IView.FindColumn(string name) - => (IViewColumn)base.FindColumn(name); + IViewColumn? IView.FindColumn(string name) + => (IViewColumn?)base.FindColumn(name); /// [DebuggerStepThrough] - IViewColumn IView.FindColumn(IProperty property) - => (IViewColumn)FindColumn(property); + IViewColumn? IView.FindColumn(IProperty property) + => (IViewColumn?)FindColumn(property); } } diff --git a/src/EFCore.Relational/Metadata/Internal/ViewColumn.cs b/src/EFCore.Relational/Metadata/Internal/ViewColumn.cs index 16af9e670f1..8e9a003b6ea 100644 --- a/src/EFCore.Relational/Metadata/Internal/ViewColumn.cs +++ b/src/EFCore.Relational/Metadata/Internal/ViewColumn.cs @@ -7,6 +7,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Infrastructure; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Internal { /// diff --git a/src/EFCore.Relational/Metadata/Internal/ViewColumnMapping.cs b/src/EFCore.Relational/Metadata/Internal/ViewColumnMapping.cs index e43ba46b24c..ea7e34a8f64 100644 --- a/src/EFCore.Relational/Metadata/Internal/ViewColumnMapping.cs +++ b/src/EFCore.Relational/Metadata/Internal/ViewColumnMapping.cs @@ -6,6 +6,8 @@ using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Storage; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Internal { /// diff --git a/src/EFCore.Relational/Metadata/Internal/ViewMapping.cs b/src/EFCore.Relational/Metadata/Internal/ViewMapping.cs index 0454158bb64..01108c77c4e 100644 --- a/src/EFCore.Relational/Metadata/Internal/ViewMapping.cs +++ b/src/EFCore.Relational/Metadata/Internal/ViewMapping.cs @@ -7,6 +7,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Infrastructure; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Internal { /// diff --git a/src/EFCore.Relational/Metadata/RelationalAnnotationNames.cs b/src/EFCore.Relational/Metadata/RelationalAnnotationNames.cs index dbd82d5fd08..bbfd296fcbb 100644 --- a/src/EFCore.Relational/Metadata/RelationalAnnotationNames.cs +++ b/src/EFCore.Relational/Metadata/RelationalAnnotationNames.cs @@ -3,6 +3,8 @@ using System; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata { /// diff --git a/src/EFCore.Relational/Metadata/RelationalAnnotationProvider.cs b/src/EFCore.Relational/Metadata/RelationalAnnotationProvider.cs index d651788bf35..7e3d3150c6b 100644 --- a/src/EFCore.Relational/Metadata/RelationalAnnotationProvider.cs +++ b/src/EFCore.Relational/Metadata/RelationalAnnotationProvider.cs @@ -8,6 +8,8 @@ using Microsoft.EntityFrameworkCore.Utilities; using Microsoft.Extensions.DependencyInjection; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata { /// diff --git a/src/EFCore.Relational/Metadata/RelationalAnnotationProviderDependencies.cs b/src/EFCore.Relational/Metadata/RelationalAnnotationProviderDependencies.cs index 87318114eee..c8cd9fb5a73 100644 --- a/src/EFCore.Relational/Metadata/RelationalAnnotationProviderDependencies.cs +++ b/src/EFCore.Relational/Metadata/RelationalAnnotationProviderDependencies.cs @@ -4,6 +4,8 @@ using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.Extensions.DependencyInjection; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata { /// diff --git a/src/EFCore.Relational/Metadata/SequenceExtensions.cs b/src/EFCore.Relational/Metadata/SequenceExtensions.cs index 619f53fb72a..020b215fc90 100644 --- a/src/EFCore.Relational/Metadata/SequenceExtensions.cs +++ b/src/EFCore.Relational/Metadata/SequenceExtensions.cs @@ -5,6 +5,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Infrastructure; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata { /// diff --git a/src/EFCore.Relational/Metadata/SqlQueryColumnExtensions.cs b/src/EFCore.Relational/Metadata/SqlQueryColumnExtensions.cs index 12bbf7d1c8d..6c13c84e665 100644 --- a/src/EFCore.Relational/Metadata/SqlQueryColumnExtensions.cs +++ b/src/EFCore.Relational/Metadata/SqlQueryColumnExtensions.cs @@ -5,6 +5,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Infrastructure; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata { /// diff --git a/src/EFCore.Relational/Metadata/SqlQueryColumnMappingExtensions.cs b/src/EFCore.Relational/Metadata/SqlQueryColumnMappingExtensions.cs index f320d06a632..2cd98627b46 100644 --- a/src/EFCore.Relational/Metadata/SqlQueryColumnMappingExtensions.cs +++ b/src/EFCore.Relational/Metadata/SqlQueryColumnMappingExtensions.cs @@ -5,6 +5,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Infrastructure; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata { /// diff --git a/src/EFCore.Relational/Metadata/SqlQueryExtensions.cs b/src/EFCore.Relational/Metadata/SqlQueryExtensions.cs index e58e2e28654..18c558f4518 100644 --- a/src/EFCore.Relational/Metadata/SqlQueryExtensions.cs +++ b/src/EFCore.Relational/Metadata/SqlQueryExtensions.cs @@ -6,6 +6,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Infrastructure; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata { /// diff --git a/src/EFCore.Relational/Metadata/SqlQueryMappingExtensions.cs b/src/EFCore.Relational/Metadata/SqlQueryMappingExtensions.cs index dbdcd3d04ba..eaec8f52469 100644 --- a/src/EFCore.Relational/Metadata/SqlQueryMappingExtensions.cs +++ b/src/EFCore.Relational/Metadata/SqlQueryMappingExtensions.cs @@ -5,6 +5,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Infrastructure; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata { /// diff --git a/src/EFCore.Relational/Metadata/StoreFunctionExtensions.cs b/src/EFCore.Relational/Metadata/StoreFunctionExtensions.cs index c47a6b836cc..2b5433ad44e 100644 --- a/src/EFCore.Relational/Metadata/StoreFunctionExtensions.cs +++ b/src/EFCore.Relational/Metadata/StoreFunctionExtensions.cs @@ -6,6 +6,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Infrastructure; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata { /// diff --git a/src/EFCore.Relational/Metadata/StoreFunctionParameterExtensions.cs b/src/EFCore.Relational/Metadata/StoreFunctionParameterExtensions.cs index e2496ae3257..2f3451f0109 100644 --- a/src/EFCore.Relational/Metadata/StoreFunctionParameterExtensions.cs +++ b/src/EFCore.Relational/Metadata/StoreFunctionParameterExtensions.cs @@ -5,6 +5,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Infrastructure; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata { /// diff --git a/src/EFCore.Relational/Metadata/StoreObjectIdentifier.cs b/src/EFCore.Relational/Metadata/StoreObjectIdentifier.cs index fab8fe1ecfc..dafaec08afa 100644 --- a/src/EFCore.Relational/Metadata/StoreObjectIdentifier.cs +++ b/src/EFCore.Relational/Metadata/StoreObjectIdentifier.cs @@ -5,6 +5,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata { /// @@ -12,7 +14,7 @@ namespace Microsoft.EntityFrameworkCore.Metadata /// public readonly struct StoreObjectIdentifier : IComparable, IEquatable { - private StoreObjectIdentifier(StoreObjectType storeObjectType, string name, string schema = null) + private StoreObjectIdentifier(StoreObjectType storeObjectType, string name, string? schema = null) { StoreObjectType = storeObjectType; Name = name; @@ -54,7 +56,7 @@ private StoreObjectIdentifier(StoreObjectType storeObjectType, string name, stri /// The table name. /// The table schema. /// The table id. - public static StoreObjectIdentifier Table([NotNull] string name, [CanBeNull] string schema) + public static StoreObjectIdentifier Table([NotNull] string name, [CanBeNull] string? schema) { Check.NotNull(name, nameof(name)); @@ -67,7 +69,7 @@ public static StoreObjectIdentifier Table([NotNull] string name, [CanBeNull] str /// The view name. /// The view schema. /// The view id. - public static StoreObjectIdentifier View([NotNull] string name, [CanBeNull] string schema) + public static StoreObjectIdentifier View([NotNull] string name, [CanBeNull] string? schema) { Check.NotNull(name, nameof(name)); @@ -123,7 +125,7 @@ public static StoreObjectIdentifier DbFunction([NotNull] string modelName) /// /// Gets the table-like store object schema. /// - public string Schema { get; } + public string? Schema { get; } /// public int CompareTo(StoreObjectIdentifier other) @@ -154,7 +156,7 @@ public override string ToString() => StoreObjectType + " " + DisplayName(); /// - public override bool Equals(object obj) + public override bool Equals(object? obj) => obj is StoreObjectIdentifier identifier && Equals(identifier); /// diff --git a/src/EFCore.Relational/Metadata/StoreObjectType.cs b/src/EFCore.Relational/Metadata/StoreObjectType.cs index 4fd72c71bb3..0949986beb8 100644 --- a/src/EFCore.Relational/Metadata/StoreObjectType.cs +++ b/src/EFCore.Relational/Metadata/StoreObjectType.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.Relational/Metadata/TableExtensions.cs b/src/EFCore.Relational/Metadata/TableExtensions.cs index 67ead53c010..8f1788f9951 100644 --- a/src/EFCore.Relational/Metadata/TableExtensions.cs +++ b/src/EFCore.Relational/Metadata/TableExtensions.cs @@ -6,6 +6,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Infrastructure; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata { /// diff --git a/src/EFCore.Relational/Metadata/TableIndexExtensions.cs b/src/EFCore.Relational/Metadata/TableIndexExtensions.cs index 7fefd245dbf..f396466f4cb 100644 --- a/src/EFCore.Relational/Metadata/TableIndexExtensions.cs +++ b/src/EFCore.Relational/Metadata/TableIndexExtensions.cs @@ -6,6 +6,8 @@ using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata.Internal; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata { /// diff --git a/src/EFCore.Relational/Metadata/TableMappingExtensions.cs b/src/EFCore.Relational/Metadata/TableMappingExtensions.cs index f71c48ec74c..15a4bab23aa 100644 --- a/src/EFCore.Relational/Metadata/TableMappingExtensions.cs +++ b/src/EFCore.Relational/Metadata/TableMappingExtensions.cs @@ -5,6 +5,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Infrastructure; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata { /// diff --git a/src/EFCore.Relational/Metadata/UniqueConstraintExtensions.cs b/src/EFCore.Relational/Metadata/UniqueConstraintExtensions.cs index c08a4819b15..daf6eb4a22f 100644 --- a/src/EFCore.Relational/Metadata/UniqueConstraintExtensions.cs +++ b/src/EFCore.Relational/Metadata/UniqueConstraintExtensions.cs @@ -6,6 +6,8 @@ using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata.Internal; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata { /// diff --git a/src/EFCore.Relational/Metadata/ViewColumnExtensions.cs b/src/EFCore.Relational/Metadata/ViewColumnExtensions.cs index dd3b5a507c6..b8b533c202b 100644 --- a/src/EFCore.Relational/Metadata/ViewColumnExtensions.cs +++ b/src/EFCore.Relational/Metadata/ViewColumnExtensions.cs @@ -5,6 +5,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Infrastructure; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata { /// diff --git a/src/EFCore.Relational/Metadata/ViewColumnMappingExtensions.cs b/src/EFCore.Relational/Metadata/ViewColumnMappingExtensions.cs index 388f83530c5..1065474268e 100644 --- a/src/EFCore.Relational/Metadata/ViewColumnMappingExtensions.cs +++ b/src/EFCore.Relational/Metadata/ViewColumnMappingExtensions.cs @@ -5,6 +5,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Infrastructure; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata { /// diff --git a/src/EFCore.Relational/Metadata/ViewExtensions.cs b/src/EFCore.Relational/Metadata/ViewExtensions.cs index 5f3d61eb995..5bb1eda309f 100644 --- a/src/EFCore.Relational/Metadata/ViewExtensions.cs +++ b/src/EFCore.Relational/Metadata/ViewExtensions.cs @@ -6,6 +6,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Infrastructure; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata { /// diff --git a/src/EFCore.Relational/Metadata/ViewMappingExtensions.cs b/src/EFCore.Relational/Metadata/ViewMappingExtensions.cs index b8432732b3c..2a0b74c7190 100644 --- a/src/EFCore.Relational/Metadata/ViewMappingExtensions.cs +++ b/src/EFCore.Relational/Metadata/ViewMappingExtensions.cs @@ -5,6 +5,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Infrastructure; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata { /// diff --git a/src/EFCore.Relational/Query/RelationalEntityShaperExpression.cs b/src/EFCore.Relational/Query/RelationalEntityShaperExpression.cs index 9e4354f33e3..f6c07d2a7ab 100644 --- a/src/EFCore.Relational/Query/RelationalEntityShaperExpression.cs +++ b/src/EFCore.Relational/Query/RelationalEntityShaperExpression.cs @@ -188,7 +188,7 @@ private IReadOnlyList GetNonSharedProperties(ITableBase table, IEntit continue; } - var propertyMappings = table.FindColumn(property).PropertyMappings; + var propertyMappings = table.FindColumn(property)!.PropertyMappings; if (propertyMappings.Count() > 1 && propertyMappings.Any(pm => principalEntityTypes.Contains(pm.TableMapping.EntityType))) { diff --git a/src/EFCore.Relational/Query/RelationalMethodCallTranslatorProvider.cs b/src/EFCore.Relational/Query/RelationalMethodCallTranslatorProvider.cs index e29090f3798..7b18e0be550 100644 --- a/src/EFCore.Relational/Query/RelationalMethodCallTranslatorProvider.cs +++ b/src/EFCore.Relational/Query/RelationalMethodCallTranslatorProvider.cs @@ -85,23 +85,32 @@ public RelationalMethodCallTranslatorProvider([NotNull] RelationalMethodCallTran arguments.Select(e => _sqlExpressionFactory.ApplyDefaultTypeMapping(e)).ToList()); } + var argumentsPropagateNullability = dbFunction.Parameters.Select(p => p.PropagatesNullability); + if (dbFunction.IsBuiltIn) { return _sqlExpressionFactory.Function( dbFunction.Name, arguments, - nullable: dbFunction.IsNullable, - argumentsPropagateNullability: dbFunction.Parameters.Select(p => p.PropagatesNullability), + dbFunction.IsNullable, + argumentsPropagateNullability, method.ReturnType.UnwrapNullableType()); } - return _sqlExpressionFactory.Function( - dbFunction.Schema, - dbFunction.Name, - arguments, - nullable: dbFunction.IsNullable, - argumentsPropagateNullability: dbFunction.Parameters.Select(p => p.PropagatesNullability), - method.ReturnType.UnwrapNullableType()); + return dbFunction.Schema is null + ? _sqlExpressionFactory.Function( + dbFunction.Name, + arguments, + dbFunction.IsNullable, + argumentsPropagateNullability, + method.ReturnType.UnwrapNullableType()) + : _sqlExpressionFactory.Function( + dbFunction.Schema, + dbFunction.Name, + arguments, + dbFunction.IsNullable, + argumentsPropagateNullability, + method.ReturnType.UnwrapNullableType()); } return _plugins.Concat(_translators) diff --git a/src/EFCore.Relational/Query/RelationalQueryableMethodTranslatingExpressionVisitor.cs b/src/EFCore.Relational/Query/RelationalQueryableMethodTranslatingExpressionVisitor.cs index e805fa50c92..40b034449cc 100644 --- a/src/EFCore.Relational/Query/RelationalQueryableMethodTranslatingExpressionVisitor.cs +++ b/src/EFCore.Relational/Query/RelationalQueryableMethodTranslatingExpressionVisitor.cs @@ -1333,7 +1333,7 @@ protected override Expression VisitExtension(Expression extensionExpression) var navigation = member.MemberInfo != null ? entityType.FindNavigation(member.MemberInfo) - : entityType.FindNavigation(member.Name); + : entityType.FindNavigation(member.Name!); if (navigation == null) { @@ -1510,7 +1510,7 @@ private static Expression AddConvertToObject(Expression expression) .SelectMany(EntityTypeExtensions.GetDeclaredProperties)) { propertyExpressions[property] = new ColumnExpression( - property, table.FindColumn(property), tableExpression, nullable || !property.IsPrimaryKey()); + property, table.FindColumn(property)!, tableExpression, nullable || !property.IsPrimaryKey()); } return propertyExpressions; @@ -1553,7 +1553,7 @@ private static IDictionary GetPropertyExpressionsFr .GetAllBaseTypes().Concat(entityType.GetDerivedTypesInclusive()).SelectMany(EntityTypeExtensions.GetDeclaredProperties)) { propertyExpressions[property] = new ColumnExpression( - property, table.FindColumn(property), tableExpression, nullable: true); + property, table.FindColumn(property)!, tableExpression, nullable: true); } return propertyExpressions; diff --git a/src/EFCore.Relational/Query/RelationalShapedQueryCompilingExpressionVisitor.ShaperProcessingExpressionVisitor.cs b/src/EFCore.Relational/Query/RelationalShapedQueryCompilingExpressionVisitor.ShaperProcessingExpressionVisitor.cs index 1bc2563207a..d27aed3a4f4 100644 --- a/src/EFCore.Relational/Query/RelationalShapedQueryCompilingExpressionVisitor.ShaperProcessingExpressionVisitor.cs +++ b/src/EFCore.Relational/Query/RelationalShapedQueryCompilingExpressionVisitor.ShaperProcessingExpressionVisitor.cs @@ -912,7 +912,7 @@ private static LambdaExpression GenerateFixup( Type entityType, Type relatedEntityType, INavigationBase navigation, - INavigationBase inverseNavigation) + INavigationBase? inverseNavigation) { var entityParameter = Expression.Parameter(entityType); var relatedEntityParameter = Expression.Parameter(relatedEntityType); diff --git a/src/EFCore.Relational/Query/RelationalSqlTranslatingExpressionVisitor.cs b/src/EFCore.Relational/Query/RelationalSqlTranslatingExpressionVisitor.cs index a0f423bc858..542bf0241f1 100644 --- a/src/EFCore.Relational/Query/RelationalSqlTranslatingExpressionVisitor.cs +++ b/src/EFCore.Relational/Query/RelationalSqlTranslatingExpressionVisitor.cs @@ -1077,7 +1077,7 @@ protected override Expression VisitUnary(UnaryExpression unaryExpression) var entityType = entityReferenceExpression.EntityType; var property = member.MemberInfo != null ? entityType.FindProperty(member.MemberInfo) - : entityType.FindProperty(member.Name); + : entityType.FindProperty(member.Name!); if (property != null) { @@ -1414,7 +1414,10 @@ private Expression CreatePropertyAccessExpression(Expression target, IProperty p { case SqlConstantExpression sqlConstantExpression: return Expression.Constant( - property.GetGetter().GetClrValue(sqlConstantExpression.Value), property.ClrType.MakeNullable()); + sqlConstantExpression.Value is null + ? null + : property.GetGetter().GetClrValue(sqlConstantExpression.Value), + property.ClrType.MakeNullable()); case SqlParameterExpression sqlParameterExpression when sqlParameterExpression.Name.StartsWith(QueryCompilationContext.QueryParameterPrefix, StringComparison.Ordinal): diff --git a/src/EFCore.Relational/Query/SqlExpressions/SelectExpression.cs b/src/EFCore.Relational/Query/SqlExpressions/SelectExpression.cs index 9885c5346e3..8b9dcc0a0c5 100644 --- a/src/EFCore.Relational/Query/SqlExpressions/SelectExpression.cs +++ b/src/EFCore.Relational/Query/SqlExpressions/SelectExpression.cs @@ -317,7 +317,7 @@ private static ColumnExpression CreateColumnExpression( ITableBase table, TableExpressionBase tableExpression, bool nullable) - => new ColumnExpression(property, table.FindColumn(property), tableExpression, nullable); + => new ColumnExpression(property, table.FindColumn(property)!, tableExpression, nullable); /// /// Checks whether this representes a which is not composed upon. diff --git a/src/EFCore.Relational/Query/SqlExpressions/TableExpression.cs b/src/EFCore.Relational/Query/SqlExpressions/TableExpression.cs index c25c20fd88e..77ae36a006e 100644 --- a/src/EFCore.Relational/Query/SqlExpressions/TableExpression.cs +++ b/src/EFCore.Relational/Query/SqlExpressions/TableExpression.cs @@ -51,7 +51,7 @@ protected override void Print(ExpressionPrinter expressionPrinter) /// /// The schema of the table or view. /// - public string Schema { get; } + public string? Schema { get; } /// /// The associated with this table or view. diff --git a/src/EFCore.SqlServer/Metadata/Internal/SqlServerAnnotationNames.cs b/src/EFCore.SqlServer/Metadata/Internal/SqlServerAnnotationNames.cs index 4aec92a48ba..f647aad30c9 100644 --- a/src/EFCore.SqlServer/Metadata/Internal/SqlServerAnnotationNames.cs +++ b/src/EFCore.SqlServer/Metadata/Internal/SqlServerAnnotationNames.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.SqlServer.Metadata.Internal { /// diff --git a/src/EFCore.SqlServer/Metadata/Internal/SqlServerAnnotationProvider.cs b/src/EFCore.SqlServer/Metadata/Internal/SqlServerAnnotationProvider.cs index e90ed375a16..0f39713cd6c 100644 --- a/src/EFCore.SqlServer/Metadata/Internal/SqlServerAnnotationProvider.cs +++ b/src/EFCore.SqlServer/Metadata/Internal/SqlServerAnnotationProvider.cs @@ -10,6 +10,8 @@ using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.Extensions.DependencyInjection; +#nullable enable + namespace Microsoft.EntityFrameworkCore.SqlServer.Metadata.Internal { /// diff --git a/src/EFCore.SqlServer/Metadata/Internal/SqlServerIndexExtensions.cs b/src/EFCore.SqlServer/Metadata/Internal/SqlServerIndexExtensions.cs index f23f05edb1e..73e6c5d22a3 100644 --- a/src/EFCore.SqlServer/Metadata/Internal/SqlServerIndexExtensions.cs +++ b/src/EFCore.SqlServer/Metadata/Internal/SqlServerIndexExtensions.cs @@ -6,6 +6,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.SqlServer.Internal; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Internal { /// diff --git a/src/EFCore.SqlServer/Metadata/Internal/SqlServerKeyExtensions.cs b/src/EFCore.SqlServer/Metadata/Internal/SqlServerKeyExtensions.cs index e085b056611..705c0b4e073 100644 --- a/src/EFCore.SqlServer/Metadata/Internal/SqlServerKeyExtensions.cs +++ b/src/EFCore.SqlServer/Metadata/Internal/SqlServerKeyExtensions.cs @@ -5,6 +5,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.SqlServer.Internal; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Internal { /// diff --git a/src/EFCore.SqlServer/Metadata/SqlServerValueGenerationStrategy.cs b/src/EFCore.SqlServer/Metadata/SqlServerValueGenerationStrategy.cs index 610e8fac7b9..a0cb11adde3 100644 --- a/src/EFCore.SqlServer/Metadata/SqlServerValueGenerationStrategy.cs +++ b/src/EFCore.SqlServer/Metadata/SqlServerValueGenerationStrategy.cs @@ -3,6 +3,8 @@ // ReSharper disable once CheckNamespace +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata { /// diff --git a/src/EFCore.Sqlite.Core/Metadata/Internal/SqliteAnnotationNames.cs b/src/EFCore.Sqlite.Core/Metadata/Internal/SqliteAnnotationNames.cs index b2562a98693..744856a71a6 100644 --- a/src/EFCore.Sqlite.Core/Metadata/Internal/SqliteAnnotationNames.cs +++ b/src/EFCore.Sqlite.Core/Metadata/Internal/SqliteAnnotationNames.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.Sqlite.Metadata.Internal { /// diff --git a/src/EFCore.Sqlite.Core/Metadata/Internal/SqliteAnnotationProvider.cs b/src/EFCore.Sqlite.Core/Metadata/Internal/SqliteAnnotationProvider.cs index 2c0021b46df..5c0e7ecd4c7 100644 --- a/src/EFCore.Sqlite.Core/Metadata/Internal/SqliteAnnotationProvider.cs +++ b/src/EFCore.Sqlite.Core/Metadata/Internal/SqliteAnnotationProvider.cs @@ -10,6 +10,8 @@ using Microsoft.EntityFrameworkCore.Sqlite.Storage.Internal; using Microsoft.Extensions.DependencyInjection; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Sqlite.Metadata.Internal { /// diff --git a/src/EFCore/Extensions/ConventionNavigationExtensions.cs b/src/EFCore/Extensions/ConventionNavigationExtensions.cs index c02851d4da9..f8e1d46195e 100644 --- a/src/EFCore/Extensions/ConventionNavigationExtensions.cs +++ b/src/EFCore/Extensions/ConventionNavigationExtensions.cs @@ -24,7 +24,7 @@ public static class ConventionNavigationExtensions /// The inverse navigation, or if none is defined. /// [Obsolete("Use IConventionNavigation.Inverse")] - public static IConventionNavigation FindInverse([NotNull] this IConventionNavigation navigation) + public static IConventionNavigation? FindInverse([NotNull] this IConventionNavigation navigation) => navigation.Inverse; /// diff --git a/src/EFCore/Extensions/MutableNavigationExtensions.cs b/src/EFCore/Extensions/MutableNavigationExtensions.cs index f2d3c80a4c5..f1d25fb7806 100644 --- a/src/EFCore/Extensions/MutableNavigationExtensions.cs +++ b/src/EFCore/Extensions/MutableNavigationExtensions.cs @@ -24,7 +24,7 @@ public static class MutableNavigationExtensions /// The inverse navigation, or if none is defined. /// [Obsolete("Use IMutableNavigation.Inverse")] - public static IMutableNavigation FindInverse([NotNull] this IMutableNavigation navigation) + public static IMutableNavigation? FindInverse([NotNull] this IMutableNavigation navigation) => navigation.Inverse; /// diff --git a/src/EFCore/Extensions/NavigationExtensions.cs b/src/EFCore/Extensions/NavigationExtensions.cs index 17f109c0352..4a52e42b6b9 100644 --- a/src/EFCore/Extensions/NavigationExtensions.cs +++ b/src/EFCore/Extensions/NavigationExtensions.cs @@ -52,11 +52,11 @@ public static bool IsCollection([NotNull] this INavigation navigation) /// /// The navigation property to find the inverse of. /// - /// The inverse navigation, or null if none is defined. + /// The inverse navigation, or if none is defined. /// [DebuggerStepThrough] [Obsolete("Use INavigation.Inverse")] - public static INavigation FindInverse([NotNull] this INavigation navigation) + public static INavigation? FindInverse([NotNull] this INavigation navigation) => Check.NotNull(navigation, nameof(navigation)).Inverse; /// diff --git a/src/EFCore/Infrastructure/ModelValidator.cs b/src/EFCore/Infrastructure/ModelValidator.cs index 200118662c9..70c210d924b 100644 --- a/src/EFCore/Infrastructure/ModelValidator.cs +++ b/src/EFCore/Infrastructure/ModelValidator.cs @@ -964,7 +964,7 @@ protected virtual void ValidateTypeMappings( || property.IsForeignKey() || property.IsUniqueIndex()) { - var _ = property.GetCurrentValueComparer(); // Will throw if there is no way to compare + _ = property.GetCurrentValueComparer(); // Will throw if there is no way to compare } } } diff --git a/src/EFCore/Metadata/ConfigurationSource.cs b/src/EFCore/Metadata/ConfigurationSource.cs index e21244a51df..c8774058cc8 100644 --- a/src/EFCore/Metadata/ConfigurationSource.cs +++ b/src/EFCore/Metadata/ConfigurationSource.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/ConfigurationSourceExtensions.cs b/src/EFCore/Metadata/ConfigurationSourceExtensions.cs index 31a8e638c9f..5df2997d052 100644 --- a/src/EFCore/Metadata/ConfigurationSourceExtensions.cs +++ b/src/EFCore/Metadata/ConfigurationSourceExtensions.cs @@ -3,6 +3,8 @@ using JetBrains.Annotations; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata { /// @@ -90,6 +92,6 @@ public static bool OverridesStrictly(this ConfigurationSource? newConfigurationS public static ConfigurationSource Max(this ConfigurationSource left, ConfigurationSource? right) => left.Overrides(right) ? left - : right.Value; + : right!.Value; } } diff --git a/src/EFCore/Metadata/ConstructorBinding.cs b/src/EFCore/Metadata/ConstructorBinding.cs index d989f794e0c..64657b92d01 100644 --- a/src/EFCore/Metadata/ConstructorBinding.cs +++ b/src/EFCore/Metadata/ConstructorBinding.cs @@ -9,6 +9,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata { /// @@ -51,6 +53,6 @@ public override Expression CreateConstructorExpression(ParameterBindingInfo bind /// The type that will be created from the expression tree created for this binding. /// public override Type RuntimeType - => Constructor.DeclaringType; + => Constructor.DeclaringType!; } } diff --git a/src/EFCore/Metadata/ContextParameterBinding.cs b/src/EFCore/Metadata/ContextParameterBinding.cs index dc8dee8a4e6..937310e193e 100644 --- a/src/EFCore/Metadata/ContextParameterBinding.cs +++ b/src/EFCore/Metadata/ContextParameterBinding.cs @@ -7,6 +7,8 @@ using Microsoft.EntityFrameworkCore.Storage; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata { /// @@ -19,10 +21,10 @@ public class ContextParameterBinding : ServiceParameterBinding /// Creates a new instance for the given service type. /// /// The CLR type. - /// The associated , or null. + /// The associated , or . public ContextParameterBinding( [NotNull] Type contextType, - [CanBeNull] IPropertyBase serviceProperty = null) + [CanBeNull] IPropertyBase? serviceProperty = null) : base(contextType, contextType, serviceProperty) { } diff --git a/src/EFCore/Metadata/DependencyInjectionMethodParameterBinding.cs b/src/EFCore/Metadata/DependencyInjectionMethodParameterBinding.cs index ce2748db33f..b600920b582 100644 --- a/src/EFCore/Metadata/DependencyInjectionMethodParameterBinding.cs +++ b/src/EFCore/Metadata/DependencyInjectionMethodParameterBinding.cs @@ -9,6 +9,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata { /// @@ -30,7 +32,7 @@ public DependencyInjectionMethodParameterBinding( [NotNull] Type parameterType, [NotNull] Type serviceType, [NotNull] MethodInfo method, - [CanBeNull] IPropertyBase serviceProperty = null) + [CanBeNull] IPropertyBase? serviceProperty = null) : base(parameterType, serviceType, serviceProperty) { Check.NotNull(method, nameof(method)); diff --git a/src/EFCore/Metadata/DependencyInjectionParameterBinding.cs b/src/EFCore/Metadata/DependencyInjectionParameterBinding.cs index 1eedd2e9225..9c57615b5b2 100644 --- a/src/EFCore/Metadata/DependencyInjectionParameterBinding.cs +++ b/src/EFCore/Metadata/DependencyInjectionParameterBinding.cs @@ -10,6 +10,8 @@ using Microsoft.EntityFrameworkCore.Storage; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata { /// @@ -20,7 +22,7 @@ namespace Microsoft.EntityFrameworkCore.Metadata public class DependencyInjectionParameterBinding : ServiceParameterBinding { private static readonly MethodInfo _getServiceMethod - = typeof(InfrastructureExtensions).GetMethod(nameof(InfrastructureExtensions.GetService)); + = typeof(InfrastructureExtensions).GetMethod(nameof(InfrastructureExtensions.GetService))!; /// /// Creates a new instance for the given service type. @@ -31,7 +33,7 @@ private static readonly MethodInfo _getServiceMethod public DependencyInjectionParameterBinding( [NotNull] Type parameterType, [NotNull] Type serviceType, - [CanBeNull] IPropertyBase serviceProperty = null) + [CanBeNull] IPropertyBase? serviceProperty = null) : base(parameterType, serviceType, serviceProperty) { } diff --git a/src/EFCore/Metadata/EntityTypeFullNameComparer.cs b/src/EFCore/Metadata/EntityTypeFullNameComparer.cs index 7f80a308234..02985a236ba 100644 --- a/src/EFCore/Metadata/EntityTypeFullNameComparer.cs +++ b/src/EFCore/Metadata/EntityTypeFullNameComparer.cs @@ -4,6 +4,8 @@ using System; using System.Collections.Generic; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata { /// @@ -33,7 +35,7 @@ private EntityTypeFullNameComparer() /// The first object to compare. /// The second object to compare. /// A negative number if 'x' is less than 'y'; a positive number if 'x' is greater than 'y'; zero otherwise. - public int Compare(IEntityType x, IEntityType y) + public int Compare(IEntityType? x, IEntityType? y) { if (ReferenceEquals(x, y)) { @@ -83,8 +85,8 @@ public int Compare(IEntityType x, IEntityType y) return result; } - x = x.DefiningEntityType; - y = y.DefiningEntityType; + x = x.DefiningEntityType!; + y = y.DefiningEntityType!; } } @@ -94,7 +96,7 @@ public int Compare(IEntityType x, IEntityType y) /// The first object to compare. /// The second object to compare. /// if the specified objects are equal; otherwise, . - public bool Equals(IEntityType x, IEntityType y) + public bool Equals(IEntityType? x, IEntityType? y) => Compare(x, y) == 0; /// @@ -108,13 +110,12 @@ public int GetHashCode(IEntityType obj) while (true) { hash.Add(obj.Name, StringComparer.Ordinal); - var definingNavigationName = obj.DefiningNavigationName; - if (definingNavigationName == null) + if (!obj.HasDefiningNavigation()) { return hash.ToHashCode(); } - hash.Add(definingNavigationName, StringComparer.Ordinal); + hash.Add(obj.DefiningNavigationName, StringComparer.Ordinal); obj = obj.DefiningEntityType; } } diff --git a/src/EFCore/Metadata/EntityTypeParameterBinding.cs b/src/EFCore/Metadata/EntityTypeParameterBinding.cs index 6f24da64b05..bd0271d5fd2 100644 --- a/src/EFCore/Metadata/EntityTypeParameterBinding.cs +++ b/src/EFCore/Metadata/EntityTypeParameterBinding.cs @@ -5,6 +5,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata { /// @@ -17,7 +19,7 @@ public class EntityTypeParameterBinding : ServiceParameterBinding /// Creates a new instance for the given service type. /// /// The associated , or null. - public EntityTypeParameterBinding([CanBeNull] IPropertyBase serviceProperty = null) + public EntityTypeParameterBinding([CanBeNull] IPropertyBase? serviceProperty = null) : base(typeof(IEntityType), typeof(IEntityType), serviceProperty) { } diff --git a/src/EFCore/Metadata/FactoryMethodBinding.cs b/src/EFCore/Metadata/FactoryMethodBinding.cs index e16325a61af..e582b6acf1e 100644 --- a/src/EFCore/Metadata/FactoryMethodBinding.cs +++ b/src/EFCore/Metadata/FactoryMethodBinding.cs @@ -9,6 +9,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata { /// @@ -16,7 +18,7 @@ namespace Microsoft.EntityFrameworkCore.Metadata /// public class FactoryMethodBinding : InstantiationBinding { - private readonly object _factoryInstance; + private readonly object? _factoryInstance; private readonly MethodInfo _factoryMethod; /// diff --git a/src/EFCore/Metadata/ForeignKeyComparer.cs b/src/EFCore/Metadata/ForeignKeyComparer.cs index 6d737d2538a..447d4624e59 100644 --- a/src/EFCore/Metadata/ForeignKeyComparer.cs +++ b/src/EFCore/Metadata/ForeignKeyComparer.cs @@ -5,6 +5,8 @@ using System.Collections.Generic; using Microsoft.EntityFrameworkCore.Metadata.Internal; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata { /// @@ -34,22 +36,22 @@ private ForeignKeyComparer() /// The first object to compare. /// The second object to compare. /// A negative number if 'x' is less than 'y'; a positive number if 'x' is greater than 'y'; zero otherwise. - public int Compare(IForeignKey x, IForeignKey y) + public int Compare(IForeignKey? x, IForeignKey? y) { - var result = PropertyListComparer.Instance.Compare(x.Properties, y.Properties); + var result = PropertyListComparer.Instance.Compare(x?.Properties, y?.Properties); if (result != 0) { return result; } - result = PropertyListComparer.Instance.Compare(x.PrincipalKey.Properties, y.PrincipalKey.Properties); + result = PropertyListComparer.Instance.Compare(x?.PrincipalKey.Properties, y?.PrincipalKey.Properties); if (result != 0) { return result; } - result = EntityTypeFullNameComparer.Instance.Compare(x.PrincipalEntityType, y.PrincipalEntityType); - return result != 0 ? result : EntityTypeFullNameComparer.Instance.Compare(x.DeclaringEntityType, y.DeclaringEntityType); + result = EntityTypeFullNameComparer.Instance.Compare(x?.PrincipalEntityType, y?.PrincipalEntityType); + return result != 0 ? result : EntityTypeFullNameComparer.Instance.Compare(x?.DeclaringEntityType, y?.DeclaringEntityType); } /// @@ -58,7 +60,7 @@ public int Compare(IForeignKey x, IForeignKey y) /// The first object to compare. /// The second object to compare. /// if the specified objects are equal; otherwise, . - public bool Equals(IForeignKey x, IForeignKey y) + public bool Equals(IForeignKey? x, IForeignKey? y) => Compare(x, y) == 0; /// diff --git a/src/EFCore/Metadata/IClrCollectionAccessor.cs b/src/EFCore/Metadata/IClrCollectionAccessor.cs index 745af83ba4a..b9606f1f808 100644 --- a/src/EFCore/Metadata/IClrCollectionAccessor.cs +++ b/src/EFCore/Metadata/IClrCollectionAccessor.cs @@ -4,6 +4,8 @@ using System; using JetBrains.Annotations; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata { /// diff --git a/src/EFCore/Metadata/IClrPropertyGetter.cs b/src/EFCore/Metadata/IClrPropertyGetter.cs index b8b10e85d37..a825e4063f8 100644 --- a/src/EFCore/Metadata/IClrPropertyGetter.cs +++ b/src/EFCore/Metadata/IClrPropertyGetter.cs @@ -3,6 +3,8 @@ using JetBrains.Annotations; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata { /// diff --git a/src/EFCore/Metadata/IClrPropertySetter.cs b/src/EFCore/Metadata/IClrPropertySetter.cs index 6c3293675a7..d4a21d1f53b 100644 --- a/src/EFCore/Metadata/IClrPropertySetter.cs +++ b/src/EFCore/Metadata/IClrPropertySetter.cs @@ -3,6 +3,8 @@ using JetBrains.Annotations; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata { /// @@ -16,6 +18,6 @@ public interface IClrPropertySetter /// /// The entity instance. /// The value to set. - void SetClrValue([NotNull] object instance, [CanBeNull] object value); + void SetClrValue([NotNull] object instance, [CanBeNull] object? value); } } diff --git a/src/EFCore/Metadata/IConstructorBindingFactory.cs b/src/EFCore/Metadata/IConstructorBindingFactory.cs index 0f26188c21b..18edb00d9c3 100644 --- a/src/EFCore/Metadata/IConstructorBindingFactory.cs +++ b/src/EFCore/Metadata/IConstructorBindingFactory.cs @@ -6,6 +6,8 @@ using JetBrains.Annotations; using Microsoft.Extensions.DependencyInjection; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata { /// @@ -33,8 +35,8 @@ public interface IConstructorBindingFactory bool TryBindConstructor( [NotNull] IConventionEntityType entityType, [NotNull] ConstructorInfo constructor, - [CanBeNull] out InstantiationBinding binding, - [CanBeNull] out IEnumerable unboundParameters); + [CanBeNull] out InstantiationBinding? binding, + [CanBeNull] out IEnumerable? unboundParameters); /// /// Attempts to create a for the given and @@ -48,7 +50,7 @@ bool TryBindConstructor( bool TryBindConstructor( [NotNull] IMutableEntityType entityType, [NotNull] ConstructorInfo constructor, - [CanBeNull] out InstantiationBinding binding, - [CanBeNull] out IEnumerable unboundParameters); + [CanBeNull] out InstantiationBinding? binding, + [CanBeNull] out IEnumerable? unboundParameters); } } diff --git a/src/EFCore/Metadata/IConventionAnnotation.cs b/src/EFCore/Metadata/IConventionAnnotation.cs index 014e6a89614..d85c2a6c382 100644 --- a/src/EFCore/Metadata/IConventionAnnotation.cs +++ b/src/EFCore/Metadata/IConventionAnnotation.cs @@ -3,6 +3,8 @@ using Microsoft.EntityFrameworkCore.Infrastructure; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata { /// diff --git a/src/EFCore/Metadata/IConventionModel.cs b/src/EFCore/Metadata/IConventionModel.cs index b7d6041fb21..f6c37e17fc9 100644 --- a/src/EFCore/Metadata/IConventionModel.cs +++ b/src/EFCore/Metadata/IConventionModel.cs @@ -27,7 +27,7 @@ public interface IConventionModel : IModel, IConventionAnnotatable /// /// Gets the builder that can be used to configure this model. /// - new IConventionModelBuilder? Builder { get; } + new IConventionModelBuilder Builder { get; } /// /// diff --git a/src/EFCore/Metadata/IConventionNavigation.cs b/src/EFCore/Metadata/IConventionNavigation.cs index a512e3a0b6f..8a1e657753d 100644 --- a/src/EFCore/Metadata/IConventionNavigation.cs +++ b/src/EFCore/Metadata/IConventionNavigation.cs @@ -65,10 +65,10 @@ ConfigurationSource IConventionPropertyBase.GetConfigurationSource() /// /// Gets the inverse navigation. /// - new IConventionNavigation Inverse + new IConventionNavigation? Inverse { [DebuggerStepThrough] - get => (IConventionNavigation)((INavigation)this).Inverse; + get => (IConventionNavigation?)((INavigation)this).Inverse; } /// diff --git a/src/EFCore/Metadata/IConventionPropertyBase.cs b/src/EFCore/Metadata/IConventionPropertyBase.cs index b7281a54445..96eacc7fa8a 100644 --- a/src/EFCore/Metadata/IConventionPropertyBase.cs +++ b/src/EFCore/Metadata/IConventionPropertyBase.cs @@ -6,6 +6,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Metadata.Internal; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata { /// @@ -44,7 +46,7 @@ public interface IConventionPropertyBase : IPropertyBase, IConventionAnnotatable /// The for the underlying CLR field to use. /// Indicates whether the configuration was specified using a data annotation. /// The new . - FieldInfo SetFieldInfo([CanBeNull] FieldInfo fieldInfo, bool fromDataAnnotation = false); + FieldInfo? SetFieldInfo([CanBeNull] FieldInfo? fieldInfo, bool fromDataAnnotation = false); /// /// @@ -60,7 +62,7 @@ public interface IConventionPropertyBase : IPropertyBase, IConventionAnnotatable /// The for the underlying CLR field to use. /// Indicates whether the configuration was specified using a data annotation. [Obsolete("Use SetFieldInfo")] - void SetField([CanBeNull] FieldInfo fieldInfo, bool fromDataAnnotation = false) + void SetField([CanBeNull] FieldInfo? fieldInfo, bool fromDataAnnotation = false) => SetFieldInfo(fieldInfo, fromDataAnnotation); /// @@ -84,7 +86,7 @@ void SetField([CanBeNull] FieldInfo fieldInfo, bool fromDataAnnotation = false) /// The name of the field to use. /// Indicates whether the configuration was specified using a data annotation. /// The new . - FieldInfo SetField([CanBeNull] string fieldName, bool fromDataAnnotation = false) + FieldInfo? SetField([CanBeNull] string? fieldName, bool fromDataAnnotation = false) => this.AsPropertyBase() .SetField(fieldName, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); diff --git a/src/EFCore/Metadata/IConventionServiceProperty.cs b/src/EFCore/Metadata/IConventionServiceProperty.cs index bddfc226f95..d7276f59da8 100644 --- a/src/EFCore/Metadata/IConventionServiceProperty.cs +++ b/src/EFCore/Metadata/IConventionServiceProperty.cs @@ -4,6 +4,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Metadata.Builders; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata { /// @@ -21,7 +23,7 @@ public interface IConventionServiceProperty : IServiceProperty, IConventionPrope /// /// Gets the builder that can be used to configure this service property. /// - new IConventionServicePropertyBuilder Builder { get; } + new IConventionServicePropertyBuilder? Builder { get; } /// /// Gets the type that this property belongs to. @@ -34,7 +36,7 @@ public interface IConventionServiceProperty : IServiceProperty, IConventionPrope /// The parameter binding. /// Indicates whether the configuration was specified using a data annotation. /// The configured binding. - ServiceParameterBinding SetParameterBinding([CanBeNull] ServiceParameterBinding parameterBinding, bool fromDataAnnotation = false); + ServiceParameterBinding? SetParameterBinding([CanBeNull] ServiceParameterBinding? parameterBinding, bool fromDataAnnotation = false); /// /// Returns the configuration source for . diff --git a/src/EFCore/Metadata/IConventionTypeBase.cs b/src/EFCore/Metadata/IConventionTypeBase.cs index 2f67dbf397d..82157d24ffe 100644 --- a/src/EFCore/Metadata/IConventionTypeBase.cs +++ b/src/EFCore/Metadata/IConventionTypeBase.cs @@ -4,6 +4,8 @@ using System.Collections.Generic; using JetBrains.Annotations; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata { /// @@ -36,7 +38,7 @@ public interface IConventionTypeBase : ITypeBase, IConventionAnnotatable /// /// The name of the member to be removed. /// The removed ignored member name. - string RemoveIgnored([NotNull] string memberName); + string? RemoveIgnored([NotNull] string memberName); /// /// Indicates whether the given member name is ignored. diff --git a/src/EFCore/Metadata/IMetadataReference.cs b/src/EFCore/Metadata/IMetadataReference.cs index bee0742ec6d..1961cbc0b2f 100644 --- a/src/EFCore/Metadata/IMetadataReference.cs +++ b/src/EFCore/Metadata/IMetadataReference.cs @@ -2,6 +2,9 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using CA = System.Diagnostics.CodeAnalysis; + +#nullable enable namespace Microsoft.EntityFrameworkCore.Metadata { @@ -15,6 +18,7 @@ public interface IMetadataReference : IDisposable /// /// The referenced object. /// + [CA.MaybeNull] T Object { get; } } } diff --git a/src/EFCore/Metadata/IMutableNavigation.cs b/src/EFCore/Metadata/IMutableNavigation.cs index e3762c731f1..b111c72a7e3 100644 --- a/src/EFCore/Metadata/IMutableNavigation.cs +++ b/src/EFCore/Metadata/IMutableNavigation.cs @@ -50,10 +50,10 @@ public interface IMutableNavigation : INavigation, IMutableNavigationBase /// /// Gets the inverse navigation. /// - new IMutableNavigation Inverse + new IMutableNavigation? Inverse { [DebuggerStepThrough] - get => (IMutableNavigation)((INavigation)this).Inverse; + get => (IMutableNavigation?)((INavigation)this).Inverse; } /// diff --git a/src/EFCore/Metadata/INavigation.cs b/src/EFCore/Metadata/INavigation.cs index 74be6187fff..37b3625c4bd 100644 --- a/src/EFCore/Metadata/INavigation.cs +++ b/src/EFCore/Metadata/INavigation.cs @@ -4,6 +4,8 @@ using System.Diagnostics; using Microsoft.EntityFrameworkCore.Metadata.Internal; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata { /// @@ -32,7 +34,7 @@ public interface INavigation : INavigationBase /// /// Gets the inverse navigation. /// - new INavigation Inverse + new INavigation? Inverse { [DebuggerStepThrough] get => IsOnDependent ? ForeignKey.PrincipalToDependent : ForeignKey.DependentToPrincipal; @@ -91,7 +93,7 @@ IEntityType INavigationBase.TargetEntityType /// /// Gets the inverse navigation. /// - INavigationBase INavigationBase.Inverse + INavigationBase? INavigationBase.Inverse { [DebuggerStepThrough] get => Inverse; diff --git a/src/EFCore/Metadata/INavigationBase.cs b/src/EFCore/Metadata/INavigationBase.cs index 33730800a67..36a734b79f0 100644 --- a/src/EFCore/Metadata/INavigationBase.cs +++ b/src/EFCore/Metadata/INavigationBase.cs @@ -3,6 +3,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Internal; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata { /// @@ -23,7 +25,7 @@ public interface INavigationBase : IPropertyBase /// /// Gets the inverse navigation. /// - INavigationBase Inverse { get; } + INavigationBase? Inverse { get; } /// /// Gets a value indicating whether the navigation property is a collection property. diff --git a/src/EFCore/Metadata/IParameterBindingFactories.cs b/src/EFCore/Metadata/IParameterBindingFactories.cs index 36176725356..96f4f7afec8 100644 --- a/src/EFCore/Metadata/IParameterBindingFactories.cs +++ b/src/EFCore/Metadata/IParameterBindingFactories.cs @@ -5,6 +5,8 @@ using JetBrains.Annotations; using Microsoft.Extensions.DependencyInjection; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata { /// diff --git a/src/EFCore/Metadata/IParameterBindingFactory.cs b/src/EFCore/Metadata/IParameterBindingFactory.cs index 169673ffcc5..94bd65ae590 100644 --- a/src/EFCore/Metadata/IParameterBindingFactory.cs +++ b/src/EFCore/Metadata/IParameterBindingFactory.cs @@ -5,6 +5,8 @@ using JetBrains.Annotations; using Microsoft.Extensions.DependencyInjection; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata { /// diff --git a/src/EFCore/Metadata/IProperty.cs b/src/EFCore/Metadata/IProperty.cs index b381e4dd397..cdbff052e38 100644 --- a/src/EFCore/Metadata/IProperty.cs +++ b/src/EFCore/Metadata/IProperty.cs @@ -3,6 +3,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Internal; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata { /// diff --git a/src/EFCore/Metadata/IPropertyParameterBindingFactory.cs b/src/EFCore/Metadata/IPropertyParameterBindingFactory.cs index e9342545999..a0041fc6765 100644 --- a/src/EFCore/Metadata/IPropertyParameterBindingFactory.cs +++ b/src/EFCore/Metadata/IPropertyParameterBindingFactory.cs @@ -5,6 +5,8 @@ using JetBrains.Annotations; using Microsoft.Extensions.DependencyInjection; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata { /// diff --git a/src/EFCore/Metadata/IServiceProperty.cs b/src/EFCore/Metadata/IServiceProperty.cs index 3cecb084713..0445539cebb 100644 --- a/src/EFCore/Metadata/IServiceProperty.cs +++ b/src/EFCore/Metadata/IServiceProperty.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 { /// @@ -17,6 +19,6 @@ public interface IServiceProperty : IPropertyBase /// /// The for this property. /// - ServiceParameterBinding ParameterBinding { get; } + ServiceParameterBinding? ParameterBinding { get; } } } diff --git a/src/EFCore/Metadata/IndexComparer.cs b/src/EFCore/Metadata/IndexComparer.cs index fe7cfed43f6..e270875f8a8 100644 --- a/src/EFCore/Metadata/IndexComparer.cs +++ b/src/EFCore/Metadata/IndexComparer.cs @@ -5,6 +5,8 @@ using System.Collections.Generic; using Microsoft.EntityFrameworkCore.Metadata.Internal; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata { /// @@ -34,10 +36,10 @@ private IndexComparer() /// The first object to compare. /// The second object to compare. /// A negative number if 'x' is less than 'y'; a positive number if 'x' is greater than 'y'; zero otherwise. - public int Compare(IIndex x, IIndex y) + public int Compare(IIndex? x, IIndex? y) { - var result = PropertyListComparer.Instance.Compare(x.Properties, y.Properties); - return result != 0 ? result : EntityTypeFullNameComparer.Instance.Compare(x.DeclaringEntityType, y.DeclaringEntityType); + var result = PropertyListComparer.Instance.Compare(x?.Properties, y?.Properties); + return result != 0 ? result : EntityTypeFullNameComparer.Instance.Compare(x?.DeclaringEntityType, y?.DeclaringEntityType); } /// @@ -46,7 +48,7 @@ public int Compare(IIndex x, IIndex y) /// The first object to compare. /// The second object to compare. /// if the specified objects are equal; otherwise, . - public bool Equals(IIndex x, IIndex y) + public bool Equals(IIndex? x, IIndex? y) => Compare(x, y) == 0; /// diff --git a/src/EFCore/Metadata/InstantiationBinding.cs b/src/EFCore/Metadata/InstantiationBinding.cs index 782129adc9b..f196713eaf0 100644 --- a/src/EFCore/Metadata/InstantiationBinding.cs +++ b/src/EFCore/Metadata/InstantiationBinding.cs @@ -7,6 +7,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata { /// diff --git a/src/EFCore/Metadata/Internal/EntityType.cs b/src/EFCore/Metadata/Internal/EntityType.cs index 31eb3694f9e..e91823d1479 100644 --- a/src/EFCore/Metadata/Internal/EntityType.cs +++ b/src/EFCore/Metadata/Internal/EntityType.cs @@ -1502,7 +1502,7 @@ public virtual Navigation AddNavigation( private Navigation AddNavigation(MemberIdentity navigationMember, ForeignKey foreignKey, bool pointsToPrincipal) { - var name = navigationMember.Name; + var name = navigationMember.Name!; var duplicateNavigation = FindNavigationsInHierarchy(name).FirstOrDefault(); if (duplicateNavigation != null) { diff --git a/src/EFCore/Metadata/Internal/Navigation.cs b/src/EFCore/Metadata/Internal/Navigation.cs index 157def6b4e8..9847adde32e 100644 --- a/src/EFCore/Metadata/Internal/Navigation.cs +++ b/src/EFCore/Metadata/Internal/Navigation.cs @@ -266,10 +266,10 @@ public 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 Navigation Inverse + public virtual Navigation? Inverse { [DebuggerStepThrough] - get => (Navigation)((INavigationBase)this).Inverse; + get => (Navigation?)((INavigationBase)this).Inverse; } /// diff --git a/src/EFCore/Metadata/Internal/PropertyBase.cs b/src/EFCore/Metadata/Internal/PropertyBase.cs index 52172bec9a3..88aac68f23e 100644 --- a/src/EFCore/Metadata/Internal/PropertyBase.cs +++ b/src/EFCore/Metadata/Internal/PropertyBase.cs @@ -467,7 +467,7 @@ IConventionTypeBase IConventionPropertyBase.DeclaringType /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [DebuggerStepThrough] - FieldInfo? IConventionPropertyBase.SetFieldInfo(FieldInfo fieldInfo, bool fromDataAnnotation) + FieldInfo? IConventionPropertyBase.SetFieldInfo(FieldInfo? fieldInfo, bool fromDataAnnotation) => SetFieldInfo(fieldInfo, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); } } diff --git a/src/EFCore/Metadata/Internal/PropertyListComparer.cs b/src/EFCore/Metadata/Internal/PropertyListComparer.cs index 02a13ad5cbd..94bba3e0da5 100644 --- a/src/EFCore/Metadata/Internal/PropertyListComparer.cs +++ b/src/EFCore/Metadata/Internal/PropertyListComparer.cs @@ -4,6 +4,8 @@ using System; using System.Collections.Generic; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Internal { /// @@ -33,8 +35,23 @@ private PropertyListComparer() /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public int Compare(IReadOnlyList x, IReadOnlyList y) + public int Compare(IReadOnlyList? x, IReadOnlyList? y) { + if (ReferenceEquals(x, y)) + { + return 0; + } + + if (x is null) + { + return -1; + } + + if (y is null) + { + return 1; + } + var result = x.Count - y.Count; if (result != 0) @@ -59,7 +76,7 @@ public int Compare(IReadOnlyList x, IReadOnlyList y) /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public bool Equals(IReadOnlyList x, IReadOnlyList y) + public bool Equals(IReadOnlyList? x, IReadOnlyList? y) => Compare(x, y) == 0; /// diff --git a/src/EFCore/Metadata/Internal/PropertyNameComparer.cs b/src/EFCore/Metadata/Internal/PropertyNameComparer.cs index 100e55aec6c..b5ee52f03d4 100644 --- a/src/EFCore/Metadata/Internal/PropertyNameComparer.cs +++ b/src/EFCore/Metadata/Internal/PropertyNameComparer.cs @@ -5,6 +5,8 @@ using System.Collections.Generic; using JetBrains.Annotations; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata.Internal { /// @@ -34,7 +36,7 @@ public PropertyNameComparer([NotNull] EntityType entityType) /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public int Compare(string x, string y) + public int Compare(string? x, string? y) { var xIndex = -1; var yIndex = -1; diff --git a/src/EFCore/Metadata/Internal/Reference.cs b/src/EFCore/Metadata/Internal/Reference.cs index c5c4f29267e..7956fcffcf6 100644 --- a/src/EFCore/Metadata/Internal/Reference.cs +++ b/src/EFCore/Metadata/Internal/Reference.cs @@ -2,6 +2,9 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using JetBrains.Annotations; +using CA = System.Diagnostics.CodeAnalysis; + +#nullable enable namespace Microsoft.EntityFrameworkCore.Metadata.Internal { @@ -13,7 +16,8 @@ namespace Microsoft.EntityFrameworkCore.Metadata.Internal /// public class Reference : IMetadataReference { - private readonly IReferenceRoot _root; + private T _object; + private readonly IReferenceRoot? _root; private int _referenceCount = 1; /// @@ -22,7 +26,7 @@ public class Reference : IMetadataReference /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public Reference([CanBeNull] T @object) + public Reference([NotNull] T @object) : this(@object, null) { } @@ -33,9 +37,9 @@ public Reference([CanBeNull] T @object) /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public Reference([CanBeNull] T @object, [CanBeNull] IReferenceRoot root) + public Reference([NotNull] T @object, [CanBeNull] IReferenceRoot? root) { - Object = @object; + _object = @object; _root = root; } @@ -45,7 +49,11 @@ public Reference([CanBeNull] T @object, [CanBeNull] IReferenceRoot root) /// any release. You should only use it directly in your 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 Object { get; [param: NotNull]set; } + public virtual T Object + { + get => _object; + [param: NotNull] set => _object = value; + } /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -58,7 +66,7 @@ public virtual void Dispose() if (_referenceCount-- == 1) { _root?.Release(this); - Object = default; + _object = default!; } } diff --git a/src/EFCore/Metadata/Internal/ServiceProperty.cs b/src/EFCore/Metadata/Internal/ServiceProperty.cs index 4bb914007aa..acfded8a81f 100644 --- a/src/EFCore/Metadata/Internal/ServiceProperty.cs +++ b/src/EFCore/Metadata/Internal/ServiceProperty.cs @@ -122,7 +122,7 @@ public virtual ServiceParameterBinding? ParameterBinding /// doing so can result in application failures when updating to a new Entity Framework Core release. /// ServiceParameterBinding? IConventionServiceProperty.SetParameterBinding( - ServiceParameterBinding parameterBinding, + ServiceParameterBinding? parameterBinding, bool fromDataAnnotation) => SetParameterBinding( parameterBinding, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention); diff --git a/src/EFCore/Metadata/KeyComparer.cs b/src/EFCore/Metadata/KeyComparer.cs index dd0133f0cad..42e39c7a440 100644 --- a/src/EFCore/Metadata/KeyComparer.cs +++ b/src/EFCore/Metadata/KeyComparer.cs @@ -5,6 +5,8 @@ using System.Collections.Generic; using Microsoft.EntityFrameworkCore.Metadata.Internal; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata { /// @@ -34,10 +36,10 @@ private KeyComparer() /// The first object to compare. /// The second object to compare. /// A negative number if 'x' is less than 'y'; a positive number if 'x' is greater than 'y'; zero otherwise. - public int Compare(IKey x, IKey y) + public int Compare(IKey? x, IKey? y) { - var result = PropertyListComparer.Instance.Compare(x.Properties, y.Properties); - return result != 0 ? result : EntityTypeFullNameComparer.Instance.Compare(x.DeclaringEntityType, y.DeclaringEntityType); + var result = PropertyListComparer.Instance.Compare(x?.Properties, y?.Properties); + return result != 0 ? result : EntityTypeFullNameComparer.Instance.Compare(x?.DeclaringEntityType, y?.DeclaringEntityType); } /// @@ -46,7 +48,7 @@ public int Compare(IKey x, IKey y) /// The first object to compare. /// The second object to compare. /// if the specified objects are equal; otherwise, . - public bool Equals(IKey x, IKey y) + public bool Equals(IKey? x, IKey? y) => Compare(x, y) == 0; /// diff --git a/src/EFCore/Metadata/LazyLoaderParameterBindingFactory.cs b/src/EFCore/Metadata/LazyLoaderParameterBindingFactory.cs index 809c65151b2..b30165b0213 100644 --- a/src/EFCore/Metadata/LazyLoaderParameterBindingFactory.cs +++ b/src/EFCore/Metadata/LazyLoaderParameterBindingFactory.cs @@ -11,6 +11,8 @@ using Microsoft.EntityFrameworkCore.Utilities; using Microsoft.Extensions.DependencyInjection; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata { /// @@ -26,8 +28,8 @@ namespace Microsoft.EntityFrameworkCore.Metadata /// public class LazyLoaderParameterBindingFactory : ServiceParameterBindingFactory { - private static readonly MethodInfo _loadMethod = typeof(ILazyLoader).GetMethod(nameof(ILazyLoader.Load)); - private static readonly MethodInfo _loadAsyncMethod = typeof(ILazyLoader).GetMethod(nameof(ILazyLoader.LoadAsync)); + private static readonly MethodInfo _loadMethod = typeof(ILazyLoader).GetMethod(nameof(ILazyLoader.Load))!; + private static readonly MethodInfo _loadAsyncMethod = typeof(ILazyLoader).GetMethod(nameof(ILazyLoader.LoadAsync))!; /// /// Creates a new instance. diff --git a/src/EFCore/Metadata/LazyLoaderParameterBindingFactoryDependencies.cs b/src/EFCore/Metadata/LazyLoaderParameterBindingFactoryDependencies.cs index 76a5a2ccd78..c3a6dcb749f 100644 --- a/src/EFCore/Metadata/LazyLoaderParameterBindingFactoryDependencies.cs +++ b/src/EFCore/Metadata/LazyLoaderParameterBindingFactoryDependencies.cs @@ -4,6 +4,8 @@ using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.Extensions.DependencyInjection; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata { /// diff --git a/src/EFCore/Metadata/MemberIdentity.cs b/src/EFCore/Metadata/MemberIdentity.cs index f9c84d54879..7d8d8e8f3d9 100644 --- a/src/EFCore/Metadata/MemberIdentity.cs +++ b/src/EFCore/Metadata/MemberIdentity.cs @@ -7,6 +7,8 @@ using System.Reflection; using JetBrains.Annotations; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata { /// @@ -15,7 +17,7 @@ namespace Microsoft.EntityFrameworkCore.Metadata [DebuggerDisplay("{DebuggerDisplay(),nq}")] public readonly struct MemberIdentity : IEquatable { - private readonly object _nameOrMember; + private readonly object? _nameOrMember; /// /// Constructs a new from the given member name. @@ -38,7 +40,7 @@ public MemberIdentity([NotNull] MemberInfo memberInfo) } [DebuggerStepThrough] - private MemberIdentity([CanBeNull] object nameOrMember) + private MemberIdentity([CanBeNull] object? nameOrMember) { _nameOrMember = nameOrMember; } @@ -53,7 +55,7 @@ public bool IsNone() /// /// A instance that does not represent any member. /// - public static readonly MemberIdentity None = new MemberIdentity((object)null); + public static readonly MemberIdentity None = new MemberIdentity((object?)null); /// /// Creates a new from the given member name. @@ -61,7 +63,7 @@ public bool IsNone() /// The member name. /// The newly created identity, or if the given name is . [DebuggerStepThrough] - public static MemberIdentity Create([CanBeNull] string name) + public static MemberIdentity Create([CanBeNull] string? name) => name == null ? None : new MemberIdentity(name); /// @@ -70,21 +72,21 @@ public static MemberIdentity Create([CanBeNull] string name) /// The member. /// The newly created identity, or if the given name is . [DebuggerStepThrough] - public static MemberIdentity Create([CanBeNull] MemberInfo memberInfo) + public static MemberIdentity Create([CanBeNull] MemberInfo? memberInfo) => memberInfo == null ? None : new MemberIdentity(memberInfo); /// /// The name of the member. /// - public string Name + public string? Name { - [DebuggerStepThrough] get => MemberInfo?.GetSimpleMemberName() ?? (string)_nameOrMember; + [DebuggerStepThrough] get => MemberInfo?.GetSimpleMemberName() ?? (string?)_nameOrMember; } /// /// The representing the member, or if not known. /// - public MemberInfo MemberInfo + public MemberInfo? MemberInfo { [DebuggerStepThrough] get => _nameOrMember as MemberInfo; } @@ -93,7 +95,7 @@ private string DebuggerDisplay() => Name ?? "NONE"; /// - public override bool Equals(object obj) + public override bool Equals(object? obj) => obj is MemberIdentity identity && Equals(identity); /// diff --git a/src/EFCore/Metadata/ObjectArrayParameterBinding.cs b/src/EFCore/Metadata/ObjectArrayParameterBinding.cs index f5fbb39f6f5..bddeeb0b628 100644 --- a/src/EFCore/Metadata/ObjectArrayParameterBinding.cs +++ b/src/EFCore/Metadata/ObjectArrayParameterBinding.cs @@ -7,6 +7,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata { /// diff --git a/src/EFCore/Metadata/ParameterBinding.cs b/src/EFCore/Metadata/ParameterBinding.cs index 28dafd0e6cc..db25dec73d9 100644 --- a/src/EFCore/Metadata/ParameterBinding.cs +++ b/src/EFCore/Metadata/ParameterBinding.cs @@ -7,6 +7,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata { /// diff --git a/src/EFCore/Metadata/ParameterBindingInfo.cs b/src/EFCore/Metadata/ParameterBindingInfo.cs index d2e639b4340..a533681137a 100644 --- a/src/EFCore/Metadata/ParameterBindingInfo.cs +++ b/src/EFCore/Metadata/ParameterBindingInfo.cs @@ -6,6 +6,8 @@ using Microsoft.EntityFrameworkCore.Storage; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata { /// @@ -20,9 +22,10 @@ public readonly struct ParameterBindingInfo /// The expression tree from which the parameter value will come. public ParameterBindingInfo( [NotNull] IEntityType entityType, - [CanBeNull] Expression materializationContextExpression) + [NotNull] Expression materializationContextExpression) { Check.NotNull(entityType, nameof(entityType)); + Check.NotNull(entityType, nameof(materializationContextExpression)); EntityType = entityType; MaterializationContextExpression = materializationContextExpression; diff --git a/src/EFCore/Metadata/PropertyParameterBinding.cs b/src/EFCore/Metadata/PropertyParameterBinding.cs index 410b8be9d45..ce50b4a1a98 100644 --- a/src/EFCore/Metadata/PropertyParameterBinding.cs +++ b/src/EFCore/Metadata/PropertyParameterBinding.cs @@ -6,6 +6,8 @@ using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Storage; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata { /// diff --git a/src/EFCore/Metadata/PropertySaveBehavior.cs b/src/EFCore/Metadata/PropertySaveBehavior.cs index 00226ece335..c64692d67d4 100644 --- a/src/EFCore/Metadata/PropertySaveBehavior.cs +++ b/src/EFCore/Metadata/PropertySaveBehavior.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/ServiceParameterBinding.cs b/src/EFCore/Metadata/ServiceParameterBinding.cs index 4a8dea6c6e9..b939c346f6f 100644 --- a/src/EFCore/Metadata/ServiceParameterBinding.cs +++ b/src/EFCore/Metadata/ServiceParameterBinding.cs @@ -8,6 +8,8 @@ using Microsoft.EntityFrameworkCore.Storage; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata { /// @@ -17,7 +19,7 @@ namespace Microsoft.EntityFrameworkCore.Metadata /// public abstract class ServiceParameterBinding : ParameterBinding { - private Func _serviceDelegate; + private Func? _serviceDelegate; /// /// Creates a new instance for the given service type @@ -29,7 +31,7 @@ public abstract class ServiceParameterBinding : ParameterBinding protected ServiceParameterBinding( [NotNull] Type parameterType, [NotNull] Type serviceType, - [CanBeNull] IPropertyBase serviceProperty = null) + [CanBeNull] IPropertyBase? serviceProperty = null) : base( parameterType, serviceProperty != null ? new[] { serviceProperty } diff --git a/src/EFCore/Metadata/ServiceParameterBindingFactory.cs b/src/EFCore/Metadata/ServiceParameterBindingFactory.cs index 1620945952a..4decec7aa4e 100644 --- a/src/EFCore/Metadata/ServiceParameterBindingFactory.cs +++ b/src/EFCore/Metadata/ServiceParameterBindingFactory.cs @@ -7,6 +7,8 @@ using Microsoft.EntityFrameworkCore.Utilities; using Microsoft.Extensions.DependencyInjection; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata { /// diff --git a/src/EFCore/Metadata/SimpleModelFactory.cs b/src/EFCore/Metadata/SimpleModelFactory.cs index 1b97fdcb8a0..354d5979d96 100644 --- a/src/EFCore/Metadata/SimpleModelFactory.cs +++ b/src/EFCore/Metadata/SimpleModelFactory.cs @@ -3,12 +3,14 @@ using Microsoft.EntityFrameworkCore.Metadata.Internal; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata { /// /// /// Creates instances of that have no conventions. This is useful when - /// Exhaustively configuring a model based on some existing metadata. + /// exhaustively configuring a model based on some existing metadata. /// /// /// This is typically not used in application code since building a model by overriding diff --git a/src/EFCore/Metadata/ValueGenerated.cs b/src/EFCore/Metadata/ValueGenerated.cs index 727047efb73..a492c1802b0 100644 --- a/src/EFCore/Metadata/ValueGenerated.cs +++ b/src/EFCore/Metadata/ValueGenerated.cs @@ -3,6 +3,8 @@ using System; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Metadata { /// diff --git a/src/EFCore/Query/Internal/NavigationExpandingExpressionVisitor.ExpressionVisitors.cs b/src/EFCore/Query/Internal/NavigationExpandingExpressionVisitor.ExpressionVisitors.cs index ea94b338492..b106a121cb1 100644 --- a/src/EFCore/Query/Internal/NavigationExpandingExpressionVisitor.ExpressionVisitors.cs +++ b/src/EFCore/Query/Internal/NavigationExpandingExpressionVisitor.ExpressionVisitors.cs @@ -124,7 +124,7 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp var navigation = memberIdentity.MemberInfo != null ? entityType.FindNavigation(memberIdentity.MemberInfo) - : entityType.FindNavigation(memberIdentity.Name); + : entityType.FindNavigation(memberIdentity.Name!); if (navigation != null) { return ExpandNavigation(root, entityReference, navigation, convertedType != null); @@ -132,7 +132,9 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp var skipNavigation = memberIdentity.MemberInfo != null ? entityType.FindSkipNavigation(memberIdentity.MemberInfo) - : entityType.FindSkipNavigation(memberIdentity.Name); + : memberIdentity.Name is not null + ? entityType.FindSkipNavigation(memberIdentity.Name) + : null; if (skipNavigation != null) { return ExpandSkipNavigation(root, entityReference, skipNavigation, convertedType != null);