diff --git a/src/EFCore.Relational/Design/AnnotationCodeGenerator.cs b/src/EFCore.Relational/Design/AnnotationCodeGenerator.cs index be4440770ca..a601cfbef14 100644 --- a/src/EFCore.Relational/Design/AnnotationCodeGenerator.cs +++ b/src/EFCore.Relational/Design/AnnotationCodeGenerator.cs @@ -10,7 +10,9 @@ using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Metadata.Internal; using Microsoft.EntityFrameworkCore.Utilities; +using NotNullWhenAttribute = System.Diagnostics.CodeAnalysis.NotNullWhenAttribute; +#nullable enable #pragma warning disable EF1001 // Accessing annotation names (internal) namespace Microsoft.EntityFrameworkCore.Design @@ -144,10 +146,10 @@ public virtual IReadOnlyList GenerateFluentApiCalls( annotations, RelationalAnnotationNames.ColumnName, nameof(RelationalPropertyBuilderExtensions.HasColumnName), methodCallCodeFragments); - if (TryGetAndRemove(annotations, RelationalAnnotationNames.DefaultValueSql, out string defaultValueSql)) + if (TryGetAndRemove(annotations, RelationalAnnotationNames.DefaultValueSql, out string? defaultValueSql)) { methodCallCodeFragments.Add( - defaultValueSql?.Length == 0 + defaultValueSql.Length == 0 ? new MethodCallCodeFragment( nameof(RelationalPropertyBuilderExtensions.HasDefaultValueSql)) : new MethodCallCodeFragment( @@ -155,10 +157,10 @@ public virtual IReadOnlyList GenerateFluentApiCalls( defaultValueSql)); } - if (TryGetAndRemove(annotations, RelationalAnnotationNames.ComputedColumnSql, out string computedColumnSql)) + if (TryGetAndRemove(annotations, RelationalAnnotationNames.ComputedColumnSql, out string? computedColumnSql)) { methodCallCodeFragments.Add( - computedColumnSql?.Length == 0 + computedColumnSql.Length == 0 ? new MethodCallCodeFragment( nameof(RelationalPropertyBuilderExtensions.HasComputedColumnSql)) : TryGetAndRemove(annotations, RelationalAnnotationNames.IsStored, out bool isStored) @@ -437,7 +439,7 @@ protected virtual bool IsHandledByConvention([NotNull] IIndex index, [NotNull] I /// The . /// The . /// . - protected virtual MethodCallCodeFragment GenerateFluentApi([NotNull] IModel model, [NotNull] IAnnotation annotation) + protected virtual MethodCallCodeFragment? GenerateFluentApi([NotNull] IModel model, [NotNull] IAnnotation annotation) { Check.NotNull(model, nameof(model)); Check.NotNull(annotation, nameof(annotation)); @@ -457,7 +459,7 @@ protected virtual MethodCallCodeFragment GenerateFluentApi([NotNull] IModel mode /// The . /// The . /// . - protected virtual MethodCallCodeFragment GenerateFluentApi([NotNull] IEntityType entityType, [NotNull] IAnnotation annotation) + protected virtual MethodCallCodeFragment? GenerateFluentApi([NotNull] IEntityType entityType, [NotNull] IAnnotation annotation) { Check.NotNull(entityType, nameof(entityType)); Check.NotNull(annotation, nameof(annotation)); @@ -477,7 +479,7 @@ protected virtual MethodCallCodeFragment GenerateFluentApi([NotNull] IEntityType /// The . /// The . /// . - protected virtual MethodCallCodeFragment GenerateFluentApi([NotNull] IKey key, [NotNull] IAnnotation annotation) + protected virtual MethodCallCodeFragment? GenerateFluentApi([NotNull] IKey key, [NotNull] IAnnotation annotation) { Check.NotNull(key, nameof(key)); Check.NotNull(annotation, nameof(annotation)); @@ -497,7 +499,7 @@ protected virtual MethodCallCodeFragment GenerateFluentApi([NotNull] IKey key, [ /// The . /// The . /// . - protected virtual MethodCallCodeFragment GenerateFluentApi([NotNull] IProperty property, [NotNull] IAnnotation annotation) + protected virtual MethodCallCodeFragment? GenerateFluentApi([NotNull] IProperty property, [NotNull] IAnnotation annotation) { Check.NotNull(property, nameof(property)); Check.NotNull(annotation, nameof(annotation)); @@ -517,7 +519,7 @@ protected virtual MethodCallCodeFragment GenerateFluentApi([NotNull] IProperty p /// The . /// The . /// . - protected virtual MethodCallCodeFragment GenerateFluentApi([NotNull] IForeignKey foreignKey, [NotNull] IAnnotation annotation) + protected virtual MethodCallCodeFragment? GenerateFluentApi([NotNull] IForeignKey foreignKey, [NotNull] IAnnotation annotation) { Check.NotNull(foreignKey, nameof(foreignKey)); Check.NotNull(annotation, nameof(annotation)); @@ -537,7 +539,7 @@ protected virtual MethodCallCodeFragment GenerateFluentApi([NotNull] IForeignKey /// The . /// The . /// . - protected virtual MethodCallCodeFragment GenerateFluentApi([NotNull] INavigation navigation, [NotNull] IAnnotation annotation) + protected virtual MethodCallCodeFragment? GenerateFluentApi([NotNull] INavigation navigation, [NotNull] IAnnotation annotation) { Check.NotNull(navigation, nameof(navigation)); Check.NotNull(annotation, nameof(annotation)); @@ -557,7 +559,7 @@ protected virtual MethodCallCodeFragment GenerateFluentApi([NotNull] INavigation /// The . /// The . /// . - protected virtual MethodCallCodeFragment GenerateFluentApi([NotNull] ISkipNavigation navigation, [NotNull] IAnnotation annotation) + protected virtual MethodCallCodeFragment? GenerateFluentApi([NotNull] ISkipNavigation navigation, [NotNull] IAnnotation annotation) { Check.NotNull(navigation, nameof(navigation)); Check.NotNull(annotation, nameof(annotation)); @@ -577,7 +579,7 @@ protected virtual MethodCallCodeFragment GenerateFluentApi([NotNull] ISkipNaviga /// The . /// The . /// . - protected virtual MethodCallCodeFragment GenerateFluentApi([NotNull] IIndex index, [NotNull] IAnnotation annotation) + protected virtual MethodCallCodeFragment? GenerateFluentApi([NotNull] IIndex index, [NotNull] IAnnotation annotation) { Check.NotNull(index, nameof(index)); Check.NotNull(annotation, nameof(annotation)); @@ -597,7 +599,7 @@ protected virtual MethodCallCodeFragment GenerateFluentApi([NotNull] IIndex inde /// The . /// The . /// . - protected virtual AttributeCodeFragment GenerateDataAnnotation([NotNull] IEntityType entityType, [NotNull] IAnnotation annotation) + protected virtual AttributeCodeFragment? GenerateDataAnnotation([NotNull] IEntityType entityType, [NotNull] IAnnotation annotation) { Check.NotNull(entityType, nameof(entityType)); Check.NotNull(annotation, nameof(annotation)); @@ -617,7 +619,7 @@ protected virtual AttributeCodeFragment GenerateDataAnnotation([NotNull] IEntity /// The . /// The . /// . - protected virtual AttributeCodeFragment GenerateDataAnnotation([NotNull] IProperty property, [NotNull] IAnnotation annotation) + protected virtual AttributeCodeFragment? GenerateDataAnnotation([NotNull] IProperty property, [NotNull] IAnnotation annotation) { Check.NotNull(property, nameof(property)); Check.NotNull(annotation, nameof(annotation)); @@ -628,7 +630,8 @@ protected virtual AttributeCodeFragment GenerateDataAnnotation([NotNull] IProper private IEnumerable GenerateFluentApiCallsHelper( TAnnotatable annotatable, IDictionary annotations, - Func generateCodeFragment) + Func generateCodeFragment) + where TCodeFragment : notnull { foreach (var (name, annotation) in EnumerateForRemoval(annotations)) { @@ -655,7 +658,7 @@ private void RemoveConventionalAnnotationsHelper( } } - private static bool TryGetAndRemove(IDictionary annotations, string annotationName, out T annotationValue) + private static bool TryGetAndRemove(IDictionary annotations, string annotationName, [NotNullWhen(true)] out T? annotationValue) { if (annotations.TryGetValue(annotationName, out var annotation) && annotation.Value != null) diff --git a/src/EFCore.Relational/Design/AnnotationCodeGeneratorDependencies.cs b/src/EFCore.Relational/Design/AnnotationCodeGeneratorDependencies.cs index ee20a777691..49453ae9beb 100644 --- a/src/EFCore.Relational/Design/AnnotationCodeGeneratorDependencies.cs +++ b/src/EFCore.Relational/Design/AnnotationCodeGeneratorDependencies.cs @@ -6,6 +6,8 @@ using Microsoft.EntityFrameworkCore.Storage; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Design { /// diff --git a/src/EFCore.Relational/Design/AttributeCodeFragment.cs b/src/EFCore.Relational/Design/AttributeCodeFragment.cs index 02b0d9bc100..deac6eea012 100644 --- a/src/EFCore.Relational/Design/AttributeCodeFragment.cs +++ b/src/EFCore.Relational/Design/AttributeCodeFragment.cs @@ -6,6 +6,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Design { /// diff --git a/src/EFCore.Relational/Design/IAnnotationCodeGenerator.cs b/src/EFCore.Relational/Design/IAnnotationCodeGenerator.cs index e017e8117a8..b8e91ec9259 100644 --- a/src/EFCore.Relational/Design/IAnnotationCodeGenerator.cs +++ b/src/EFCore.Relational/Design/IAnnotationCodeGenerator.cs @@ -7,6 +7,8 @@ using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Design { /// diff --git a/src/EFCore.Relational/Design/MethodCallCodeFragment.cs b/src/EFCore.Relational/Design/MethodCallCodeFragment.cs index 5573850a7f7..280ac62a130 100644 --- a/src/EFCore.Relational/Design/MethodCallCodeFragment.cs +++ b/src/EFCore.Relational/Design/MethodCallCodeFragment.cs @@ -5,6 +5,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Design { /// @@ -12,20 +14,20 @@ namespace Microsoft.EntityFrameworkCore.Design /// public class MethodCallCodeFragment { - private readonly List _arguments; + private readonly List _arguments; /// /// Initializes a new instance of the class. /// /// The method's name. /// The method call's arguments. Can be . - public MethodCallCodeFragment([NotNull] string method, [NotNull] params object[] arguments) + public MethodCallCodeFragment([NotNull] string method, [NotNull] params object?[] arguments) { Check.NotEmpty(method, nameof(method)); Check.NotNull(arguments, nameof(arguments)); Method = method; - _arguments = new List(arguments); + _arguments = new List(arguments); } /// @@ -36,7 +38,7 @@ public MethodCallCodeFragment([NotNull] string method, [NotNull] params object[] /// The next method call to chain after this. public MethodCallCodeFragment( [NotNull] string method, - [NotNull] object[] arguments, + [NotNull] object?[] arguments, [NotNull] MethodCallCodeFragment chainedCall) : this(method, arguments) { @@ -55,14 +57,14 @@ public MethodCallCodeFragment( /// Gets the method call's arguments. /// /// The method call's arguments. - public virtual IReadOnlyList Arguments + public virtual IReadOnlyList Arguments => _arguments; /// /// Gets the next method call to chain after this. /// /// The next method call. - public virtual MethodCallCodeFragment ChainedCall { get; } + public virtual MethodCallCodeFragment? ChainedCall { get; } /// /// Creates a method chain from this method to another. diff --git a/src/EFCore.Relational/Design/NestedClosureCodeFragment.cs b/src/EFCore.Relational/Design/NestedClosureCodeFragment.cs index fe25877ee34..2102a87a683 100644 --- a/src/EFCore.Relational/Design/NestedClosureCodeFragment.cs +++ b/src/EFCore.Relational/Design/NestedClosureCodeFragment.cs @@ -4,6 +4,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Design { /// diff --git a/src/EFCore.Relational/Scaffolding/DatabaseModelFactory.cs b/src/EFCore.Relational/Scaffolding/DatabaseModelFactory.cs index 5eddcdd829f..711069444ee 100644 --- a/src/EFCore.Relational/Scaffolding/DatabaseModelFactory.cs +++ b/src/EFCore.Relational/Scaffolding/DatabaseModelFactory.cs @@ -4,6 +4,8 @@ using System.Data.Common; using Microsoft.EntityFrameworkCore.Scaffolding.Metadata; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Scaffolding { /// diff --git a/src/EFCore.Relational/Scaffolding/DatabaseModelFactoryOptions.cs b/src/EFCore.Relational/Scaffolding/DatabaseModelFactoryOptions.cs index cd6ccd990bb..f070ce0df46 100644 --- a/src/EFCore.Relational/Scaffolding/DatabaseModelFactoryOptions.cs +++ b/src/EFCore.Relational/Scaffolding/DatabaseModelFactoryOptions.cs @@ -5,6 +5,8 @@ using System.Linq; using JetBrains.Annotations; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Scaffolding { /// @@ -17,7 +19,7 @@ public class DatabaseModelFactoryOptions /// /// A list of tables to include. Empty to include all tables. /// A list of schemas to include. Empty to include all schemas. - public DatabaseModelFactoryOptions([CanBeNull] IEnumerable tables = null, [CanBeNull] IEnumerable schemas = null) + public DatabaseModelFactoryOptions([CanBeNull] IEnumerable? tables = null, [CanBeNull] IEnumerable? schemas = null) { Tables = tables ?? Enumerable.Empty(); Schemas = schemas ?? Enumerable.Empty(); diff --git a/src/EFCore.Relational/Scaffolding/IDatabaseModelFactory.cs b/src/EFCore.Relational/Scaffolding/IDatabaseModelFactory.cs index 0113420c000..0b0163b9273 100644 --- a/src/EFCore.Relational/Scaffolding/IDatabaseModelFactory.cs +++ b/src/EFCore.Relational/Scaffolding/IDatabaseModelFactory.cs @@ -5,6 +5,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Scaffolding.Metadata; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Scaffolding { /// diff --git a/src/EFCore.Relational/Scaffolding/IProviderCodeGeneratorPlugin.cs b/src/EFCore.Relational/Scaffolding/IProviderCodeGeneratorPlugin.cs index d203069dad2..3ae09504f4b 100644 --- a/src/EFCore.Relational/Scaffolding/IProviderCodeGeneratorPlugin.cs +++ b/src/EFCore.Relational/Scaffolding/IProviderCodeGeneratorPlugin.cs @@ -3,6 +3,8 @@ using Microsoft.EntityFrameworkCore.Design; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Scaffolding { /// @@ -14,12 +16,12 @@ public interface IProviderCodeGeneratorPlugin /// Generates a method chain used to configure provider-specific options. /// /// The method chain. May be null. - MethodCallCodeFragment GenerateProviderOptions(); + MethodCallCodeFragment? GenerateProviderOptions(); /// /// Generates a method chain to configure additional context options. /// /// The method chain. May be null. - MethodCallCodeFragment GenerateContextOptions(); + MethodCallCodeFragment? GenerateContextOptions(); } } diff --git a/src/EFCore.Relational/Scaffolding/IProviderConfigurationCodeGenerator.cs b/src/EFCore.Relational/Scaffolding/IProviderConfigurationCodeGenerator.cs index 8b1b3cc794f..caf1432224a 100644 --- a/src/EFCore.Relational/Scaffolding/IProviderConfigurationCodeGenerator.cs +++ b/src/EFCore.Relational/Scaffolding/IProviderConfigurationCodeGenerator.cs @@ -4,6 +4,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Design; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Scaffolding { /// @@ -16,7 +18,7 @@ public interface IProviderConfigurationCodeGenerator /// Generates a method chain used to configure provider-specific options. /// /// The method chain. May be null. - MethodCallCodeFragment GenerateProviderOptions(); + MethodCallCodeFragment? GenerateProviderOptions(); /// /// Generates a code fragment like .UseSqlServer("Database=Foo") which can be used in @@ -27,13 +29,13 @@ public interface IProviderConfigurationCodeGenerator /// The code fragment. MethodCallCodeFragment GenerateUseProvider( [NotNull] string connectionString, - [CanBeNull] MethodCallCodeFragment providerOptions); + [CanBeNull] MethodCallCodeFragment? providerOptions); /// /// Generates a method chain to configure additional context options. /// /// The method chain. May be null. - MethodCallCodeFragment GenerateContextOptions(); + MethodCallCodeFragment? GenerateContextOptions(); /// /// Generates a code fragment like .UseSqlServer("Database=Foo") which can be used in diff --git a/src/EFCore.Relational/Scaffolding/Metadata/DatabaseColumn.cs b/src/EFCore.Relational/Scaffolding/Metadata/DatabaseColumn.cs index d3901ed054c..b60f6b3c825 100644 --- a/src/EFCore.Relational/Scaffolding/Metadata/DatabaseColumn.cs +++ b/src/EFCore.Relational/Scaffolding/Metadata/DatabaseColumn.cs @@ -1,9 +1,13 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata; +using DisallowNullAttribute = System.Diagnostics.CodeAnalysis.DisallowNullAttribute; + +#nullable enable namespace Microsoft.EntityFrameworkCore.Scaffolding.Metadata { @@ -15,12 +19,14 @@ public class DatabaseColumn : Annotatable /// /// The table that contains this column. /// - public virtual DatabaseTable Table { get; [param: NotNull] set; } + [DisallowNull] + public virtual DatabaseTable? Table { get; [param: NotNull] set; } /// /// The column name. /// - public virtual string Name { get; [param: NotNull] set; } + [DisallowNull] + public virtual string? Name { get; [param: NotNull] set; } /// /// Indicates whether or not this column can contain values. @@ -30,18 +36,18 @@ public class DatabaseColumn : Annotatable /// /// The database/store type of the column. /// - public virtual string StoreType { get; [param: CanBeNull] set; } + public virtual string? StoreType { get; [param: CanBeNull] set; } /// /// The default constraint for the column, or if none. /// - public virtual string DefaultValueSql { get; [param: CanBeNull] set; } + public virtual string? DefaultValueSql { get; [param: CanBeNull] set; } /// /// Whether the value of the computed column this property is mapped to is stored in the database, or calculated when /// it is read. /// - public virtual string ComputedColumnSql { get; [param: CanBeNull] set; } + public virtual string? ComputedColumnSql { get; [param: CanBeNull] set; } /// /// Whether the value of the computed column this property is mapped to is stored in the database, or calculated when @@ -52,12 +58,12 @@ public class DatabaseColumn : Annotatable /// /// The column comment, or if none is set. /// - public virtual string Comment { get; [param: CanBeNull] set; } + public virtual string? Comment { get; [param: CanBeNull] set; } /// /// The column collation, or if none is set. /// - public virtual string Collation { get; [param: CanBeNull] set; } + public virtual string? Collation { get; [param: CanBeNull] set; } /// /// Indicates when values will be generated by the database for this column, or if diff --git a/src/EFCore.Relational/Scaffolding/Metadata/DatabaseForeignKey.cs b/src/EFCore.Relational/Scaffolding/Metadata/DatabaseForeignKey.cs index 6326e0ce23f..41f5492c1b1 100644 --- a/src/EFCore.Relational/Scaffolding/Metadata/DatabaseForeignKey.cs +++ b/src/EFCore.Relational/Scaffolding/Metadata/DatabaseForeignKey.cs @@ -5,6 +5,9 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Migrations; +using DisallowNullAttribute = System.Diagnostics.CodeAnalysis.DisallowNullAttribute; + +#nullable enable namespace Microsoft.EntityFrameworkCore.Scaffolding.Metadata { @@ -16,12 +19,14 @@ public class DatabaseForeignKey : Annotatable /// /// The table that contains the foreign key constraint. /// - public virtual DatabaseTable Table { get; [param: NotNull] set; } + [DisallowNull] + public virtual DatabaseTable? Table { get; [param: NotNull] set; } /// /// The table to which the columns are constrained. /// - public virtual DatabaseTable PrincipalTable { get; [param: NotNull] set; } + [DisallowNull] + public virtual DatabaseTable? PrincipalTable { get; [param: NotNull] set; } /// /// The ordered list of columns that are constrained. @@ -37,7 +42,7 @@ public class DatabaseForeignKey : Annotatable /// /// The foreign key constraint name. /// - public virtual string Name { get; [param: CanBeNull] set; } + public virtual string? Name { get; [param: CanBeNull] set; } /// /// The action performed by the database when a row constrained by this foreign key diff --git a/src/EFCore.Relational/Scaffolding/Metadata/DatabaseIndex.cs b/src/EFCore.Relational/Scaffolding/Metadata/DatabaseIndex.cs index 7185ca69ed6..218844e03c9 100644 --- a/src/EFCore.Relational/Scaffolding/Metadata/DatabaseIndex.cs +++ b/src/EFCore.Relational/Scaffolding/Metadata/DatabaseIndex.cs @@ -5,6 +5,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Infrastructure; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Scaffolding.Metadata { /// @@ -15,12 +17,12 @@ public class DatabaseIndex : Annotatable /// /// The table that contains the index. /// - public virtual DatabaseTable Table { get; [param: CanBeNull] set; } + public virtual DatabaseTable? Table { get; [param: CanBeNull] set; } /// /// The index name. /// - public virtual string Name { get; [param: CanBeNull] set; } + public virtual string? Name { get; [param: CanBeNull] set; } /// /// The ordered list of columns that make up the index. @@ -35,7 +37,7 @@ public class DatabaseIndex : Annotatable /// /// The filter expression, or if the index has no filter. /// - public virtual string Filter { get; [param: CanBeNull] set; } + public virtual string? Filter { get; [param: CanBeNull] set; } /// public override string ToString() diff --git a/src/EFCore.Relational/Scaffolding/Metadata/DatabaseModel.cs b/src/EFCore.Relational/Scaffolding/Metadata/DatabaseModel.cs index 39f815ab3a3..6f3c34472b5 100644 --- a/src/EFCore.Relational/Scaffolding/Metadata/DatabaseModel.cs +++ b/src/EFCore.Relational/Scaffolding/Metadata/DatabaseModel.cs @@ -5,6 +5,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Infrastructure; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Scaffolding.Metadata { /// @@ -15,17 +17,17 @@ public class DatabaseModel : Annotatable /// /// The database name, or if none is set. /// - public virtual string DatabaseName { get; [param: CanBeNull] set; } + public virtual string? DatabaseName { get; [param: CanBeNull] set; } /// /// The database schema, or to use the default schema. /// - public virtual string DefaultSchema { get; [param: CanBeNull] set; } + public virtual string? DefaultSchema { get; [param: CanBeNull] set; } /// /// The database collation, or if none is set. /// - public virtual string Collation { get; [param: CanBeNull] set; } + public virtual string? Collation { get; [param: CanBeNull] set; } /// /// The list of tables in the database. diff --git a/src/EFCore.Relational/Scaffolding/Metadata/DatabasePrimaryKey.cs b/src/EFCore.Relational/Scaffolding/Metadata/DatabasePrimaryKey.cs index 498c5046651..b47c8c8d73d 100644 --- a/src/EFCore.Relational/Scaffolding/Metadata/DatabasePrimaryKey.cs +++ b/src/EFCore.Relational/Scaffolding/Metadata/DatabasePrimaryKey.cs @@ -5,6 +5,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Infrastructure; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Scaffolding.Metadata { /// @@ -15,12 +17,12 @@ public class DatabasePrimaryKey : Annotatable /// /// The table on which the primary key is defined. /// - public virtual DatabaseTable Table { get; [param: CanBeNull] set; } + public virtual DatabaseTable? Table { get; [param: CanBeNull] set; } /// /// The name of the primary key. /// - public virtual string Name { get; [param: CanBeNull] set; } + public virtual string? Name { get; [param: CanBeNull] set; } /// /// The ordered list of columns that make up the primary key. diff --git a/src/EFCore.Relational/Scaffolding/Metadata/DatabaseSequence.cs b/src/EFCore.Relational/Scaffolding/Metadata/DatabaseSequence.cs index 151ef352122..66815334f8b 100644 --- a/src/EFCore.Relational/Scaffolding/Metadata/DatabaseSequence.cs +++ b/src/EFCore.Relational/Scaffolding/Metadata/DatabaseSequence.cs @@ -3,6 +3,9 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Infrastructure; +using DisallowNullAttribute = System.Diagnostics.CodeAnalysis.DisallowNullAttribute; + +#nullable enable namespace Microsoft.EntityFrameworkCore.Scaffolding.Metadata { @@ -14,22 +17,24 @@ public class DatabaseSequence : Annotatable /// /// The database that contains the sequence. /// - public virtual DatabaseModel Database { get; [param: NotNull] set; } + [DisallowNull] + public virtual DatabaseModel? Database { get; [param: NotNull] set; } /// /// The sequence name. /// - public virtual string Name { get; [param: NotNull] set; } + [DisallowNull] + public virtual string? Name { get; [param: NotNull] set; } /// /// The schema that contains the sequence, or to use the default schema. /// - public virtual string Schema { get; [param: CanBeNull] set; } + public virtual string? Schema { get; [param: CanBeNull] set; } /// /// The database/store type of the sequence, or if not set. /// - public virtual string StoreType { get; [param: CanBeNull] set; } + public virtual string? StoreType { get; [param: CanBeNull] set; } /// /// The start value for the sequence, or if not set. diff --git a/src/EFCore.Relational/Scaffolding/Metadata/DatabaseTable.cs b/src/EFCore.Relational/Scaffolding/Metadata/DatabaseTable.cs index ed15740a63f..a73705d1e10 100644 --- a/src/EFCore.Relational/Scaffolding/Metadata/DatabaseTable.cs +++ b/src/EFCore.Relational/Scaffolding/Metadata/DatabaseTable.cs @@ -4,6 +4,9 @@ using System.Collections.Generic; using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Infrastructure; +using DisallowNullAttribute = System.Diagnostics.CodeAnalysis.DisallowNullAttribute; + +#nullable enable namespace Microsoft.EntityFrameworkCore.Scaffolding.Metadata { @@ -15,27 +18,28 @@ public class DatabaseTable : Annotatable /// /// The database that contains the table. /// - public virtual DatabaseModel Database { get; [param: CanBeNull] set; } + public virtual DatabaseModel? Database { get; [param: CanBeNull] set; } /// /// The table name. /// - public virtual string Name { get; [param: NotNull] set; } + [DisallowNull] + public virtual string? Name { get; [param: NotNull] set; } /// /// The table schema, or to use the default schema. /// - public virtual string Schema { get; [param: CanBeNull] set; } + public virtual string? Schema { get; [param: CanBeNull] set; } /// /// The table comment, or if none is set. /// - public virtual string Comment { get; [param: CanBeNull] set; } + public virtual string? Comment { get; [param: CanBeNull] set; } /// /// The primary key of the table. /// - public virtual DatabasePrimaryKey PrimaryKey { get; [param: CanBeNull] set; } + public virtual DatabasePrimaryKey? PrimaryKey { get; [param: CanBeNull] set; } /// /// The ordered list of columns in the table. diff --git a/src/EFCore.Relational/Scaffolding/Metadata/DatabaseUniqueConstraint.cs b/src/EFCore.Relational/Scaffolding/Metadata/DatabaseUniqueConstraint.cs index c04eb7dde2c..eadadf5d123 100644 --- a/src/EFCore.Relational/Scaffolding/Metadata/DatabaseUniqueConstraint.cs +++ b/src/EFCore.Relational/Scaffolding/Metadata/DatabaseUniqueConstraint.cs @@ -4,6 +4,9 @@ using System.Collections.Generic; using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Infrastructure; +using DisallowNullAttribute = System.Diagnostics.CodeAnalysis.DisallowNullAttribute; + +#nullable enable namespace Microsoft.EntityFrameworkCore.Scaffolding.Metadata { @@ -15,12 +18,13 @@ public class DatabaseUniqueConstraint : Annotatable /// /// The table on which the unique constraint is defined. /// - public virtual DatabaseTable Table { get; [param: NotNull] set; } + [DisallowNull] + public virtual DatabaseTable? Table { get; [param: NotNull] set; } /// /// The name of the constraint. /// - public virtual string Name { get; [param: CanBeNull] set; } + public virtual string? Name { get; [param: CanBeNull] set; } /// /// The ordered list of columns that make up the constraint. diff --git a/src/EFCore.Relational/Scaffolding/Metadata/DatabaseView.cs b/src/EFCore.Relational/Scaffolding/Metadata/DatabaseView.cs index 1f936e7ad18..40c71be3214 100644 --- a/src/EFCore.Relational/Scaffolding/Metadata/DatabaseView.cs +++ b/src/EFCore.Relational/Scaffolding/Metadata/DatabaseView.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.Scaffolding.Metadata { /// diff --git a/src/EFCore.Relational/Scaffolding/ProviderCodeGenerator.cs b/src/EFCore.Relational/Scaffolding/ProviderCodeGenerator.cs index f48a8815497..fd6ee40905d 100644 --- a/src/EFCore.Relational/Scaffolding/ProviderCodeGenerator.cs +++ b/src/EFCore.Relational/Scaffolding/ProviderCodeGenerator.cs @@ -5,6 +5,8 @@ using Microsoft.EntityFrameworkCore.Design; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Scaffolding { /// @@ -28,9 +30,9 @@ protected ProviderCodeGenerator([NotNull] ProviderCodeGeneratorDependencies depe /// Generates a method chain used to configure provider-specific options. /// /// The method chain. May be null. - public virtual MethodCallCodeFragment GenerateProviderOptions() + public virtual MethodCallCodeFragment? GenerateProviderOptions() { - MethodCallCodeFragment providerOptions = null; + MethodCallCodeFragment? providerOptions = null; foreach (var plugin in Dependencies.Plugins) { @@ -55,15 +57,15 @@ public virtual MethodCallCodeFragment GenerateProviderOptions() /// The code fragment. public abstract MethodCallCodeFragment GenerateUseProvider( string connectionString, - MethodCallCodeFragment providerOptions); + MethodCallCodeFragment? providerOptions); /// /// Generates a method chain to configure additional context options. /// /// The method chain. May be null. - public virtual MethodCallCodeFragment GenerateContextOptions() + public virtual MethodCallCodeFragment? GenerateContextOptions() { - MethodCallCodeFragment contextOptions = null; + MethodCallCodeFragment? contextOptions = null; foreach (var plugin in Dependencies.Plugins) { diff --git a/src/EFCore.Relational/Scaffolding/ProviderCodeGeneratorDependencies.cs b/src/EFCore.Relational/Scaffolding/ProviderCodeGeneratorDependencies.cs index bc24f0cafb4..b898477b061 100644 --- a/src/EFCore.Relational/Scaffolding/ProviderCodeGeneratorDependencies.cs +++ b/src/EFCore.Relational/Scaffolding/ProviderCodeGeneratorDependencies.cs @@ -6,6 +6,8 @@ using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Scaffolding { /// diff --git a/src/EFCore.Relational/Scaffolding/ProviderCodeGeneratorPlugin.cs b/src/EFCore.Relational/Scaffolding/ProviderCodeGeneratorPlugin.cs index 472d9ab6174..eae9aff7fca 100644 --- a/src/EFCore.Relational/Scaffolding/ProviderCodeGeneratorPlugin.cs +++ b/src/EFCore.Relational/Scaffolding/ProviderCodeGeneratorPlugin.cs @@ -3,6 +3,8 @@ using Microsoft.EntityFrameworkCore.Design; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Scaffolding { /// @@ -14,14 +16,14 @@ public class ProviderCodeGeneratorPlugin : IProviderCodeGeneratorPlugin /// Generates a method chain used to configure provider-specific options. /// /// The method chain. May be null. - public virtual MethodCallCodeFragment GenerateContextOptions() + public virtual MethodCallCodeFragment? GenerateContextOptions() => null; /// /// Generates a method chain to configure additional context options. /// /// The method chain. May be null. - public virtual MethodCallCodeFragment GenerateProviderOptions() + public virtual MethodCallCodeFragment? GenerateProviderOptions() => null; } } diff --git a/src/EFCore.SqlServer.NTS/Design/Internal/SqlServerNetTopologySuiteDesignTimeServices.cs b/src/EFCore.SqlServer.NTS/Design/Internal/SqlServerNetTopologySuiteDesignTimeServices.cs index e1ad4b40e98..a7fe0519313 100644 --- a/src/EFCore.SqlServer.NTS/Design/Internal/SqlServerNetTopologySuiteDesignTimeServices.cs +++ b/src/EFCore.SqlServer.NTS/Design/Internal/SqlServerNetTopologySuiteDesignTimeServices.cs @@ -10,6 +10,8 @@ using Microsoft.Extensions.DependencyInjection.Extensions; using NetTopologySuite; +#nullable enable + namespace Microsoft.EntityFrameworkCore.SqlServer.Design.Internal { /// diff --git a/src/EFCore.SqlServer.NTS/Extensions/SqlServerNetTopologySuiteDbContextOptionsBuilderExtensions.cs b/src/EFCore.SqlServer.NTS/Extensions/SqlServerNetTopologySuiteDbContextOptionsBuilderExtensions.cs index b304c2b35ee..6d0d48a8a63 100644 --- a/src/EFCore.SqlServer.NTS/Extensions/SqlServerNetTopologySuiteDbContextOptionsBuilderExtensions.cs +++ b/src/EFCore.SqlServer.NTS/Extensions/SqlServerNetTopologySuiteDbContextOptionsBuilderExtensions.cs @@ -6,6 +6,8 @@ using Microsoft.EntityFrameworkCore.SqlServer.Infrastructure.Internal; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + namespace Microsoft.EntityFrameworkCore { /// diff --git a/src/EFCore.SqlServer.NTS/Extensions/SqlServerNetTopologySuiteServiceCollectionExtensions.cs b/src/EFCore.SqlServer.NTS/Extensions/SqlServerNetTopologySuiteServiceCollectionExtensions.cs index b5ad3c544cf..ba38a057ddf 100644 --- a/src/EFCore.SqlServer.NTS/Extensions/SqlServerNetTopologySuiteServiceCollectionExtensions.cs +++ b/src/EFCore.SqlServer.NTS/Extensions/SqlServerNetTopologySuiteServiceCollectionExtensions.cs @@ -11,6 +11,8 @@ using Microsoft.Extensions.DependencyInjection.Extensions; using NetTopologySuite; +#nullable enable + namespace Microsoft.Extensions.DependencyInjection { /// diff --git a/src/EFCore.SqlServer.NTS/Infrastructure/Internal/SqlServerNetTopologySuiteOptionsExtension.cs b/src/EFCore.SqlServer.NTS/Infrastructure/Internal/SqlServerNetTopologySuiteOptionsExtension.cs index d20f9c1176e..eab5bf08b79 100644 --- a/src/EFCore.SqlServer.NTS/Infrastructure/Internal/SqlServerNetTopologySuiteOptionsExtension.cs +++ b/src/EFCore.SqlServer.NTS/Infrastructure/Internal/SqlServerNetTopologySuiteOptionsExtension.cs @@ -10,6 +10,8 @@ using Microsoft.EntityFrameworkCore.Storage; using Microsoft.Extensions.DependencyInjection; +#nullable enable + namespace Microsoft.EntityFrameworkCore.SqlServer.Infrastructure.Internal { /// @@ -20,7 +22,7 @@ namespace Microsoft.EntityFrameworkCore.SqlServer.Infrastructure.Internal /// public class SqlServerNetTopologySuiteOptionsExtension : IDbContextOptionsExtension { - private DbContextOptionsExtensionInfo _info; + private DbContextOptionsExtensionInfo? _info; /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to diff --git a/src/EFCore.SqlServer.NTS/Scaffolding/Internal/SqlServerNetTopologySuiteCodeGeneratorPlugin.cs b/src/EFCore.SqlServer.NTS/Scaffolding/Internal/SqlServerNetTopologySuiteCodeGeneratorPlugin.cs index 96d09ee9124..59599d9c587 100644 --- a/src/EFCore.SqlServer.NTS/Scaffolding/Internal/SqlServerNetTopologySuiteCodeGeneratorPlugin.cs +++ b/src/EFCore.SqlServer.NTS/Scaffolding/Internal/SqlServerNetTopologySuiteCodeGeneratorPlugin.cs @@ -4,6 +4,8 @@ using Microsoft.EntityFrameworkCore.Design; using Microsoft.EntityFrameworkCore.Scaffolding; +#nullable enable + namespace Microsoft.EntityFrameworkCore.SqlServer.Scaffolding.Internal { /// diff --git a/src/EFCore.SqlServer.NTS/Storage/ValueConversion/Internal/GeometryValueConverter.cs b/src/EFCore.SqlServer.NTS/Storage/ValueConversion/Internal/GeometryValueConverter.cs index 2bd23aa8527..ebd95d77d84 100644 --- a/src/EFCore.SqlServer.NTS/Storage/ValueConversion/Internal/GeometryValueConverter.cs +++ b/src/EFCore.SqlServer.NTS/Storage/ValueConversion/Internal/GeometryValueConverter.cs @@ -7,6 +7,8 @@ using NetTopologySuite.Geometries; using NetTopologySuite.IO; +#nullable enable + namespace Microsoft.EntityFrameworkCore.SqlServer.Storage.ValueConversion.Internal { /// diff --git a/src/EFCore.SqlServer/Design/Internal/SqlServerAnnotationCodeGenerator.cs b/src/EFCore.SqlServer/Design/Internal/SqlServerAnnotationCodeGenerator.cs index a4a39b55a58..9f13efd3cb1 100644 --- a/src/EFCore.SqlServer/Design/Internal/SqlServerAnnotationCodeGenerator.cs +++ b/src/EFCore.SqlServer/Design/Internal/SqlServerAnnotationCodeGenerator.cs @@ -11,6 +11,8 @@ using Microsoft.EntityFrameworkCore.SqlServer.Metadata.Internal; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + namespace Microsoft.EntityFrameworkCore.SqlServer.Design.Internal { /// @@ -93,11 +95,11 @@ protected override bool IsHandledByConvention(IModel model, IAnnotation annotati if (annotation.Name == RelationalAnnotationNames.DefaultSchema) { - return (string)annotation.Value == "dbo"; + return (string?)annotation.Value == "dbo"; } return annotation.Name == SqlServerAnnotationNames.ValueGenerationStrategy - && (SqlServerValueGenerationStrategy)annotation.Value == SqlServerValueGenerationStrategy.IdentityColumn; + && (SqlServerValueGenerationStrategy)annotation.Value! == SqlServerValueGenerationStrategy.IdentityColumn; } /// @@ -106,9 +108,9 @@ protected override bool IsHandledByConvention(IModel model, IAnnotation annotati /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - protected override MethodCallCodeFragment GenerateFluentApi(IKey key, IAnnotation annotation) + protected override MethodCallCodeFragment? GenerateFluentApi(IKey key, IAnnotation annotation) => annotation.Name == SqlServerAnnotationNames.Clustered - ? (bool)annotation.Value == false + ? (bool)annotation.Value! == false ? new MethodCallCodeFragment(nameof(SqlServerIndexBuilderExtensions.IsClustered), false) : new MethodCallCodeFragment(nameof(SqlServerIndexBuilderExtensions.IsClustered)) : null; @@ -119,10 +121,10 @@ protected override MethodCallCodeFragment GenerateFluentApi(IKey key, IAnnotatio /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - protected override MethodCallCodeFragment GenerateFluentApi(IIndex index, IAnnotation annotation) + protected override MethodCallCodeFragment? GenerateFluentApi(IIndex index, IAnnotation annotation) => annotation.Name switch { - SqlServerAnnotationNames.Clustered => (bool)annotation.Value == false + SqlServerAnnotationNames.Clustered => (bool)annotation.Value! == false ? new MethodCallCodeFragment(nameof(SqlServerIndexBuilderExtensions.IsClustered), false) : new MethodCallCodeFragment(nameof(SqlServerIndexBuilderExtensions.IsClustered)), @@ -135,7 +137,7 @@ protected override MethodCallCodeFragment GenerateFluentApi(IIndex index, IAnnot _ => null }; - private MethodCallCodeFragment GenerateValueGenerationStrategy( + private MethodCallCodeFragment? GenerateValueGenerationStrategy( IDictionary annotations, bool onModel) { @@ -175,8 +177,8 @@ private MethodCallCodeFragment GenerateValueGenerationStrategy( (name, schema) switch { (null, null) => Array.Empty(), - (_, null) => new object[] { name }, - _ => new object[] { name, schema } + (_, null) => new object[] { name! }, + _ => new object[] { name!, schema! } }); case SqlServerValueGenerationStrategy.None: @@ -190,7 +192,7 @@ private MethodCallCodeFragment GenerateValueGenerationStrategy( } } - private static T GetAndRemove(IDictionary annotations, string annotationName) + private static T? GetAndRemove(IDictionary annotations, string annotationName) { if (annotations.TryGetValue(annotationName, out var annotation) && annotation.Value != null) diff --git a/src/EFCore.SqlServer/Design/Internal/SqlServerDesignTimeServices.cs b/src/EFCore.SqlServer/Design/Internal/SqlServerDesignTimeServices.cs index 997af8fcd4f..1210c28ef1d 100644 --- a/src/EFCore.SqlServer/Design/Internal/SqlServerDesignTimeServices.cs +++ b/src/EFCore.SqlServer/Design/Internal/SqlServerDesignTimeServices.cs @@ -10,6 +10,8 @@ using Microsoft.EntityFrameworkCore.Storage; using Microsoft.Extensions.DependencyInjection; +#nullable enable + namespace Microsoft.EntityFrameworkCore.SqlServer.Design.Internal { /// diff --git a/src/EFCore.SqlServer/Scaffolding/Internal/SqlDataReaderExtension.cs b/src/EFCore.SqlServer/Scaffolding/Internal/SqlDataReaderExtension.cs index 32015ae2fb1..65591cddb06 100644 --- a/src/EFCore.SqlServer/Scaffolding/Internal/SqlDataReaderExtension.cs +++ b/src/EFCore.SqlServer/Scaffolding/Internal/SqlDataReaderExtension.cs @@ -5,6 +5,8 @@ using JetBrains.Annotations; using CA = System.Diagnostics.CodeAnalysis; +#nullable enable + namespace Microsoft.EntityFrameworkCore.SqlServer.Scaffolding.Internal { /// diff --git a/src/EFCore.SqlServer/Storage/Internal/SqlServerTypeMappingSource.cs b/src/EFCore.SqlServer/Storage/Internal/SqlServerTypeMappingSource.cs index 6e129f0105c..04c808bf620 100644 --- a/src/EFCore.SqlServer/Storage/Internal/SqlServerTypeMappingSource.cs +++ b/src/EFCore.SqlServer/Storage/Internal/SqlServerTypeMappingSource.cs @@ -111,7 +111,9 @@ private readonly DoubleTypeMapping _double = new SqlServerDoubleTypeMapping("float"); private readonly SqlServerDateTimeOffsetTypeMapping _datetimeoffset +#pragma warning disable CS8620 // TODO: Follow up. Possibly dotnet/roslyn#50311 = new("datetimeoffset"); +#pragma warning restore CS8620 private readonly GuidTypeMapping _uniqueidentifier = new("uniqueidentifier", DbType.Guid); diff --git a/src/EFCore.Sqlite.Core/Design/Internal/SqliteDesignTimeServices.cs b/src/EFCore.Sqlite.Core/Design/Internal/SqliteDesignTimeServices.cs index 8cacaabc7b9..c9b27f6c800 100644 --- a/src/EFCore.Sqlite.Core/Design/Internal/SqliteDesignTimeServices.cs +++ b/src/EFCore.Sqlite.Core/Design/Internal/SqliteDesignTimeServices.cs @@ -10,6 +10,8 @@ using Microsoft.EntityFrameworkCore.Storage; using Microsoft.Extensions.DependencyInjection; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Sqlite.Design.Internal { /// diff --git a/src/EFCore.Sqlite.Core/Scaffolding/Internal/SqliteCodeGenerator.cs b/src/EFCore.Sqlite.Core/Scaffolding/Internal/SqliteCodeGenerator.cs index 4cdd63a7740..2db13fc219d 100644 --- a/src/EFCore.Sqlite.Core/Scaffolding/Internal/SqliteCodeGenerator.cs +++ b/src/EFCore.Sqlite.Core/Scaffolding/Internal/SqliteCodeGenerator.cs @@ -5,6 +5,8 @@ using Microsoft.EntityFrameworkCore.Design; using Microsoft.EntityFrameworkCore.Scaffolding; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Sqlite.Scaffolding.Internal { /// @@ -32,7 +34,7 @@ public SqliteCodeGenerator([NotNull] ProviderCodeGeneratorDependencies dependenc /// public override MethodCallCodeFragment GenerateUseProvider( string connectionString, - MethodCallCodeFragment providerOptions) + MethodCallCodeFragment? providerOptions) => new( nameof(SqliteDbContextOptionsBuilderExtensions.UseSqlite), providerOptions == null diff --git a/src/EFCore.Sqlite.Core/Scaffolding/Internal/SqliteDatabaseModelFactory.cs b/src/EFCore.Sqlite.Core/Scaffolding/Internal/SqliteDatabaseModelFactory.cs index 1cdbe2df1bb..0608a4bce4c 100644 --- a/src/EFCore.Sqlite.Core/Scaffolding/Internal/SqliteDatabaseModelFactory.cs +++ b/src/EFCore.Sqlite.Core/Scaffolding/Internal/SqliteDatabaseModelFactory.cs @@ -21,6 +21,8 @@ using Microsoft.EntityFrameworkCore.Utilities; using static SQLitePCL.raw; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Sqlite.Scaffolding.Internal { /// @@ -272,7 +274,7 @@ private void GetColumns(DbConnection connection, DatabaseTable table) } } - private string FilterClrDefaults(string dataType, bool notNull, string defaultValue) + private string? FilterClrDefaults(string dataType, bool notNull, string defaultValue) { if (string.Equals(defaultValue, "null", StringComparison.OrdinalIgnoreCase)) { @@ -281,7 +283,7 @@ private string FilterClrDefaults(string dataType, bool notNull, string defaultVa if (notNull && defaultValue == "0" - && _typeMappingSource.FindMapping(dataType).ClrType.IsNumeric()) + && _typeMappingSource.FindMapping(dataType)?.ClrType.IsNumeric() == true) { return null; } @@ -304,7 +306,7 @@ private void GetPrimaryKey(DbConnection connection, DatabaseTable table) parameter.Value = table.Name; command.Parameters.Add(parameter); - var name = (string)command.ExecuteScalar(); + var name = (string?)command.ExecuteScalar(); if (name == null) { GetRowidPrimaryKey(connection, table); @@ -513,22 +515,23 @@ private void GetForeignKeys(DbConnection connection, DatabaseTable table, IList< var principalTable = tables.FirstOrDefault(t => t.Name == principalTableName) ?? tables.FirstOrDefault( t => t.Name!.Equals(principalTableName, StringComparison.OrdinalIgnoreCase)); - var foreignKey = new DatabaseForeignKey - { - Table = table, - Name = string.Empty, - PrincipalTable = principalTable, - OnDelete = ConvertToReferentialAction(onDelete) - }; _logger.ForeignKeyFound(table.Name, id, principalTableName, onDelete); - if (foreignKey.PrincipalTable == null) + if (principalTable == null) { _logger.ForeignKeyReferencesMissingTableWarning(id.ToString(), table.Name, principalTableName); continue; } + var foreignKey = new DatabaseForeignKey + { + Table = table, + Name = string.Empty, + PrincipalTable = principalTable, + OnDelete = ConvertToReferentialAction(onDelete) + }; + using var command2 = connection.CreateCommand(); command2.CommandText = new StringBuilder() .AppendLine("SELECT \"seq\", \"from\", \"to\"") @@ -560,7 +563,7 @@ private void GetForeignKeys(DbConnection connection, DatabaseTable table, IList< Check.DebugAssert(column != null, "column is null."); var principalColumnName = reader2.IsDBNull(2) ? null : reader2.GetString(2); - DatabaseColumn principalColumn = null; + DatabaseColumn? principalColumn = null; if (principalColumnName != null) { principalColumn = diff --git a/src/EFCore.Sqlite.NTS/Design/Internal/SqliteNetTopologySuiteDesignTimeServices.cs b/src/EFCore.Sqlite.NTS/Design/Internal/SqliteNetTopologySuiteDesignTimeServices.cs index de1e092bb76..17bd1c31431 100644 --- a/src/EFCore.Sqlite.NTS/Design/Internal/SqliteNetTopologySuiteDesignTimeServices.cs +++ b/src/EFCore.Sqlite.NTS/Design/Internal/SqliteNetTopologySuiteDesignTimeServices.cs @@ -10,6 +10,8 @@ using Microsoft.Extensions.DependencyInjection.Extensions; using NetTopologySuite; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Sqlite.Design.Internal { /// diff --git a/src/EFCore.Sqlite.NTS/Extensions/SqliteNetTopologySuiteDbContextOptionsBuilderExtensions.cs b/src/EFCore.Sqlite.NTS/Extensions/SqliteNetTopologySuiteDbContextOptionsBuilderExtensions.cs index 93f04d25409..9179f02db60 100644 --- a/src/EFCore.Sqlite.NTS/Extensions/SqliteNetTopologySuiteDbContextOptionsBuilderExtensions.cs +++ b/src/EFCore.Sqlite.NTS/Extensions/SqliteNetTopologySuiteDbContextOptionsBuilderExtensions.cs @@ -6,6 +6,8 @@ using Microsoft.EntityFrameworkCore.Sqlite.Infrastructure.Internal; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + // ReSharper disable once CheckNamespace namespace Microsoft.EntityFrameworkCore { diff --git a/src/EFCore.Sqlite.NTS/Extensions/SqliteNetTopologySuiteServiceCollectionExtensions.cs b/src/EFCore.Sqlite.NTS/Extensions/SqliteNetTopologySuiteServiceCollectionExtensions.cs index c10f6698ff1..4b3cb78da84 100644 --- a/src/EFCore.Sqlite.NTS/Extensions/SqliteNetTopologySuiteServiceCollectionExtensions.cs +++ b/src/EFCore.Sqlite.NTS/Extensions/SqliteNetTopologySuiteServiceCollectionExtensions.cs @@ -11,6 +11,8 @@ using Microsoft.Extensions.DependencyInjection.Extensions; using NetTopologySuite; +#nullable enable + // ReSharper disable once CheckNamespace namespace Microsoft.Extensions.DependencyInjection { diff --git a/src/EFCore.Sqlite.NTS/Infrastructure/Internal/SqliteNetTopologySuiteOptionsExtension.cs b/src/EFCore.Sqlite.NTS/Infrastructure/Internal/SqliteNetTopologySuiteOptionsExtension.cs index 9a3bb47ddc3..f4066b799a6 100644 --- a/src/EFCore.Sqlite.NTS/Infrastructure/Internal/SqliteNetTopologySuiteOptionsExtension.cs +++ b/src/EFCore.Sqlite.NTS/Infrastructure/Internal/SqliteNetTopologySuiteOptionsExtension.cs @@ -10,6 +10,8 @@ using Microsoft.EntityFrameworkCore.Storage; using Microsoft.Extensions.DependencyInjection; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Sqlite.Infrastructure.Internal { /// @@ -20,7 +22,7 @@ namespace Microsoft.EntityFrameworkCore.Sqlite.Infrastructure.Internal /// public class SqliteNetTopologySuiteOptionsExtension : IDbContextOptionsExtension { - private DbContextOptionsExtensionInfo _info; + private DbContextOptionsExtensionInfo? _info; /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to diff --git a/src/EFCore.Sqlite.NTS/Scaffolding/Internal/SqliteNetTopologySuiteCodeGeneratorPlugin.cs b/src/EFCore.Sqlite.NTS/Scaffolding/Internal/SqliteNetTopologySuiteCodeGeneratorPlugin.cs index 5560fe3ab21..5e7ed67ab13 100644 --- a/src/EFCore.Sqlite.NTS/Scaffolding/Internal/SqliteNetTopologySuiteCodeGeneratorPlugin.cs +++ b/src/EFCore.Sqlite.NTS/Scaffolding/Internal/SqliteNetTopologySuiteCodeGeneratorPlugin.cs @@ -4,6 +4,8 @@ using Microsoft.EntityFrameworkCore.Design; using Microsoft.EntityFrameworkCore.Scaffolding; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Sqlite.Scaffolding.Internal { /// diff --git a/src/EFCore.Sqlite.NTS/Storage/ValueConversion/Internal/GeometryValueConverter.cs b/src/EFCore.Sqlite.NTS/Storage/ValueConversion/Internal/GeometryValueConverter.cs index 5e797267937..1c59f0a2bb4 100644 --- a/src/EFCore.Sqlite.NTS/Storage/ValueConversion/Internal/GeometryValueConverter.cs +++ b/src/EFCore.Sqlite.NTS/Storage/ValueConversion/Internal/GeometryValueConverter.cs @@ -6,6 +6,8 @@ using NetTopologySuite.Geometries; using NetTopologySuite.IO; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Sqlite.Storage.ValueConversion.Internal { /// diff --git a/src/EFCore/Diagnostics/CoreLoggerExtensions.cs b/src/EFCore/Diagnostics/CoreLoggerExtensions.cs index b059b0d6868..680e9cf36f1 100644 --- a/src/EFCore/Diagnostics/CoreLoggerExtensions.cs +++ b/src/EFCore/Diagnostics/CoreLoggerExtensions.cs @@ -1725,7 +1725,7 @@ public static void MultipleInversePropertiesSameTargetWarning( { definition.Log( diagnostics, - string.Join(", ", conflictingNavigations.Select(n => n.Item2.ShortDisplayName() + "." + n.Item1.Name)), + string.Join(", ", conflictingNavigations.Select(n => n.Item2.ShortDisplayName() + "." + n.Item1?.Name)), inverseNavigation.Name); }