diff --git a/src/EFCore.Relational/Migrations/HistoryRepository.cs b/src/EFCore.Relational/Migrations/HistoryRepository.cs index 9b2bdd4996e..705aeee50ed 100644 --- a/src/EFCore.Relational/Migrations/HistoryRepository.cs +++ b/src/EFCore.Relational/Migrations/HistoryRepository.cs @@ -16,6 +16,8 @@ using Microsoft.EntityFrameworkCore.Utilities; using Microsoft.Extensions.DependencyInjection; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Migrations { /// @@ -42,9 +44,9 @@ public abstract class HistoryRepository : IHistoryRepository /// public const string DefaultTableName = "__EFMigrationsHistory"; - private IModel _model; - private string _migrationIdColumnName; - private string _productVersionColumnName; + private IModel? _model; + private string? _migrationIdColumnName; + private string? _productVersionColumnName; /// /// Initializes a new instance of this class. @@ -80,15 +82,15 @@ protected virtual ISqlGenerationHelper SqlGenerationHelper /// /// The schema that contains the history table, or if the default schema should be used. /// - protected virtual string TableSchema { get; } + protected virtual string? TableSchema { get; } /// /// The name of the column that holds the Migration identifier. /// protected virtual string MigrationIdColumnName => _migrationIdColumnName ??= EnsureModel() - .FindEntityType(typeof(HistoryRow)) - .FindProperty(nameof(HistoryRow.MigrationId)) + .FindEntityType(typeof(HistoryRow))! + .FindProperty(nameof(HistoryRow.MigrationId))! .GetColumnBaseName(); private IModel EnsureModel() @@ -120,8 +122,8 @@ private IModel EnsureModel() /// protected virtual string ProductVersionColumnName => _productVersionColumnName ??= EnsureModel() - .FindEntityType(typeof(HistoryRow)) - .FindProperty(nameof(HistoryRow.ProductVersion)) + .FindEntityType(typeof(HistoryRow))! + .FindProperty(nameof(HistoryRow.ProductVersion))! .GetColumnBaseName(); /// @@ -169,7 +171,7 @@ await Dependencies.RawSqlCommandBuilder.Build(ExistsSql).ExecuteScalarAsync( /// Interprets the result of executing . /// /// if the table already exists, otherwise. - protected abstract bool InterpretExistsResult([NotNull] object value); + protected abstract bool InterpretExistsResult([CanBeNull] object? value); /// /// Overridden by a database provider to generate a SQL script that will create the history table diff --git a/src/EFCore.Relational/Migrations/HistoryRepositoryDependencies.cs b/src/EFCore.Relational/Migrations/HistoryRepositoryDependencies.cs index c450314a070..480f81b664e 100644 --- a/src/EFCore.Relational/Migrations/HistoryRepositoryDependencies.cs +++ b/src/EFCore.Relational/Migrations/HistoryRepositoryDependencies.cs @@ -10,6 +10,8 @@ using Microsoft.EntityFrameworkCore.Utilities; using Microsoft.Extensions.DependencyInjection; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Migrations { /// diff --git a/src/EFCore.Relational/Migrations/HistoryRow.cs b/src/EFCore.Relational/Migrations/HistoryRow.cs index 65a0cce171e..f477afd7b23 100644 --- a/src/EFCore.Relational/Migrations/HistoryRow.cs +++ b/src/EFCore.Relational/Migrations/HistoryRow.cs @@ -5,6 +5,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Migrations { /// diff --git a/src/EFCore.Relational/Migrations/IHistoryRepository.cs b/src/EFCore.Relational/Migrations/IHistoryRepository.cs index a46d30b305d..560ac34a60a 100644 --- a/src/EFCore.Relational/Migrations/IHistoryRepository.cs +++ b/src/EFCore.Relational/Migrations/IHistoryRepository.cs @@ -8,6 +8,8 @@ using JetBrains.Annotations; using Microsoft.Extensions.DependencyInjection; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Migrations { /// diff --git a/src/EFCore.Relational/Migrations/IMigrationCommandExecutor.cs b/src/EFCore.Relational/Migrations/IMigrationCommandExecutor.cs index 9a9ee0bf88d..709a029f259 100644 --- a/src/EFCore.Relational/Migrations/IMigrationCommandExecutor.cs +++ b/src/EFCore.Relational/Migrations/IMigrationCommandExecutor.cs @@ -9,6 +9,8 @@ using Microsoft.EntityFrameworkCore.Storage; using Microsoft.Extensions.DependencyInjection; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Migrations { /// diff --git a/src/EFCore.Relational/Migrations/IMigrationsAnnotationProvider.cs b/src/EFCore.Relational/Migrations/IMigrationsAnnotationProvider.cs index 549617c3d75..bb15727cf1d 100644 --- a/src/EFCore.Relational/Migrations/IMigrationsAnnotationProvider.cs +++ b/src/EFCore.Relational/Migrations/IMigrationsAnnotationProvider.cs @@ -7,6 +7,8 @@ using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.Extensions.DependencyInjection; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Migrations { /// diff --git a/src/EFCore.Relational/Migrations/IMigrationsAssembly.cs b/src/EFCore.Relational/Migrations/IMigrationsAssembly.cs index 2f6de9586a2..333a33fe9bb 100644 --- a/src/EFCore.Relational/Migrations/IMigrationsAssembly.cs +++ b/src/EFCore.Relational/Migrations/IMigrationsAssembly.cs @@ -8,6 +8,8 @@ using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.Extensions.DependencyInjection; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Migrations { /// @@ -32,7 +34,7 @@ public interface IMigrationsAssembly /// /// The snapshot of the contained in the assembly. /// - ModelSnapshot ModelSnapshot { get; } + ModelSnapshot? ModelSnapshot { get; } /// /// The assembly that contains the migrations, snapshot, etc. @@ -45,7 +47,7 @@ public interface IMigrationsAssembly /// /// The name or identifier to lookup. /// The identifier of the migration, or if none was found. - string FindMigrationId([NotNull] string nameOrId); + string? FindMigrationId([NotNull] string nameOrId); /// /// Creates an instance of the migration class. diff --git a/src/EFCore.Relational/Migrations/IMigrationsIdGenerator.cs b/src/EFCore.Relational/Migrations/IMigrationsIdGenerator.cs index d697c022791..aa40672b272 100644 --- a/src/EFCore.Relational/Migrations/IMigrationsIdGenerator.cs +++ b/src/EFCore.Relational/Migrations/IMigrationsIdGenerator.cs @@ -4,6 +4,8 @@ using JetBrains.Annotations; using Microsoft.Extensions.DependencyInjection; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Migrations { /// diff --git a/src/EFCore.Relational/Migrations/IMigrationsModelDiffer.cs b/src/EFCore.Relational/Migrations/IMigrationsModelDiffer.cs index 222aa08260c..9306216c433 100644 --- a/src/EFCore.Relational/Migrations/IMigrationsModelDiffer.cs +++ b/src/EFCore.Relational/Migrations/IMigrationsModelDiffer.cs @@ -7,6 +7,8 @@ using Microsoft.EntityFrameworkCore.Migrations.Operations; using Microsoft.Extensions.DependencyInjection; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Migrations { /// @@ -32,7 +34,7 @@ public interface IMigrationsModelDiffer /// /// if there are any differences and otherwise. /// - bool HasDifferences([CanBeNull] IRelationalModel source, [CanBeNull] IRelationalModel target); + bool HasDifferences([CanBeNull] IRelationalModel? source, [CanBeNull] IRelationalModel? target); /// /// Finds the differences between two models. @@ -43,6 +45,6 @@ public interface IMigrationsModelDiffer /// A list of the operations that need to applied to the database to migrate it /// from mapping to the source model so that is now mapping to the target model. /// - IReadOnlyList GetDifferences([CanBeNull] IRelationalModel source, [CanBeNull] IRelationalModel target); + IReadOnlyList GetDifferences([CanBeNull] IRelationalModel? source, [CanBeNull] IRelationalModel? target); } } diff --git a/src/EFCore.Relational/Migrations/IMigrationsSqlGenerator.cs b/src/EFCore.Relational/Migrations/IMigrationsSqlGenerator.cs index 56378cec781..2b8fa3a2ff8 100644 --- a/src/EFCore.Relational/Migrations/IMigrationsSqlGenerator.cs +++ b/src/EFCore.Relational/Migrations/IMigrationsSqlGenerator.cs @@ -7,6 +7,8 @@ using Microsoft.EntityFrameworkCore.Migrations.Operations; using Microsoft.Extensions.DependencyInjection; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Migrations { /// @@ -32,7 +34,7 @@ public interface IMigrationsSqlGenerator /// The list of commands to be executed or scripted. IReadOnlyList Generate( [NotNull] IReadOnlyList operations, - [CanBeNull] IModel model = null, + [CanBeNull] IModel? model = null, MigrationsSqlGenerationOptions options = MigrationsSqlGenerationOptions.Default); } } diff --git a/src/EFCore.Relational/Migrations/IMigrator.cs b/src/EFCore.Relational/Migrations/IMigrator.cs index 00d248d338b..f58e47e0f3a 100644 --- a/src/EFCore.Relational/Migrations/IMigrator.cs +++ b/src/EFCore.Relational/Migrations/IMigrator.cs @@ -7,6 +7,8 @@ using JetBrains.Annotations; using Microsoft.Extensions.DependencyInjection; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Migrations { /// @@ -30,7 +32,7 @@ public interface IMigrator /// /// The target migration to migrate the database to, or to migrate to the latest. /// - void Migrate([CanBeNull] string targetMigration = null); + void Migrate([CanBeNull] string? targetMigration = null); /// /// Migrates the database to either a specified target migration or up to the latest @@ -43,7 +45,7 @@ public interface IMigrator /// A task that represents the asynchronous operation /// If the is canceled. Task MigrateAsync( - [CanBeNull] string targetMigration = null, + [CanBeNull] string? targetMigration = null, CancellationToken cancellationToken = default); /// @@ -61,8 +63,8 @@ Task MigrateAsync( /// /// The generated script. string GenerateScript( - [CanBeNull] string fromMigration = null, - [CanBeNull] string toMigration = null, + [CanBeNull] string? fromMigration = null, + [CanBeNull] string? toMigration = null, MigrationsSqlGenerationOptions options = MigrationsSqlGenerationOptions.Default); } } diff --git a/src/EFCore.Relational/Migrations/Internal/MigrationCommandExecutor.cs b/src/EFCore.Relational/Migrations/Internal/MigrationCommandExecutor.cs index bf98b0e7ef5..fe7a3b44a5d 100644 --- a/src/EFCore.Relational/Migrations/Internal/MigrationCommandExecutor.cs +++ b/src/EFCore.Relational/Migrations/Internal/MigrationCommandExecutor.cs @@ -9,6 +9,8 @@ using Microsoft.EntityFrameworkCore.Utilities; using Microsoft.Extensions.DependencyInjection; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Migrations.Internal { /// @@ -45,7 +47,7 @@ public virtual void ExecuteNonQuery( try { - IDbContextTransaction transaction = null; + IDbContextTransaction? transaction = null; try { @@ -103,7 +105,7 @@ public virtual async Task ExecuteNonQueryAsync( try { - IDbContextTransaction transaction = null; + IDbContextTransaction? transaction = null; try { diff --git a/src/EFCore.Relational/Migrations/Internal/MigrationExtensions.cs b/src/EFCore.Relational/Migrations/Internal/MigrationExtensions.cs index 445f55fe806..5ce0a28808e 100644 --- a/src/EFCore.Relational/Migrations/Internal/MigrationExtensions.cs +++ b/src/EFCore.Relational/Migrations/Internal/MigrationExtensions.cs @@ -4,6 +4,8 @@ using System.Reflection; using JetBrains.Annotations; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Migrations.Internal { /// @@ -21,6 +23,6 @@ public static class MigrationExtensions /// doing so can result in application failures when updating to a new Entity Framework Core release. /// public static string GetId([NotNull] this Migration migration) - => migration.GetType().GetCustomAttribute()?.Id; + => migration.GetType().GetCustomAttribute()!.Id; } } diff --git a/src/EFCore.Relational/Migrations/Internal/MigrationsAssembly.cs b/src/EFCore.Relational/Migrations/Internal/MigrationsAssembly.cs index 95a85f2e4ee..93698fe0aaa 100644 --- a/src/EFCore.Relational/Migrations/Internal/MigrationsAssembly.cs +++ b/src/EFCore.Relational/Migrations/Internal/MigrationsAssembly.cs @@ -11,6 +11,8 @@ using Microsoft.EntityFrameworkCore.Utilities; using Microsoft.Extensions.DependencyInjection; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Migrations.Internal { /// @@ -31,8 +33,8 @@ public class MigrationsAssembly : IMigrationsAssembly { private readonly IMigrationsIdGenerator _idGenerator; private readonly IDiagnosticsLogger _logger; - private IReadOnlyDictionary _migrations; - private ModelSnapshot _modelSnapshot; + private IReadOnlyDictionary? _migrations; + private ModelSnapshot? _modelSnapshot; private readonly Type _contextType; /// @@ -110,12 +112,12 @@ orderby id /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public virtual ModelSnapshot ModelSnapshot + public virtual ModelSnapshot? ModelSnapshot => _modelSnapshot ??= (from t in Assembly.GetConstructibleTypes() where t.IsSubclassOf(typeof(ModelSnapshot)) && t.GetCustomAttribute()?.ContextType == _contextType - select (ModelSnapshot)Activator.CreateInstance(t.AsType())) + select (ModelSnapshot)Activator.CreateInstance(t.AsType())!) .FirstOrDefault(); /// @@ -132,7 +134,7 @@ where t.IsSubclassOf(typeof(ModelSnapshot)) /// any release. You should only use it directly in your code 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 FindMigrationId(string nameOrId) + public virtual string? FindMigrationId(string nameOrId) => Migrations.Keys .Where( _idGenerator.IsValidId(nameOrId) @@ -151,7 +153,7 @@ public virtual Migration CreateMigration(TypeInfo migrationClass, string activeP { Check.NotNull(activeProvider, nameof(activeProvider)); - var migration = (Migration)Activator.CreateInstance(migrationClass.AsType()); + var migration = (Migration)Activator.CreateInstance(migrationClass.AsType())!; migration.ActiveProvider = activeProvider; return migration; diff --git a/src/EFCore.Relational/Migrations/Internal/MigrationsIdGenerator.cs b/src/EFCore.Relational/Migrations/Internal/MigrationsIdGenerator.cs index a0db9e89755..5430454fb5b 100644 --- a/src/EFCore.Relational/Migrations/Internal/MigrationsIdGenerator.cs +++ b/src/EFCore.Relational/Migrations/Internal/MigrationsIdGenerator.cs @@ -6,6 +6,8 @@ using System.Text.RegularExpressions; using Microsoft.Extensions.DependencyInjection; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Migrations.Internal { /// diff --git a/src/EFCore.Relational/Migrations/Internal/MigrationsModelDiffer.cs b/src/EFCore.Relational/Migrations/Internal/MigrationsModelDiffer.cs index e5a6759fc8e..f210a20dee4 100644 --- a/src/EFCore.Relational/Migrations/Internal/MigrationsModelDiffer.cs +++ b/src/EFCore.Relational/Migrations/Internal/MigrationsModelDiffer.cs @@ -20,6 +20,9 @@ using Microsoft.EntityFrameworkCore.Update.Internal; using Microsoft.EntityFrameworkCore.Utilities; using Microsoft.Extensions.DependencyInjection; +using DisallowNullAttribute = System.Diagnostics.CodeAnalysis.DisallowNullAttribute; + +#nullable enable namespace Microsoft.EntityFrameworkCore.Migrations.Internal { @@ -65,8 +68,8 @@ public class MigrationsModelDiffer : IMigrationsModelDiffer typeof(AddForeignKeyOperation), typeof(CreateIndexOperation), typeof(AddCheckConstraintOperation) }; - private IUpdateAdapter _sourceUpdateAdapter; - private IUpdateAdapter _targetUpdateAdapter; + private IUpdateAdapter? _sourceUpdateAdapter; + private IUpdateAdapter? _targetUpdateAdapter; private readonly Dictionary _sourceSharedIdentityEntryMaps = new(); @@ -149,7 +152,7 @@ public MigrationsModelDiffer( /// any release. You should only use it directly in your code 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 HasDifferences(IRelationalModel source, IRelationalModel target) + public virtual bool HasDifferences(IRelationalModel? source, IRelationalModel? target) => Diff(source, target, new DiffContext()).Any(); /// @@ -158,7 +161,7 @@ public virtual bool HasDifferences(IRelationalModel source, IRelationalModel tar /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public virtual IReadOnlyList GetDifferences(IRelationalModel source, IRelationalModel target) + public virtual IReadOnlyList GetDifferences(IRelationalModel? source, IRelationalModel? target) { var diffContext = new DiffContext(); return Sort(Diff(source, target, diffContext), diffContext); @@ -327,7 +330,7 @@ protected virtual IReadOnlyList Sort( dropTableGraph.AddVertices(dropTableOperations); foreach (var dropTableOperation in dropTableOperations) { - var table = diffContext.FindTable(dropTableOperation); + var table = diffContext.FindTable(dropTableOperation)!; foreach (var foreignKey in table.ForeignKeyConstraints) { var principalDropTableOperation = diffContext.FindDrop(foreignKey.PrincipalTable); @@ -379,8 +382,8 @@ protected virtual IReadOnlyList Sort( /// doing so can result in application failures when updating to a new Entity Framework Core release. /// protected virtual IEnumerable Diff( - [CanBeNull] IRelationalModel source, - [CanBeNull] IRelationalModel target, + [CanBeNull] IRelationalModel? source, + [CanBeNull] IRelationalModel? target, [NotNull] DiffContext diffContext) { var operations = Enumerable.Empty(); @@ -394,7 +397,8 @@ protected virtual IEnumerable Diff( { var alterDatabaseOperation = new AlterDatabaseOperation { - Collation = target.Collation, OldDatabase = { Collation = source.Collation } + Collation = target.Collation, + OldDatabase = { Collation = source.Collation } }; alterDatabaseOperation.AddAnnotations(targetMigrationsAnnotations); @@ -426,8 +430,8 @@ protected virtual IEnumerable Diff( } private IEnumerable DiffAnnotations( - IRelationalModel source, - IRelationalModel target) + IRelationalModel? source, + IRelationalModel? target) { var targetMigrationsAnnotations = target?.GetAnnotations().ToList(); @@ -456,11 +460,11 @@ private IEnumerable DiffAnnotations( yield break; } - var sourceMigrationsAnnotations = source?.GetAnnotations().ToList(); - if (HasDifferences(sourceMigrationsAnnotations, targetMigrationsAnnotations)) + var sourceMigrationsAnnotations = source.GetAnnotations().ToList(); + if (HasDifferences(sourceMigrationsAnnotations, targetMigrationsAnnotations!)) { var alterDatabaseOperation = new AlterDatabaseOperation(); - alterDatabaseOperation.AddAnnotations(targetMigrationsAnnotations); + alterDatabaseOperation.AddAnnotations(targetMigrationsAnnotations!); alterDatabaseOperation.OldDatabase.AddAnnotations(sourceMigrationsAnnotations); yield return alterDatabaseOperation; } @@ -598,7 +602,7 @@ protected virtual IEnumerable Diff( && target.IsExcludedFromMigrations) { // Populate column mapping - foreach(var _ in Diff(source.Columns, target.Columns, diffContext)) + foreach (var _ in Diff(source.Columns, target.Columns, diffContext)) { } yield break; @@ -724,7 +728,7 @@ private static IEnumerable GetSortedColumns(ITable table) var sortedColumns = new List(columns.Count); foreach (var property in GetSortedProperties(GetMainType(table).GetRootType(), table)) { - var column = table.FindColumn(property); + var column = table.FindColumn(property)!; if (columns.Remove(column)) { sortedColumns.Add(column); @@ -765,7 +769,7 @@ private static IEnumerable GetSortedProperties(IEntityType entityType continue; } - clrProperty = foreignKey.DependentToPrincipal.PropertyInfo; + clrProperty = foreignKey.DependentToPrincipal!.PropertyInfo!; var groupIndex = foreignKey.Properties.IndexOf(property); unorderedGroups.GetOrAddNew(clrProperty).Add(groupIndex, property); @@ -781,7 +785,7 @@ private static IEnumerable GetSortedProperties(IEntityType entityType clrProperty, new List { property }); } - var clrType = clrProperty.DeclaringType; + var clrType = clrProperty.DeclaringType!; var index = clrType.GetTypeInfo().DeclaredProperties .IndexOf(clrProperty, PropertyInfoEqualityComparer.Instance); @@ -809,7 +813,7 @@ private static IEnumerable GetSortedProperties(IEntityType entityType groups.Add(linkingNavigationProperty, properties); - var clrType = linkingNavigationProperty.DeclaringType; + var clrType = linkingNavigationProperty.DeclaringType!; var index = clrType.GetTypeInfo().DeclaredProperties .IndexOf(linkingNavigationProperty, PropertyInfoEqualityComparer.Instance); @@ -818,7 +822,7 @@ private static IEnumerable GetSortedProperties(IEntityType entityType } } - var graph = new Multigraph(); + var graph = new Multigraph(); graph.AddVertices(types.Keys); foreach (var left in types.Keys) @@ -848,7 +852,7 @@ private static IEnumerable GetSortedProperties(IEntityType entityType return sortedPropertyInfos .Select(pi => primaryKeyPropertyGroups.ContainsKey(pi) ? primaryKeyPropertyGroups[pi] : null) - .Where(e => e != null) + .Where(e => e != null).Cast() .Concat(leastPriorityPrimaryKeyProperties) .Concat( sortedPropertyInfos @@ -870,10 +874,10 @@ private PropertyInfoEqualityComparer() public static readonly PropertyInfoEqualityComparer Instance = new(); - public bool Equals(PropertyInfo x, PropertyInfo y) + public bool Equals(PropertyInfo? x, PropertyInfo? y) => x.IsSameAs(y); - public int GetHashCode(PropertyInfo obj) + public int GetHashCode([DisallowNull] PropertyInfo obj) => throw new NotSupportedException(); } @@ -1490,7 +1494,7 @@ protected virtual IEnumerable Remove([NotNull] ICheckConstra { Name = source.Name, Schema = sourceEntityType.GetSchema(), - Table = sourceEntityType.GetTableName() + Table = sourceEntityType.GetTableName()! }; operation.AddAnnotations(MigrationsAnnotations.ForRemove(source)); @@ -1633,8 +1637,8 @@ private static SequenceOperation Initialize( /// doing so can result in application failures when updating to a new Entity Framework Core release. /// protected virtual void TrackData( - [CanBeNull] IRelationalModel source, - [CanBeNull] IRelationalModel target, + [CanBeNull] IRelationalModel? source, + [CanBeNull] IRelationalModel? target, [NotNull] DiffContext diffContext) { if (target == null) @@ -1653,7 +1657,7 @@ protected virtual void TrackData( var targetEntry = _targetUpdateAdapter.CreateEntry(targetSeed, targetEntityType); if (targetEntry.ToEntityEntry().Entity is Dictionary targetBag) { - targetBag.Remove((key, _, target) => !target.ContainsKey(key), targetSeed); + targetBag.Remove((key, _, target) => !target!.ContainsKey(key), targetSeed); } targetEntry.EntityState = EntityState.Added; @@ -1686,9 +1690,9 @@ protected virtual void TrackData( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - protected virtual Dictionary> DiffData( - [CanBeNull] IRelationalModel source, - [CanBeNull] IRelationalModel target, + protected virtual Dictionary>? DiffData( + [CanBeNull] IRelationalModel? source, + [CanBeNull] IRelationalModel? target, [NotNull] DiffContext diffContext) { Check.NotNull(diffContext, nameof(diffContext)); @@ -1700,7 +1704,7 @@ protected virtual Dictionary> DiffData( } var keyMapping = new Dictionary>>(); + Dictionary<(IKey, ITable), List<(IProperty Property, ValueConverter? SourceConverter, ValueConverter? TargetConverter)>>>(); foreach (var sourceEntityType in source.Model.GetEntityTypes()) { foreach (var sourceTableMapping in sourceEntityType.GetTableMappings()) @@ -1714,7 +1718,7 @@ protected virtual Dictionary> DiffData( foreach (var targetKey in targetTable.PrimaryKey.MappedKeys) { - var keyPropertiesMap = new List<(IProperty, ValueConverter, ValueConverter)>(); + var keyPropertiesMap = new List<(IProperty, ValueConverter?, ValueConverter?)>(); foreach (var keyProperty in targetKey.Properties) { var targetColumn = targetTable.FindColumn(keyProperty); @@ -1762,7 +1766,7 @@ protected virtual Dictionary> DiffData( continue; } - ITable firstSourceTable = null; + ITable? firstSourceTable = null; foreach (var targetTableMapping in targetEntityType.GetTableMappings()) { var targetTable = targetTableMapping.Table; @@ -1806,10 +1810,10 @@ protected virtual Dictionary> DiffData( foreach (var sourceEntityType in source.Model.GetEntityTypes()) { - ITable firstSourceTable = null; + ITable? firstSourceTable = null; if (keyMapping.TryGetValue(sourceEntityType, out var targetKeyMap)) { - ITable firstTargetTable = null; + ITable? firstTargetTable = null; foreach (var sourceTableMapping in sourceEntityType.GetTableMappings()) { var sourceTable = sourceTableMapping.Table; @@ -1870,11 +1874,11 @@ protected virtual Dictionary> DiffData( foreach (var sourceSeed in sourceEntityType.GetSeedData()) { - var sourceEntry = GetEntry(sourceSeed, sourceEntityType, _sourceUpdateAdapter); + var sourceEntry = GetEntry(sourceSeed, sourceEntityType, _sourceUpdateAdapter!); if (!_sourceSharedIdentityEntryMaps.TryGetValue(principalSourceTable, out var sourceTableEntryMappingMap)) { - sourceTableEntryMappingMap = new SharedIdentityMap(_sourceUpdateAdapter); + sourceTableEntryMappingMap = new SharedIdentityMap(_sourceUpdateAdapter!); _sourceSharedIdentityEntryMaps.Add(principalSourceTable, sourceTableEntryMappingMap); } @@ -1891,7 +1895,7 @@ protected virtual Dictionary> DiffData( var (targetKey, targetTable) = targetKeyTuple.Key; var keyPropertiesMap = targetKeyTuple.Value; - var targetKeyValues = new object[keyPropertiesMap.Count]; + var targetKeyValues = new object?[keyPropertiesMap.Count]; for (var i = 0; i < keyPropertiesMap.Count; i++) { var (sourceProperty, sourceConverter, targetConverter) = keyPropertiesMap[i]; @@ -1899,11 +1903,11 @@ protected virtual Dictionary> DiffData( targetKeyValues[i] = targetKey.Properties[i].ClrType != sourceProperty.ClrType ? sourceConverter != null ? sourceConverter.ConvertToProvider(sourceValue) - : targetConverter.ConvertFromProvider(sourceValue) + : targetConverter!.ConvertFromProvider(sourceValue) : sourceValue; } - var entry = _targetUpdateAdapter.TryGetEntry(targetKey, targetKeyValues); + var entry = _targetUpdateAdapter!.TryGetEntry(targetKey, targetKeyValues); if (entry == null) { continue; @@ -2037,18 +2041,18 @@ var modelValuesChanged } private static IUpdateEntry GetEntry( - IDictionary sourceSeed, + IDictionary sourceSeed, IEntityType sourceEntityType, IUpdateAdapter updateAdapter) { - var key = sourceEntityType.FindPrimaryKey(); - var keyValues = new object[key.Properties.Count]; + var key = sourceEntityType.FindPrimaryKey()!; + var keyValues = new object?[key.Properties.Count]; for (var i = 0; i < keyValues.Length; i++) { keyValues[i] = sourceSeed[key.Properties[i].Name]; } - return updateAdapter.TryGetEntry(key, keyValues); + return updateAdapter.TryGetEntry(key, keyValues)!; } /// @@ -2058,8 +2062,8 @@ private static IUpdateEntry GetEntry( /// doing so can result in application failures when updating to a new Entity Framework Core release. /// protected virtual IEnumerable GetDataOperations( - [NotNull] IRelationalModel source, - [NotNull] IRelationalModel target, + [CanBeNull] IRelationalModel? source, + [CanBeNull] IRelationalModel? target, [NotNull] DiffContext diffContext) { TrackData(source, target, diffContext); @@ -2076,7 +2080,7 @@ protected virtual IEnumerable GetDataOperations( foreach (var sourceEntry in entryMapping.SourceEntries) { sourceEntry.EntityState = EntityState.Deleted; - _sourceUpdateAdapter.CascadeDelete( + _sourceUpdateAdapter!.CascadeDelete( sourceEntry, sourceEntry.EntityType.GetReferencingForeignKeys() .Where( @@ -2107,7 +2111,7 @@ protected virtual IEnumerable GetDataOperations( sourceEntry.EntityState = EntityState.Deleted; } } - else if (entryMapping.SourceEntries.Any(en => changedTableMappings.ContainsKey(en.EntityType))) + else if (entryMapping.SourceEntries.Any(en => changedTableMappings!.ContainsKey(en.EntityType))) { foreach (var sourceEntry in entryMapping.SourceEntries) { @@ -2131,7 +2135,7 @@ protected virtual IEnumerable GetDataOperations( private IEnumerable GetDataOperations( bool forSource, - Dictionary> changedTableMappings, + Dictionary>? changedTableMappings, HashSet entriesWithRemovedMappings, DiffContext diffContext) { @@ -2155,10 +2159,10 @@ private IEnumerable GetDataOperations( foreach (var commandBatch in commandBatches) { - InsertDataOperation batchInsertOperation = null; + InsertDataOperation? batchInsertOperation = null; foreach (var command in commandBatch.ModificationCommands) { - var table = model.FindTable(command.TableName, command.Schema); + var table = model.FindTable(command.TableName, command.Schema)!; if (diffContext.FindDrop(table) != null || table.IsExcludedFromMigrations) { @@ -2217,7 +2221,7 @@ private IEnumerable GetDataOperations( } if (command.Entries.Any( - en => changedTableMappings.TryGetValue(en.EntityType, out var newTables) + en => changedTableMappings!.TryGetValue(en.EntityType, out var newTables) && newTables.Any(t => t.Name == command.TableName && t.Schema == command.Schema))) { // If the entity type uses TPT add the rows to the new tables to which the entity has been mapped @@ -2250,14 +2254,14 @@ private IEnumerable GetDataOperations( // If the entity type used TPT delete the rows in the tables to which the entity is no longer mapped if (command.Entries.Any(en => entriesWithRemovedMappings.Contains(en)) && !command.Entries.Any( - en => changedTableMappings.TryGetValue(en.EntityType, out var removedTables) + en => changedTableMappings!.TryGetValue(en.EntityType, out var removedTables) && removedTables.Any(t => t.Name == command.TableName && t.Schema == command.Schema))) { break; } var keyColumns = command.ColumnModifications.Where(col => col.IsKey) - .Select(c => table.FindColumn(c.ColumnName)); + .Select(c => table.FindColumn(c.ColumnName)!); var anyKeyColumnDropped = keyColumns.Any(c => diffContext.FindDrop(c) != null); yield return new DeleteDataOperation @@ -2286,9 +2290,9 @@ private IEnumerable GetDataOperations( } } - private object GetValue(ColumnModification columnModification) + private object? GetValue(ColumnModification columnModification) { - var converter = GetValueConverter(columnModification.Property); + var converter = GetValueConverter(columnModification.Property!); var value = columnModification.UseCurrentValueParameter ? columnModification.Value : columnModification.OriginalValue; @@ -2313,6 +2317,7 @@ protected virtual IEnumerable DiffCollection( [NotNull] Func> add, [NotNull] Func> remove, [NotNull] params Func[] predicates) + where T : notnull { var sourceList = sources.ToList(); var targetList = targets.ToList(); @@ -2402,6 +2407,7 @@ protected virtual IEnumerable GetSchemas([NotNull] IRelationalModel mode .Concat(model.Views.Where(t => t.ViewDefinitionSql != null).Select(s => s.Schema)) .Concat(model.Sequences.Select(s => s.Schema)) .Where(s => !string.IsNullOrEmpty(s)) + .Cast() .Distinct(); /// @@ -2414,14 +2420,14 @@ protected virtual object GetDefaultValue([NotNull] Type type) => type == typeof(string) ? string.Empty : type.IsArray - ? Array.CreateInstance(type.GetElementType(), 0) + ? Array.CreateInstance(type.GetElementType()!, 0) : type.UnwrapNullableType().GetDefaultValue(); - private ValueConverter GetValueConverter(IProperty property, RelationalTypeMapping typeMapping = null) + private ValueConverter? GetValueConverter(IProperty property, RelationalTypeMapping? typeMapping = null) => property.GetValueConverter() ?? (property.FindRelationalTypeMapping() ?? typeMapping)?.Converter; private static IEntityType GetMainType(ITable table) - => table.EntityTypeMappings.FirstOrDefault(t => t.IsSharedTablePrincipal).EntityType; + => table.EntityTypeMappings.First(t => t.IsSharedTablePrincipal).EntityType; /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -2448,9 +2454,9 @@ public static IProperty[] GetMappedProperties([NotNull] ITable table, [NotNull] return properties; } - private static object[,] ToMultidimensionalArray(IReadOnlyList values) + private static object?[,] ToMultidimensionalArray(IReadOnlyList values) { - var result = new object[1, values.Count]; + var result = new object?[1, values.Count]; for (var i = 0; i < values.Count; i++) { result[0, i] = values[i]; @@ -2459,14 +2465,14 @@ public static IProperty[] GetMappedProperties([NotNull] ITable table, [NotNull] return result; } - private static object[,] AddToMultidimensionalArray(IReadOnlyList values, object[,] array) + private static object?[,] AddToMultidimensionalArray(IReadOnlyList values, object?[,] array) { var width = array.GetLength(0); var height = array.GetLength(1); Check.DebugAssert(height == values.Count, $"height of {height} != values.Count of {values.Count}"); - var result = new object[width + 1, height]; + var result = new object?[width + 1, height]; for (var i = 0; i < width; i++) { Array.Copy(array, i * height, result, i * height, height); @@ -2581,6 +2587,7 @@ private readonly IDictionary _removedTables /// doing so can result in application failures when updating to a new Entity Framework Core release. /// public virtual void AddMapping([NotNull] T source, [NotNull] T target) + where T : notnull { _targetToSource.Add(target, source); _sourceToTarget.Add(source, target); @@ -2633,7 +2640,7 @@ public virtual ITable GetTable(IEntityType 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 virtual T FindSource([CanBeNull] T target) + public virtual T? FindSource([CanBeNull] T? target) where T : class => target == null ? null @@ -2647,7 +2654,7 @@ public virtual T FindSource([CanBeNull] T target) /// any release. You should only use it directly in your code 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 FindTarget([CanBeNull] T source) + public virtual T? FindTarget([CanBeNull] T? source) where T : class => source == null ? null @@ -2661,7 +2668,7 @@ public virtual T FindTarget([CanBeNull] T source) /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public virtual CreateTableOperation FindCreate([NotNull] ITable target) + public virtual CreateTableOperation? FindCreate([NotNull] ITable target) => _createTableOperations.TryGetValue(target, out var operation) ? operation : null; @@ -2672,7 +2679,7 @@ public virtual CreateTableOperation FindCreate([NotNull] ITable target) /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public virtual DropTableOperation FindDrop([NotNull] ITable source) + public virtual DropTableOperation? FindDrop([NotNull] ITable source) => _dropTableOperations.TryGetValue(source, out var operation) ? operation : null; @@ -2683,7 +2690,7 @@ public virtual DropTableOperation FindDrop([NotNull] ITable source) /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public virtual DropColumnOperation FindDrop([NotNull] IColumn source) + public virtual DropColumnOperation? FindDrop([NotNull] IColumn source) => _dropColumnOperations.TryGetValue(source, out var operation) ? operation : null; @@ -2694,7 +2701,7 @@ public virtual DropColumnOperation FindDrop([NotNull] IColumn source) /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public virtual ITable FindTable([NotNull] DropTableOperation operation) + public virtual ITable? FindTable([NotNull] DropTableOperation operation) => _removedTables.TryGetValue(operation, out var source) ? source : null; diff --git a/src/EFCore.Relational/Migrations/Internal/Migrator.cs b/src/EFCore.Relational/Migrations/Internal/Migrator.cs index 5ac8170e1fc..1b51501cd54 100644 --- a/src/EFCore.Relational/Migrations/Internal/Migrator.cs +++ b/src/EFCore.Relational/Migrations/Internal/Migrator.cs @@ -15,6 +15,8 @@ using Microsoft.EntityFrameworkCore.Utilities; using Microsoft.Extensions.DependencyInjection; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Migrations.Internal { /// @@ -103,7 +105,7 @@ public Migrator( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public virtual void Migrate(string targetMigration = null) + public virtual void Migrate(string? targetMigration = null) { _logger.MigrateUsingConnection(this, _connection); @@ -140,7 +142,7 @@ public virtual void Migrate(string targetMigration = null) /// doing so can result in application failures when updating to a new Entity Framework Core release. /// public virtual async Task MigrateAsync( - string targetMigration = null, + string? targetMigration = null, CancellationToken cancellationToken = default) { _logger.MigrateUsingConnection(this, _connection); @@ -179,7 +181,7 @@ await _migrationCommandExecutor.ExecuteNonQueryAsync(commandList(), _connection, private IEnumerable>> GetMigrationCommandLists( IReadOnlyList appliedMigrationEntries, - string targetMigration = null) + string? targetMigration = null) { PopulateMigrations( appliedMigrationEntries.Select(t => t.MigrationId), @@ -229,10 +231,10 @@ private IEnumerable>> GetMigrationCommandLi /// protected virtual void PopulateMigrations( [NotNull] IEnumerable appliedMigrationEntries, - [NotNull] string targetMigration, + [CanBeNull] string? targetMigration, [NotNull] out IReadOnlyList migrationsToApply, [NotNull] out IReadOnlyList migrationsToRevert, - [NotNull] out Migration actualTargetMigration) + [CanBeNull] out Migration? actualTargetMigration) { var appliedMigrations = new Dictionary(); var unappliedMigrations = new Dictionary(); @@ -299,8 +301,8 @@ protected virtual void PopulateMigrations( /// doing so can result in application failures when updating to a new Entity Framework Core release. /// public virtual string GenerateScript( - string fromMigration = null, - string toMigration = null, + string? fromMigration = null, + string? toMigration = null, MigrationsSqlGenerationOptions options = MigrationsSqlGenerationOptions.Default) { options |= MigrationsSqlGenerationOptions.Script; @@ -482,7 +484,7 @@ protected virtual IReadOnlyList GenerateUpSql( /// protected virtual IReadOnlyList GenerateDownSql( [NotNull] Migration migration, - [CanBeNull] Migration previousMigration, + [CanBeNull] Migration? previousMigration, MigrationsSqlGenerationOptions options = MigrationsSqlGenerationOptions.Default) { Check.NotNull(migration, nameof(migration)); diff --git a/src/EFCore.Relational/Migrations/Migration.cs b/src/EFCore.Relational/Migrations/Migration.cs index 24dfd72a767..d3f72c8b540 100644 --- a/src/EFCore.Relational/Migrations/Migration.cs +++ b/src/EFCore.Relational/Migrations/Migration.cs @@ -7,6 +7,9 @@ using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Migrations.Operations; +using DisallowNullAttribute = System.Diagnostics.CodeAnalysis.DisallowNullAttribute; + +#nullable enable namespace Microsoft.EntityFrameworkCore.Migrations { @@ -20,9 +23,9 @@ public abstract class Migration /// public const string InitialDatabase = "0"; - private IModel _targetModel; - private List _upOperations; - private List _downOperations; + private IModel? _targetModel; + private List? _upOperations; + private List? _downOperations; /// /// The that the database will map to after the migration has been applied. @@ -78,7 +81,8 @@ public virtual IReadOnlyList DownOperations /// can be made to the database depending on the type of database being used. /// /// - public virtual string ActiveProvider { get; [param: NotNull] set; } + [DisallowNull] + public virtual string? ActiveProvider { get; [param: NotNull] set; } /// /// Implemented to build the . diff --git a/src/EFCore.Relational/Migrations/MigrationAttribute.cs b/src/EFCore.Relational/Migrations/MigrationAttribute.cs index 768de253086..daa49369656 100644 --- a/src/EFCore.Relational/Migrations/MigrationAttribute.cs +++ b/src/EFCore.Relational/Migrations/MigrationAttribute.cs @@ -5,6 +5,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Migrations { /// diff --git a/src/EFCore.Relational/Migrations/MigrationBuilder.cs b/src/EFCore.Relational/Migrations/MigrationBuilder.cs index b19bd38f35d..6031ea8746c 100644 --- a/src/EFCore.Relational/Migrations/MigrationBuilder.cs +++ b/src/EFCore.Relational/Migrations/MigrationBuilder.cs @@ -11,6 +11,8 @@ using Microsoft.EntityFrameworkCore.Migrations.Operations.Builders; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Migrations { /// @@ -22,7 +24,7 @@ public class MigrationBuilder /// Creates a new instance of the builder. /// /// The name of the database provider being used. - public MigrationBuilder([CanBeNull] string activeProvider) + public MigrationBuilder([CanBeNull] string? activeProvider) { ActiveProvider = activeProvider; } @@ -30,7 +32,7 @@ public MigrationBuilder([CanBeNull] string activeProvider) /// /// The name of the database provider being used. /// - public virtual string ActiveProvider { get; } + public virtual string? ActiveProvider { get; } /// /// The list of s being built. @@ -73,18 +75,18 @@ public MigrationBuilder([CanBeNull] string activeProvider) public virtual OperationBuilder AddColumn( [NotNull] string name, [NotNull] string table, - [CanBeNull] string type = null, + [CanBeNull] string? type = null, bool? unicode = null, int? maxLength = null, bool rowVersion = false, - [CanBeNull] string schema = null, + [CanBeNull] string? schema = null, bool nullable = false, - [CanBeNull] object defaultValue = null, - [CanBeNull] string defaultValueSql = null, - [CanBeNull] string computedColumnSql = null, + [CanBeNull] object? defaultValue = null, + [CanBeNull] string? defaultValueSql = null, + [CanBeNull] string? computedColumnSql = null, bool? fixedLength = null, - [CanBeNull] string comment = null, - [CanBeNull] string collation = null, + [CanBeNull] string? comment = null, + [CanBeNull] string? collation = null, int? precision = null, int? scale = null, bool? stored = null) @@ -141,9 +143,9 @@ public virtual OperationBuilder AddForeignKey( [NotNull] string table, [NotNull] string column, [NotNull] string principalTable, - [CanBeNull] string schema = null, - [CanBeNull] string principalSchema = null, - [CanBeNull] string principalColumn = null, + [CanBeNull] string? schema = null, + [CanBeNull] string? principalSchema = null, + [CanBeNull] string? principalColumn = null, ReferentialAction onUpdate = ReferentialAction.NoAction, ReferentialAction onDelete = ReferentialAction.NoAction) => AddForeignKey( @@ -180,9 +182,9 @@ public virtual OperationBuilder AddForeignKey( [NotNull] string table, [NotNull] string[] columns, [NotNull] string principalTable, - [CanBeNull] string schema = null, - [CanBeNull] string principalSchema = null, - [CanBeNull] string[] principalColumns = null, + [CanBeNull] string? schema = null, + [CanBeNull] string? principalSchema = null, + [CanBeNull] string[]? principalColumns = null, ReferentialAction onUpdate = ReferentialAction.NoAction, ReferentialAction onDelete = ReferentialAction.NoAction) { @@ -220,7 +222,7 @@ public virtual OperationBuilder AddPrimaryKey( [NotNull] string name, [NotNull] string table, [NotNull] string column, - [CanBeNull] string schema = null) + [CanBeNull] string? schema = null) => AddPrimaryKey( name, table, @@ -239,7 +241,7 @@ public virtual OperationBuilder AddPrimaryKey( [NotNull] string name, [NotNull] string table, [NotNull] string[] columns, - [CanBeNull] string schema = null) + [CanBeNull] string? schema = null) { Check.NotEmpty(name, nameof(name)); Check.NotEmpty(table, nameof(table)); @@ -269,7 +271,7 @@ public virtual OperationBuilder AddUniqueConstrain [NotNull] string name, [NotNull] string table, [NotNull] string column, - [CanBeNull] string schema = null) + [CanBeNull] string? schema = null) => AddUniqueConstraint( name, table, @@ -288,7 +290,7 @@ public virtual OperationBuilder AddUniqueConstrain [NotNull] string name, [NotNull] string table, [NotNull] string[] columns, - [CanBeNull] string schema = null) + [CanBeNull] string? schema = null) { Check.NotEmpty(name, nameof(name)); Check.NotEmpty(table, nameof(table)); @@ -388,30 +390,30 @@ public virtual OperationBuilder AddUniqueConstrain public virtual AlterOperationBuilder AlterColumn( [NotNull] string name, [NotNull] string table, - [CanBeNull] string type = null, + [CanBeNull] string? type = null, bool? unicode = null, int? maxLength = null, bool rowVersion = false, - [CanBeNull] string schema = null, + [CanBeNull] string? schema = null, bool nullable = false, - [CanBeNull] object defaultValue = null, - [CanBeNull] string defaultValueSql = null, - [CanBeNull] string computedColumnSql = null, - [CanBeNull] Type oldClrType = null, - [CanBeNull] string oldType = null, + [CanBeNull] object? defaultValue = null, + [CanBeNull] string? defaultValueSql = null, + [CanBeNull] string? computedColumnSql = null, + [CanBeNull] Type? oldClrType = null, + [CanBeNull] string? oldType = null, bool? oldUnicode = null, int? oldMaxLength = null, bool oldRowVersion = false, bool oldNullable = false, - [CanBeNull] object oldDefaultValue = null, - [CanBeNull] string oldDefaultValueSql = null, - [CanBeNull] string oldComputedColumnSql = null, + [CanBeNull] object? oldDefaultValue = null, + [CanBeNull] string? oldDefaultValueSql = null, + [CanBeNull] string? oldComputedColumnSql = null, bool? fixedLength = null, bool? oldFixedLength = null, - [CanBeNull] string comment = null, - [CanBeNull] string oldComment = null, - [CanBeNull] string collation = null, - [CanBeNull] string oldCollation = null, + [CanBeNull] string? comment = null, + [CanBeNull] string? oldComment = null, + [CanBeNull] string? collation = null, + [CanBeNull] string? oldCollation = null, int? precision = null, int? oldPrecision = null, int? scale = null, @@ -474,8 +476,8 @@ public virtual AlterOperationBuilder AlterColumn( /// The previous collation to apply to the column. /// A builder to allow annotations to be added to the operation. public virtual AlterOperationBuilder AlterDatabase( - [CanBeNull] string collation = null, - [CanBeNull] string oldCollation = null) + [CanBeNull] string? collation = null, + [CanBeNull] string? oldCollation = null) { var operation = new AlterDatabaseOperation { @@ -506,7 +508,7 @@ public virtual AlterOperationBuilder AlterDatabase( /// A builder to allow annotations to be added to the operation. public virtual AlterOperationBuilder AlterSequence( [NotNull] string name, - [CanBeNull] string schema = null, + [CanBeNull] string? schema = null, int incrementBy = 1, long? minValue = null, long? maxValue = null, @@ -549,9 +551,9 @@ public virtual AlterOperationBuilder AlterSequence( /// A builder to allow annotations to be added to the operation. public virtual AlterOperationBuilder AlterTable( [NotNull] string name, - [CanBeNull] string schema = null, - [CanBeNull] string comment = null, - [CanBeNull] string oldComment = null) + [CanBeNull] string? schema = null, + [CanBeNull] string? comment = null, + [CanBeNull] string? oldComment = null) { Check.NotEmpty(name, nameof(name)); @@ -581,9 +583,9 @@ public virtual OperationBuilder CreateIndex( [NotNull] string name, [NotNull] string table, [NotNull] string column, - [CanBeNull] string schema = null, + [CanBeNull] string? schema = null, bool unique = false, - [CanBeNull] string filter = null) + [CanBeNull] string? filter = null) => CreateIndex( name, table, @@ -606,9 +608,9 @@ public virtual OperationBuilder CreateIndex( [NotNull] string name, [NotNull] string table, [NotNull] string[] columns, - [CanBeNull] string schema = null, + [CanBeNull] string? schema = null, bool unique = false, - [CanBeNull] string filter = null) + [CanBeNull] string? filter = null) { Check.NotEmpty(name, nameof(name)); Check.NotEmpty(table, nameof(table)); @@ -657,7 +659,7 @@ public virtual OperationBuilder EnsureSchema( /// A builder to allow annotations to be added to the operation. public virtual OperationBuilder CreateSequence( [NotNull] string name, - [CanBeNull] string schema = null, + [CanBeNull] string? schema = null, long startValue = 1L, int incrementBy = 1, long? minValue = null, @@ -679,7 +681,7 @@ public virtual OperationBuilder CreateSequence( /// A builder to allow annotations to be added to the operation. public virtual OperationBuilder CreateSequence( [NotNull] string name, - [CanBeNull] string schema = null, + [CanBeNull] string? schema = null, long startValue = 1L, int incrementBy = 1, long? minValue = null, @@ -722,7 +724,7 @@ public virtual OperationBuilder CreateCheckConstrai [NotNull] string name, [NotNull] string table, [NotNull] string sql, - [CanBeNull] string schema = null) + [CanBeNull] string? schema = null) => AddCheckConstraint(name, table, sql, schema); /// @@ -737,7 +739,7 @@ public virtual OperationBuilder AddCheckConstraint( [NotNull] string name, [NotNull] string table, [NotNull] string sql, - [CanBeNull] string schema = null) + [CanBeNull] string? schema = null) { Check.NotEmpty(name, nameof(name)); @@ -770,9 +772,9 @@ public virtual OperationBuilder AddCheckConstraint( public virtual CreateTableBuilder CreateTable( [NotNull] string name, [NotNull] Func columns, - [CanBeNull] string schema = null, - [CanBeNull] Action> constraints = null, - [CanBeNull] string comment = null) + [CanBeNull] string? schema = null, + [CanBeNull] Action>? constraints = null, + [CanBeNull] string? comment = null) { Check.NotEmpty(name, nameof(name)); Check.NotNull(columns, nameof(columns)); @@ -789,11 +791,13 @@ public virtual CreateTableBuilder CreateTable( var columnMap = new Dictionary(); foreach (var property in typeof(TColumns).GetTypeInfo().DeclaredProperties) { - var addColumnOperation = ((IInfrastructure)property.GetMethod.Invoke(columnsObject, null)).Instance; + var addColumnOperation = ((IInfrastructure)property.GetMethod!.Invoke(columnsObject, null)!).Instance; if (addColumnOperation.Name == null) { addColumnOperation.Name = property.Name; } + // TODO + //addColumnOperation.Validate(); columnMap.Add(property, addColumnOperation); } @@ -816,7 +820,7 @@ public virtual CreateTableBuilder CreateTable( public virtual OperationBuilder DropColumn( [NotNull] string name, [NotNull] string table, - [CanBeNull] string schema = null) + [CanBeNull] string? schema = null) { Check.NotEmpty(name, nameof(name)); Check.NotEmpty(table, nameof(table)); @@ -842,7 +846,7 @@ public virtual OperationBuilder DropColumn( public virtual OperationBuilder DropForeignKey( [NotNull] string name, [NotNull] string table, - [CanBeNull] string schema = null) + [CanBeNull] string? schema = null) { Check.NotEmpty(name, nameof(name)); Check.NotEmpty(table, nameof(table)); @@ -867,8 +871,8 @@ public virtual OperationBuilder DropForeignKey( /// A builder to allow annotations to be added to the operation. public virtual OperationBuilder DropIndex( [NotNull] string name, - [CanBeNull] string table = null, - [CanBeNull] string schema = null) + [CanBeNull] string? table = null, + [CanBeNull] string? schema = null) { Check.NotEmpty(name, nameof(name)); @@ -893,7 +897,7 @@ public virtual OperationBuilder DropIndex( public virtual OperationBuilder DropPrimaryKey( [NotNull] string name, [NotNull] string table, - [CanBeNull] string schema = null) + [CanBeNull] string? schema = null) { Check.NotEmpty(name, nameof(name)); Check.NotEmpty(table, nameof(table)); @@ -933,7 +937,7 @@ public virtual OperationBuilder DropSchema( /// A builder to allow annotations to be added to the operation. public virtual OperationBuilder DropSequence( [NotNull] string name, - [CanBeNull] string schema = null) + [CanBeNull] string? schema = null) { Check.NotEmpty(name, nameof(name)); @@ -953,7 +957,7 @@ public virtual OperationBuilder DropSequence( public virtual OperationBuilder DropCheckConstraint( [NotNull] string name, [NotNull] string table, - [CanBeNull] string schema = null) + [CanBeNull] string? schema = null) { Check.NotEmpty(name, nameof(name)); @@ -976,7 +980,7 @@ public virtual OperationBuilder DropCheckConstrain /// A builder to allow annotations to be added to the operation. public virtual OperationBuilder DropTable( [NotNull] string name, - [CanBeNull] string schema = null) + [CanBeNull] string? schema = null) { Check.NotEmpty(name, nameof(name)); @@ -996,7 +1000,7 @@ public virtual OperationBuilder DropTable( public virtual OperationBuilder DropUniqueConstraint( [NotNull] string name, [NotNull] string table, - [CanBeNull] string schema = null) + [CanBeNull] string? schema = null) { Check.NotEmpty(name, nameof(name)); Check.NotEmpty(table, nameof(table)); @@ -1024,7 +1028,7 @@ public virtual OperationBuilder RenameColumn( [NotNull] string name, [NotNull] string table, [NotNull] string newName, - [CanBeNull] string schema = null) + [CanBeNull] string? schema = null) { Check.NotEmpty(name, nameof(name)); Check.NotEmpty(table, nameof(table)); @@ -1053,8 +1057,8 @@ public virtual OperationBuilder RenameColumn( public virtual OperationBuilder RenameIndex( [NotNull] string name, [NotNull] string newName, - [CanBeNull] string table = null, - [CanBeNull] string schema = null) + [CanBeNull] string? table = null, + [CanBeNull] string? schema = null) { Check.NotEmpty(name, nameof(name)); Check.NotEmpty(newName, nameof(newName)); @@ -1081,9 +1085,9 @@ public virtual OperationBuilder RenameIndex( /// A builder to allow annotations to be added to the operation. public virtual OperationBuilder RenameSequence( [NotNull] string name, - [CanBeNull] string schema = null, - [CanBeNull] string newName = null, - [CanBeNull] string newSchema = null) + [CanBeNull] string? schema = null, + [CanBeNull] string? newName = null, + [CanBeNull] string? newSchema = null) { Check.NotEmpty(name, nameof(name)); @@ -1109,9 +1113,9 @@ public virtual OperationBuilder RenameSequence( /// A builder to allow annotations to be added to the operation. public virtual OperationBuilder RenameTable( [NotNull] string name, - [CanBeNull] string schema = null, - [CanBeNull] string newName = null, - [CanBeNull] string newSchema = null) + [CanBeNull] string? schema = null, + [CanBeNull] string? newName = null, + [CanBeNull] string? newSchema = null) { Check.NotEmpty(name, nameof(name)); @@ -1137,7 +1141,7 @@ public virtual OperationBuilder RenameTable( public virtual OperationBuilder RestartSequence( [NotNull] string name, long startValue = 1L, - [CanBeNull] string schema = null) + [CanBeNull] string? schema = null) { Check.NotEmpty(name, nameof(name)); @@ -1183,8 +1187,8 @@ public virtual OperationBuilder Sql( public virtual OperationBuilder InsertData( [NotNull] string table, [NotNull] string column, - [CanBeNull] object value, - [CanBeNull] string schema = null) + [CanBeNull] object? value, + [CanBeNull] string? schema = null) => InsertData(table, new[] { Check.NotEmpty(column, nameof(column)) }, new[] { value }, schema); /// @@ -1200,8 +1204,8 @@ public virtual OperationBuilder InsertData( [NotNull] string table, [NotNull] string column, [NotNull] string columnType, - [CanBeNull] object value, - [CanBeNull] string schema = null) + [CanBeNull] object? value, + [CanBeNull] string? schema = null) => InsertData( table, new[] { Check.NotEmpty(column, nameof(column)) }, @@ -1219,8 +1223,8 @@ public virtual OperationBuilder InsertData( public virtual OperationBuilder InsertData( [NotNull] string table, [NotNull] string[] columns, - [NotNull] object[] values, - [CanBeNull] string schema = null) + [NotNull] object?[] values, + [CanBeNull] string? schema = null) => InsertData(table, columns, ToMultidimensionalArray(Check.NotNull(values, nameof(values))), schema); /// @@ -1236,8 +1240,8 @@ public virtual OperationBuilder InsertData( [NotNull] string table, [NotNull] string[] columns, [NotNull] string[] columnTypes, - [NotNull] object[] values, - [CanBeNull] string schema = null) + [NotNull] object?[] values, + [CanBeNull] string? schema = null) => InsertData(table, columns, columnTypes, ToMultidimensionalArray(Check.NotNull(values, nameof(values))), schema); /// @@ -1252,7 +1256,7 @@ public virtual OperationBuilder InsertData( [NotNull] string table, [NotNull] string column, [NotNull] object[] values, - [CanBeNull] string schema = null) + [CanBeNull] string? schema = null) => InsertDataInternal( table, new[] { Check.NotEmpty(column, nameof(column)) }, @@ -1274,7 +1278,7 @@ public virtual OperationBuilder InsertData( [NotNull] string column, [NotNull] string columnType, [NotNull] object[] values, - [CanBeNull] string schema = null) + [CanBeNull] string? schema = null) => InsertDataInternal( table, new[] { Check.NotEmpty(column, nameof(column)) }, @@ -1296,8 +1300,8 @@ public virtual OperationBuilder InsertData( public virtual OperationBuilder InsertData( [NotNull] string table, [NotNull] string[] columns, - [NotNull] object[,] values, - [CanBeNull] string schema = null) + [NotNull] object?[,] values, + [CanBeNull] string? schema = null) => InsertDataInternal(table, columns, null, values, schema); /// @@ -1316,8 +1320,8 @@ public virtual OperationBuilder InsertData( [NotNull] string table, [NotNull] string[] columns, [NotNull] string[] columnTypes, - [NotNull] object[,] values, - [CanBeNull] string schema = null) + [NotNull] object?[,] values, + [CanBeNull] string? schema = null) { Check.NotEmpty(columnTypes, nameof(columnTypes)); @@ -1327,9 +1331,9 @@ public virtual OperationBuilder InsertData( private OperationBuilder InsertDataInternal( string table, string[] columns, - string[] columnTypes, - object[,] values, - string schema) + string[]? columnTypes, + object?[,] values, + string? schema) { Check.NotEmpty(table, nameof(table)); Check.NotNull(columns, nameof(columns)); @@ -1359,8 +1363,8 @@ private OperationBuilder InsertDataInternal( public virtual OperationBuilder DeleteData( [NotNull] string table, [NotNull] string keyColumn, - [CanBeNull] object keyValue, - [CanBeNull] string schema = null) + [CanBeNull] object? keyValue, + [CanBeNull] string? schema = null) => DeleteData(table, new[] { Check.NotNull(keyColumn, nameof(keyValue)) }, new[] { keyValue }, schema); /// @@ -1378,8 +1382,8 @@ public virtual OperationBuilder DeleteData( [NotNull] string table, [NotNull] string keyColumn, [NotNull] string keyColumnType, - [CanBeNull] object keyValue, - [CanBeNull] string schema = null) + [CanBeNull] object? keyValue, + [CanBeNull] string? schema = null) => DeleteData( table, new[] { Check.NotNull(keyColumn, nameof(keyValue)) }, @@ -1399,8 +1403,8 @@ public virtual OperationBuilder DeleteData( public virtual OperationBuilder DeleteData( [NotNull] string table, [NotNull] string[] keyColumns, - [NotNull] object[] keyValues, - [CanBeNull] string schema = null) + [NotNull] object?[] keyValues, + [CanBeNull] string? schema = null) => DeleteData( table, keyColumns, @@ -1423,8 +1427,8 @@ public virtual OperationBuilder DeleteData( [NotNull] string table, [NotNull] string[] keyColumns, [NotNull] string[] keyColumnTypes, - [NotNull] object[] keyValues, - [CanBeNull] string schema = null) + [NotNull] object?[] keyValues, + [CanBeNull] string? schema = null) => DeleteDataInternal( table, keyColumns, @@ -1444,7 +1448,7 @@ public virtual OperationBuilder DeleteData( [NotNull] string table, [NotNull] string keyColumn, [NotNull] object[] keyValues, - [CanBeNull] string schema = null) + [CanBeNull] string? schema = null) => DeleteData( table, new[] { Check.NotEmpty(keyColumn, nameof(keyColumn)) }, @@ -1467,7 +1471,7 @@ public virtual OperationBuilder DeleteData( [NotNull] string keyColumn, [NotNull] string keyColumnType, [NotNull] object[] keyValues, - [CanBeNull] string schema = null) + [CanBeNull] string? schema = null) => DeleteData( table, new[] { Check.NotEmpty(keyColumn, nameof(keyColumn)) }, @@ -1490,8 +1494,8 @@ public virtual OperationBuilder DeleteData( public virtual OperationBuilder DeleteData( [NotNull] string table, [NotNull] string[] keyColumns, - [NotNull] object[,] keyValues, - [CanBeNull] string schema = null) + [NotNull] object?[,] keyValues, + [CanBeNull] string? schema = null) => DeleteDataInternal(table, keyColumns, null, keyValues, schema); /// @@ -1513,8 +1517,8 @@ public virtual OperationBuilder DeleteData( [NotNull] string table, [NotNull] string[] keyColumns, [NotNull] string[] keyColumnTypes, - [NotNull] object[,] keyValues, - [CanBeNull] string schema = null) + [NotNull] object?[,] keyValues, + [CanBeNull] string? schema = null) { Check.NotEmpty(keyColumnTypes, nameof(keyColumnTypes)); @@ -1524,9 +1528,9 @@ public virtual OperationBuilder DeleteData( private OperationBuilder DeleteDataInternal( string table, string[] keyColumns, - string[] keyColumnTypes, - object[,] keyValues, - string schema) + string[]? keyColumnTypes, + object?[,] keyValues, + string? schema) { Check.NotEmpty(table, nameof(table)); Check.NotNull(keyColumns, nameof(keyColumns)); @@ -1558,10 +1562,10 @@ private OperationBuilder DeleteDataInternal( public virtual OperationBuilder UpdateData( [NotNull] string table, [NotNull] string keyColumn, - [CanBeNull] object keyValue, + [CanBeNull] object? keyValue, [NotNull] string column, - [CanBeNull] object value, - [CanBeNull] string schema = null) + [CanBeNull] object? value, + [CanBeNull] string? schema = null) => UpdateData( table, keyColumn, @@ -1583,10 +1587,10 @@ public virtual OperationBuilder UpdateData( public virtual OperationBuilder UpdateData( [NotNull] string table, [NotNull] string keyColumn, - [CanBeNull] object keyValue, + [CanBeNull] object? keyValue, [NotNull] string[] columns, - [NotNull] object[] values, - [CanBeNull] string schema = null) + [NotNull] object?[] values, + [CanBeNull] string? schema = null) => UpdateData( table, new[] { Check.NotEmpty(keyColumn, nameof(keyColumn)) }, @@ -1611,8 +1615,8 @@ public virtual OperationBuilder UpdateData( [NotNull] string[] keyColumns, [NotNull] object[] keyValues, [NotNull] string column, - [CanBeNull] object value, - [CanBeNull] string schema = null) + [CanBeNull] object? value, + [CanBeNull] string? schema = null) => UpdateData( table, keyColumns, @@ -1635,10 +1639,10 @@ public virtual OperationBuilder UpdateData( public virtual OperationBuilder UpdateData( [NotNull] string table, [NotNull] string[] keyColumns, - [NotNull] object[] keyValues, + [NotNull] object?[] keyValues, [NotNull] string[] columns, - [NotNull] object[] values, - [CanBeNull] string schema = null) + [NotNull] object?[] values, + [CanBeNull] string? schema = null) => UpdateData( table, keyColumns, @@ -1670,7 +1674,7 @@ public virtual OperationBuilder UpdateData( [NotNull] string[] columns, [NotNull] string[] columnTypes, [NotNull] object[] values, - [CanBeNull] string schema = null) + [CanBeNull] string? schema = null) => UpdateData( table, keyColumns, @@ -1697,7 +1701,7 @@ public virtual OperationBuilder UpdateData( [NotNull] object[] keyValues, [NotNull] string column, [NotNull] object[] values, - [CanBeNull] string schema = null) + [CanBeNull] string? schema = null) => UpdateData( table, keyColumn, @@ -1724,8 +1728,8 @@ public virtual OperationBuilder UpdateData( [NotNull] string keyColumn, [NotNull] object[] keyValues, [NotNull] string[] columns, - [NotNull] object[,] values, - [CanBeNull] string schema = null) + [NotNull] object?[,] values, + [CanBeNull] string? schema = null) => UpdateData( table, new[] { Check.NotEmpty(keyColumn, nameof(keyColumn)) }, @@ -1754,7 +1758,7 @@ public virtual OperationBuilder UpdateData( [NotNull] object[,] keyValues, [NotNull] string column, [NotNull] object[] values, - [CanBeNull] string schema = null) + [CanBeNull] string? schema = null) => UpdateData( table, keyColumns, @@ -1783,10 +1787,10 @@ public virtual OperationBuilder UpdateData( public virtual OperationBuilder UpdateData( [NotNull] string table, [NotNull] string[] keyColumns, - [NotNull] object[,] keyValues, + [NotNull] object?[,] keyValues, [NotNull] string[] columns, - [NotNull] object[,] values, - [CanBeNull] string schema = null) + [NotNull] object?[,] values, + [CanBeNull] string? schema = null) => UpdateDataInternal(table, keyColumns, null, keyValues, columns, null, values, schema); /// @@ -1814,11 +1818,11 @@ public virtual OperationBuilder UpdateData( [NotNull] string table, [NotNull] string[] keyColumns, [NotNull] string[] keyColumnTypes, - [NotNull] object[,] keyValues, + [NotNull] object?[,] keyValues, [NotNull] string[] columns, [NotNull] string[] columnTypes, - [NotNull] object[,] values, - [CanBeNull] string schema = null) + [NotNull] object?[,] values, + [CanBeNull] string? schema = null) { Check.NotEmpty(keyColumnTypes, nameof(keyColumnTypes)); Check.NotEmpty(columnTypes, nameof(columnTypes)); @@ -1829,12 +1833,12 @@ public virtual OperationBuilder UpdateData( private OperationBuilder UpdateDataInternal( string table, string[] keyColumns, - string[] keyColumnTypes, - object[,] keyValues, + string[]? keyColumnTypes, + object?[,] keyValues, string[] columns, - string[] columnTypes, - object[,] values, - string schema) + string[]? columnTypes, + object?[,] values, + string? schema) { Check.NotEmpty(table, nameof(table)); Check.NotNull(keyColumns, nameof(keyColumns)); @@ -1858,11 +1862,11 @@ private OperationBuilder UpdateDataInternal( return new OperationBuilder(operation); } - private static object[,] ToMultidimensionalArray(object[] values, bool firstDimension = false) + private static object?[,] ToMultidimensionalArray(object?[] values, bool firstDimension = false) { var result = firstDimension - ? new object[values.Length, 1] - : new object[1, values.Length]; + ? new object?[values.Length, 1] + : new object?[1, values.Length]; for (var i = 0; i < values.Length; i++) { if (firstDimension) @@ -1886,7 +1890,7 @@ private OperationBuilder UpdateDataInternal( /// A string that represents the current object. [EditorBrowsable(EditorBrowsableState.Never)] public override string ToString() - => base.ToString(); + => base.ToString()!; /// /// Determines whether the specified object is equal to the current object. @@ -1894,7 +1898,7 @@ public override string ToString() /// The object to compare with the current object. /// if the specified object is equal to the current object; otherwise, . [EditorBrowsable(EditorBrowsableState.Never)] - public override bool Equals(object obj) + public override bool Equals(object? obj) => base.Equals(obj); /// diff --git a/src/EFCore.Relational/Migrations/MigrationCommand.cs b/src/EFCore.Relational/Migrations/MigrationCommand.cs index 2687b8182ad..99448e69976 100644 --- a/src/EFCore.Relational/Migrations/MigrationCommand.cs +++ b/src/EFCore.Relational/Migrations/MigrationCommand.cs @@ -10,6 +10,8 @@ using Microsoft.EntityFrameworkCore.Storage; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Migrations { /// @@ -18,7 +20,7 @@ namespace Microsoft.EntityFrameworkCore.Migrations public class MigrationCommand { private readonly IRelationalCommand _relationalCommand; - private readonly DbContext _context; + private readonly DbContext? _context; /// /// Creates a new instance of the command. @@ -29,7 +31,7 @@ public class MigrationCommand /// Indicates whether or not transactions should be suppressed while executing the command. public MigrationCommand( [NotNull] IRelationalCommand relationalCommand, - [CanBeNull] DbContext context, + [CanBeNull] DbContext? context, [NotNull] IDiagnosticsLogger logger, bool transactionSuppressed = false) { @@ -65,7 +67,7 @@ public virtual string CommandText /// The number of rows affected. public virtual int ExecuteNonQuery( [NotNull] IRelationalConnection connection, - [CanBeNull] IReadOnlyDictionary parameterValues = null) + [CanBeNull] IReadOnlyDictionary? parameterValues = null) => _relationalCommand.ExecuteNonQuery( new RelationalCommandParameterObject( connection, @@ -84,7 +86,7 @@ public virtual int ExecuteNonQuery( /// If the is canceled. public virtual Task ExecuteNonQueryAsync( [NotNull] IRelationalConnection connection, - [CanBeNull] IReadOnlyDictionary parameterValues = null, + [CanBeNull] IReadOnlyDictionary? parameterValues = null, CancellationToken cancellationToken = default) => _relationalCommand.ExecuteNonQueryAsync( new RelationalCommandParameterObject( diff --git a/src/EFCore.Relational/Migrations/MigrationCommandListBuilder.cs b/src/EFCore.Relational/Migrations/MigrationCommandListBuilder.cs index 763bfcb70f1..556866bbe41 100644 --- a/src/EFCore.Relational/Migrations/MigrationCommandListBuilder.cs +++ b/src/EFCore.Relational/Migrations/MigrationCommandListBuilder.cs @@ -7,6 +7,8 @@ using Microsoft.EntityFrameworkCore.Storage; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Migrations { /// diff --git a/src/EFCore.Relational/Migrations/MigrationsAnnotationProvider.cs b/src/EFCore.Relational/Migrations/MigrationsAnnotationProvider.cs index 2a736dce73f..4fd1022e200 100644 --- a/src/EFCore.Relational/Migrations/MigrationsAnnotationProvider.cs +++ b/src/EFCore.Relational/Migrations/MigrationsAnnotationProvider.cs @@ -9,6 +9,8 @@ using Microsoft.EntityFrameworkCore.Utilities; using Microsoft.Extensions.DependencyInjection; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Migrations { /// diff --git a/src/EFCore.Relational/Migrations/MigrationsAnnotationProviderDependencies.cs b/src/EFCore.Relational/Migrations/MigrationsAnnotationProviderDependencies.cs index 85525c3abd1..beadc193bf6 100644 --- a/src/EFCore.Relational/Migrations/MigrationsAnnotationProviderDependencies.cs +++ b/src/EFCore.Relational/Migrations/MigrationsAnnotationProviderDependencies.cs @@ -4,6 +4,8 @@ using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.Extensions.DependencyInjection; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Migrations { /// diff --git a/src/EFCore.Relational/Migrations/MigrationsAssemblyExtensions.cs b/src/EFCore.Relational/Migrations/MigrationsAssemblyExtensions.cs index 246d59f912e..40f82bd1d82 100644 --- a/src/EFCore.Relational/Migrations/MigrationsAssemblyExtensions.cs +++ b/src/EFCore.Relational/Migrations/MigrationsAssemblyExtensions.cs @@ -6,6 +6,8 @@ using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Migrations { /// diff --git a/src/EFCore.Relational/Migrations/MigrationsSqlGenerationOptions.cs b/src/EFCore.Relational/Migrations/MigrationsSqlGenerationOptions.cs index 57aed197270..97337a8bf9a 100644 --- a/src/EFCore.Relational/Migrations/MigrationsSqlGenerationOptions.cs +++ b/src/EFCore.Relational/Migrations/MigrationsSqlGenerationOptions.cs @@ -3,6 +3,8 @@ using System; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Migrations { /// diff --git a/src/EFCore.Relational/Migrations/MigrationsSqlGenerator.cs b/src/EFCore.Relational/Migrations/MigrationsSqlGenerator.cs index c9411691c2c..097765da550 100644 --- a/src/EFCore.Relational/Migrations/MigrationsSqlGenerator.cs +++ b/src/EFCore.Relational/Migrations/MigrationsSqlGenerator.cs @@ -15,6 +15,9 @@ using Microsoft.EntityFrameworkCore.Update; using Microsoft.EntityFrameworkCore.Utilities; using Microsoft.Extensions.DependencyInjection; +using NotNullWhenAttribute = System.Diagnostics.CodeAnalysis.NotNullWhenAttribute; + +#nullable enable namespace Microsoft.EntityFrameworkCore.Migrations { @@ -36,9 +39,9 @@ namespace Microsoft.EntityFrameworkCore.Migrations public class MigrationsSqlGenerator : IMigrationsSqlGenerator { private static readonly - IReadOnlyDictionary> + IReadOnlyDictionary> _generateActions = - new Dictionary> + new Dictionary> { { typeof(AddColumnOperation), (g, o, m, b) => g.Generate((AddColumnOperation)o, m, b) }, { typeof(AddForeignKeyOperation), (g, o, m, b) => g.Generate((AddForeignKeyOperation)o, m, b) }, @@ -121,7 +124,7 @@ protected virtual IUpdateSqlGenerator SqlGenerator /// The list of commands to be executed or scripted. public virtual IReadOnlyList Generate( IReadOnlyList operations, - IModel model = null, + IModel? model = null, MigrationsSqlGenerationOptions options = MigrationsSqlGenerationOptions.Default) { Check.NotNull(operations, nameof(operations)); @@ -161,7 +164,7 @@ public virtual IReadOnlyList Generate( /// The command builder to use to build the commands. protected virtual void Generate( [NotNull] MigrationOperation operation, - [CanBeNull] IModel model, + [CanBeNull] IModel? model, [NotNull] MigrationCommandListBuilder builder) { Check.NotNull(operation, nameof(operation)); @@ -186,7 +189,7 @@ protected virtual void Generate( /// Indicates whether or not to terminate the command after generating SQL for the operation. protected virtual void Generate( [NotNull] AddColumnOperation operation, - [CanBeNull] IModel model, + [CanBeNull] IModel? model, [NotNull] MigrationCommandListBuilder builder, bool terminate = true) { @@ -217,7 +220,7 @@ protected virtual void Generate( /// Indicates whether or not to terminate the command after generating SQL for the operation. protected virtual void Generate( [NotNull] AddForeignKeyOperation operation, - [CanBeNull] IModel model, + [CanBeNull] IModel? model, [NotNull] MigrationCommandListBuilder builder, bool terminate = true) { @@ -248,7 +251,7 @@ protected virtual void Generate( /// Indicates whether or not to terminate the command after generating SQL for the operation. protected virtual void Generate( [NotNull] AddPrimaryKeyOperation operation, - [CanBeNull] IModel model, + [CanBeNull] IModel? model, [NotNull] MigrationCommandListBuilder builder, bool terminate = true) { @@ -277,7 +280,7 @@ protected virtual void Generate( /// The command builder to use to build the commands. protected virtual void Generate( [NotNull] AddUniqueConstraintOperation operation, - [CanBeNull] IModel model, + [CanBeNull] IModel? model, [NotNull] MigrationCommandListBuilder builder) { Check.NotNull(operation, nameof(operation)); @@ -301,7 +304,7 @@ protected virtual void Generate( /// The command builder to use to build the commands. protected virtual void Generate( [NotNull] AddCheckConstraintOperation operation, - [CanBeNull] IModel model, + [CanBeNull] IModel? model, [NotNull] MigrationCommandListBuilder builder) { Check.NotNull(operation, nameof(operation)); @@ -331,7 +334,7 @@ protected virtual void Generate( /// The command builder to use to build the commands. protected virtual void Generate( [NotNull] AlterColumnOperation operation, - [CanBeNull] IModel model, + [CanBeNull] IModel? model, [NotNull] MigrationCommandListBuilder builder) => throw new NotSupportedException(RelationalStrings.MigrationSqlGenerationMissing(nameof(AlterColumnOperation))); @@ -350,7 +353,7 @@ protected virtual void Generate( /// The command builder to use to build the commands. protected virtual void Generate( [NotNull] AlterDatabaseOperation operation, - [CanBeNull] IModel model, + [CanBeNull] IModel? model, [NotNull] MigrationCommandListBuilder builder) { } @@ -370,7 +373,7 @@ protected virtual void Generate( /// The command builder to use to build the commands. protected virtual void Generate( [NotNull] RenameIndexOperation operation, - [CanBeNull] IModel model, + [CanBeNull] IModel? model, [NotNull] MigrationCommandListBuilder builder) => throw new NotSupportedException(RelationalStrings.MigrationSqlGenerationMissing(nameof(RenameIndexOperation))); @@ -383,7 +386,7 @@ protected virtual void Generate( /// The command builder to use to build the commands. protected virtual void Generate( [NotNull] AlterSequenceOperation operation, - [CanBeNull] IModel model, + [CanBeNull] IModel? model, [NotNull] MigrationCommandListBuilder builder) { Check.NotNull(operation, nameof(operation)); @@ -416,7 +419,7 @@ protected virtual void Generate( /// The command builder to use to build the commands. protected virtual void Generate( [NotNull] AlterTableOperation operation, - [CanBeNull] IModel model, + [CanBeNull] IModel? model, [NotNull] MigrationCommandListBuilder builder) { } @@ -436,7 +439,7 @@ protected virtual void Generate( /// The command builder to use to build the commands. protected virtual void Generate( [NotNull] RenameTableOperation operation, - [CanBeNull] IModel model, + [CanBeNull] IModel? model, [NotNull] MigrationCommandListBuilder builder) => throw new NotSupportedException(RelationalStrings.MigrationSqlGenerationMissing(nameof(RenameTableOperation))); @@ -450,7 +453,7 @@ protected virtual void Generate( /// Indicates whether or not to terminate the command after generating SQL for the operation. protected virtual void Generate( [NotNull] CreateIndexOperation operation, - [CanBeNull] IModel model, + [CanBeNull] IModel? model, [NotNull] MigrationCommandListBuilder builder, bool terminate = true) { @@ -499,7 +502,7 @@ protected virtual void Generate( /// The command builder to use to build the commands. protected virtual void Generate( [NotNull] EnsureSchemaOperation operation, - [CanBeNull] IModel model, + [CanBeNull] IModel? model, [NotNull] MigrationCommandListBuilder builder) => throw new NotSupportedException(RelationalStrings.MigrationSqlGenerationMissing(nameof(EnsureSchemaOperation))); @@ -512,7 +515,7 @@ protected virtual void Generate( /// The command builder to use to build the commands. protected virtual void Generate( [NotNull] CreateSequenceOperation operation, - [CanBeNull] IModel model, + [CanBeNull] IModel? model, [NotNull] MigrationCommandListBuilder builder) { Check.NotNull(operation, nameof(operation)); @@ -555,7 +558,7 @@ protected virtual void Generate( /// Indicates whether or not to terminate the command after generating SQL for the operation. protected virtual void Generate( [NotNull] CreateTableOperation operation, - [CanBeNull] IModel model, + [CanBeNull] IModel? model, [NotNull] MigrationCommandListBuilder builder, bool terminate = true) { @@ -593,7 +596,7 @@ protected virtual void Generate( /// Indicates whether or not to terminate the command after generating SQL for the operation. protected virtual void Generate( [NotNull] DropColumnOperation operation, - [CanBeNull] IModel model, + [CanBeNull] IModel? model, [NotNull] MigrationCommandListBuilder builder, bool terminate = true) { @@ -623,7 +626,7 @@ protected virtual void Generate( /// Indicates whether or not to terminate the command after generating SQL for the operation. protected virtual void Generate( [NotNull] DropForeignKeyOperation operation, - [CanBeNull] IModel model, + [CanBeNull] IModel? model, [NotNull] MigrationCommandListBuilder builder, bool terminate = true) { @@ -659,7 +662,7 @@ protected virtual void Generate( /// Indicates whether or not to terminate the command after generating SQL for the operation. protected virtual void Generate( [NotNull] DropIndexOperation operation, - [CanBeNull] IModel model, + [CanBeNull] IModel? model, [NotNull] MigrationCommandListBuilder builder, bool terminate = true) => throw new NotSupportedException(RelationalStrings.MigrationSqlGenerationMissing(nameof(DropIndexOperation))); @@ -674,7 +677,7 @@ protected virtual void Generate( /// Indicates whether or not to terminate the command after generating SQL for the operation. protected virtual void Generate( [NotNull] DropPrimaryKeyOperation operation, - [CanBeNull] IModel model, + [CanBeNull] IModel? model, [NotNull] MigrationCommandListBuilder builder, bool terminate = true) { @@ -703,7 +706,7 @@ protected virtual void Generate( /// The command builder to use to build the commands. protected virtual void Generate( [NotNull] DropSchemaOperation operation, - [CanBeNull] IModel model, + [CanBeNull] IModel? model, [NotNull] MigrationCommandListBuilder builder) { Check.NotNull(operation, nameof(operation)); @@ -726,7 +729,7 @@ protected virtual void Generate( /// The command builder to use to build the commands. protected virtual void Generate( [NotNull] DropSequenceOperation operation, - [CanBeNull] IModel model, + [CanBeNull] IModel? model, [NotNull] MigrationCommandListBuilder builder) { Check.NotNull(operation, nameof(operation)); @@ -750,7 +753,7 @@ protected virtual void Generate( /// Indicates whether or not to terminate the command after generating SQL for the operation. protected virtual void Generate( [NotNull] DropTableOperation operation, - [CanBeNull] IModel model, + [CanBeNull] IModel? model, [NotNull] MigrationCommandListBuilder builder, bool terminate = true) { @@ -777,7 +780,7 @@ protected virtual void Generate( /// The command builder to use to build the commands. protected virtual void Generate( [NotNull] DropUniqueConstraintOperation operation, - [CanBeNull] IModel model, + [CanBeNull] IModel? model, [NotNull] MigrationCommandListBuilder builder) { Check.NotNull(operation, nameof(operation)); @@ -802,7 +805,7 @@ protected virtual void Generate( /// The command builder to use to build the commands. protected virtual void Generate( [NotNull] DropCheckConstraintOperation operation, - [CanBeNull] IModel model, + [CanBeNull] IModel? model, [NotNull] MigrationCommandListBuilder builder) { Check.NotNull(operation, nameof(operation)); @@ -833,7 +836,7 @@ protected virtual void Generate( /// The command builder to use to build the commands. protected virtual void Generate( [NotNull] RenameColumnOperation operation, - [CanBeNull] IModel model, + [CanBeNull] IModel? model, [NotNull] MigrationCommandListBuilder builder) => throw new NotSupportedException(RelationalStrings.MigrationSqlGenerationMissing(nameof(RenameColumnOperation))); @@ -852,7 +855,7 @@ protected virtual void Generate( /// The command builder to use to build the commands. protected virtual void Generate( [NotNull] RenameSequenceOperation operation, - [CanBeNull] IModel model, + [CanBeNull] IModel? model, [NotNull] MigrationCommandListBuilder builder) => throw new NotSupportedException(RelationalStrings.MigrationSqlGenerationMissing(nameof(RenameSequenceOperation))); @@ -865,7 +868,7 @@ protected virtual void Generate( /// The command builder to use to build the commands. protected virtual void Generate( [NotNull] RestartSequenceOperation operation, - [CanBeNull] IModel model, + [CanBeNull] IModel? model, [NotNull] MigrationCommandListBuilder builder) { Check.NotNull(operation, nameof(operation)); @@ -892,7 +895,7 @@ protected virtual void Generate( /// The command builder to use to build the commands. protected virtual void Generate( [NotNull] SqlOperation operation, - [CanBeNull] IModel model, + [CanBeNull] IModel? model, [NotNull] MigrationCommandListBuilder builder) { Check.NotNull(operation, nameof(operation)); @@ -913,7 +916,7 @@ protected virtual void Generate( /// Indicates whether or not to terminate the command after generating SQL for the operation. protected virtual void Generate( [NotNull] InsertDataOperation operation, - [CanBeNull] IModel model, + [CanBeNull] IModel? model, [NotNull] MigrationCommandListBuilder builder, bool terminate = true) { @@ -945,7 +948,7 @@ protected virtual void Generate( /// The commands that correspond to the given operation. protected virtual IEnumerable GenerateModificationCommands( [NotNull] InsertDataOperation operation, - [CanBeNull] IModel model) + [CanBeNull] IModel? model) { if (operation.Columns.Length != operation.Values.GetLength(1)) { @@ -987,7 +990,7 @@ protected virtual IEnumerable GenerateModificationCommands( ? propertyMapping.TypeMapping : value != null ? Dependencies.TypeMappingSource.FindMapping(value.GetType(), columnType) - : Dependencies.TypeMappingSource.FindMapping(columnType); + : Dependencies.TypeMappingSource.FindMapping(columnType!); modifications[j] = new ColumnModification( name, originalValue: null, value, propertyMapping?.Property, columnType, typeMapping, @@ -1009,7 +1012,7 @@ protected virtual IEnumerable GenerateModificationCommands( /// The command builder to use to build the commands. protected virtual void Generate( [NotNull] DeleteDataOperation operation, - [CanBeNull] IModel model, + [CanBeNull] IModel? model, [NotNull] MigrationCommandListBuilder builder) { Check.NotNull(operation, nameof(operation)); @@ -1036,7 +1039,7 @@ protected virtual void Generate( /// The commands that correspond to the given operation. protected virtual IEnumerable GenerateModificationCommands( [NotNull] DeleteDataOperation operation, - [CanBeNull] IModel model) + [CanBeNull] IModel? model) { if (operation.KeyColumns.Length != operation.KeyValues.GetLength(1)) { @@ -1078,7 +1081,7 @@ protected virtual IEnumerable GenerateModificationCommands( ? propertyMapping.TypeMapping : value != null ? Dependencies.TypeMappingSource.FindMapping(value.GetType(), columnType) - : Dependencies.TypeMappingSource.FindMapping(columnType); + : Dependencies.TypeMappingSource.FindMapping(columnType!); modifications[j] = new ColumnModification( name, originalValue: null, value, propertyMapping?.Property, columnType, typeMapping, @@ -1100,7 +1103,7 @@ protected virtual IEnumerable GenerateModificationCommands( /// The command builder to use to build the commands. protected virtual void Generate( [NotNull] UpdateDataOperation operation, - [CanBeNull] IModel model, + [CanBeNull] IModel? model, [NotNull] MigrationCommandListBuilder builder) { Check.NotNull(operation, nameof(operation)); @@ -1127,7 +1130,7 @@ protected virtual void Generate( /// The commands that correspond to the given operation. protected virtual IEnumerable GenerateModificationCommands( [NotNull] UpdateDataOperation operation, - [CanBeNull] IModel model) + [CanBeNull] IModel? model) { if (operation.KeyColumns.Length != operation.KeyValues.GetLength(1)) { @@ -1194,7 +1197,7 @@ protected virtual IEnumerable GenerateModificationCommands( ? propertyMapping.TypeMapping : value != null ? Dependencies.TypeMappingSource.FindMapping(value.GetType(), columnType) - : Dependencies.TypeMappingSource.FindMapping(columnType); + : Dependencies.TypeMappingSource.FindMapping(columnType!); keys[j] = new ColumnModification( name, originalValue: null, value, propertyMapping?.Property, columnType, typeMapping, @@ -1213,7 +1216,7 @@ protected virtual IEnumerable GenerateModificationCommands( ? propertyMapping.TypeMapping : value != null ? Dependencies.TypeMappingSource.FindMapping(value.GetType(), columnType) - : Dependencies.TypeMappingSource.FindMapping(columnType); + : Dependencies.TypeMappingSource.FindMapping(columnType!); modifications[j] = new ColumnModification( name, originalValue: null, value, propertyMapping?.Property, columnType, typeMapping, @@ -1227,16 +1230,16 @@ protected virtual IEnumerable GenerateModificationCommands( } } - private static string FormatTable(string table, string schema) + private static string FormatTable(string table, string? schema) => schema == null ? table : schema + "." + table; private static IColumnMapping[] GetPropertyMappings( [NotNull] string[] names, [NotNull] string tableName, - [CanBeNull] string schema, - [NotNull] IModel model) + [CanBeNull] string? schema, + [CanBeNull] IModel? model) { - var table = model.GetRelationalModel().FindTable(tableName, schema); + var table = model?.GetRelationalModel().FindTable(tableName, schema); if (table == null) { throw new InvalidOperationException( @@ -1270,7 +1273,7 @@ private static IColumnMapping[] GetPropertyMappings( /// The command builder to use to add the SQL fragment. protected virtual void SequenceOptions( [NotNull] AlterSequenceOperation operation, - [CanBeNull] IModel model, + [CanBeNull] IModel? model, [NotNull] MigrationCommandListBuilder builder) => SequenceOptions( operation.Schema, @@ -1287,7 +1290,7 @@ protected virtual void SequenceOptions( /// The command builder to use to add the SQL fragment. protected virtual void SequenceOptions( [NotNull] CreateSequenceOperation operation, - [CanBeNull] IModel model, + [CanBeNull] IModel? model, [NotNull] MigrationCommandListBuilder builder) => SequenceOptions( operation.Schema, @@ -1305,10 +1308,10 @@ protected virtual void SequenceOptions( /// The target model which may be if the operations exist without a model. /// The command builder to use to add the SQL fragment. protected virtual void SequenceOptions( - [CanBeNull] string schema, + [CanBeNull] string? schema, [NotNull] string name, [NotNull] SequenceOperation operation, - [CanBeNull] IModel model, + [CanBeNull] IModel? model, [NotNull] MigrationCommandListBuilder builder) { Check.NotEmpty(name, nameof(name)); @@ -1355,7 +1358,7 @@ protected virtual void SequenceOptions( /// The command builder to use to add the SQL fragment. protected virtual void CreateTableColumns( [NotNull] CreateTableOperation operation, - [CanBeNull] IModel model, + [CanBeNull] IModel? model, [NotNull] MigrationCommandListBuilder builder) { Check.NotNull(operation, nameof(operation)); @@ -1380,7 +1383,7 @@ protected virtual void CreateTableColumns( /// The command builder to use to add the SQL fragment. protected virtual void ColumnDefinition( [NotNull] AddColumnOperation operation, - [CanBeNull] IModel model, + [CanBeNull] IModel? model, [NotNull] MigrationCommandListBuilder builder) => ColumnDefinition( operation.Schema, @@ -1400,11 +1403,11 @@ protected virtual void ColumnDefinition( /// The target model which may be if the operations exist without a model. /// The command builder to use to add the SQL fragment. protected virtual void ColumnDefinition( - [CanBeNull] string schema, + [CanBeNull] string? schema, [NotNull] string table, [NotNull] string name, [NotNull] ColumnOperation operation, - [CanBeNull] IModel model, + [CanBeNull] IModel? model, [NotNull] MigrationCommandListBuilder builder) { Check.NotEmpty(name, nameof(name)); @@ -1418,7 +1421,7 @@ protected virtual void ColumnDefinition( return; } - var columnType = operation.ColumnType ?? GetColumnType(schema, table, name, operation, model); + var columnType = operation.ColumnType ?? GetColumnType(schema, table, name, operation, model)!; builder .Append(Dependencies.SqlGenerationHelper.DelimitIdentifier(name)) .Append(" ") @@ -1446,11 +1449,11 @@ protected virtual void ColumnDefinition( /// The target model which may be if the operations exist without a model. /// The command builder to use to add the SQL fragment. protected virtual void ComputedColumnDefinition( - [CanBeNull] string schema, + [CanBeNull] string? schema, [NotNull] string table, [NotNull] string name, [NotNull] ColumnOperation operation, - [CanBeNull] IModel model, + [CanBeNull] IModel? model, [NotNull] MigrationCommandListBuilder builder) => throw new NotSupportedException(RelationalStrings.MigrationSqlGenerationMissing(nameof(ColumnOperation))); @@ -1463,12 +1466,12 @@ protected virtual void ComputedColumnDefinition( /// The column metadata. /// The target model which may be if the operations exist without a model. /// The database/store type for the column. - protected virtual string GetColumnType( - [CanBeNull] string schema, + protected virtual string? GetColumnType( + [CanBeNull] string? schema, [NotNull] string tableName, [NotNull] string name, [NotNull] ColumnOperation operation, - [CanBeNull] IModel model) + [CanBeNull] IModel? model) { Check.NotEmpty(tableName, nameof(tableName)); Check.NotEmpty(name, nameof(name)); @@ -1490,7 +1493,7 @@ protected virtual string GetColumnType( return column.StoreType; } - keyOrIndex = table.UniqueConstraints.Any(u => u.Columns.Contains(column)) + keyOrIndex = table!.UniqueConstraints.Any(u => u.Columns.Contains(column)) || table.ForeignKeyConstraints.Any(u => u.Columns.Contains(column)) || table.Indexes.Any(u => u.Columns.Contains(column)); } @@ -1505,7 +1508,7 @@ protected virtual string GetColumnType( operation.IsFixedLength, operation.Precision, operation.Scale) - .StoreType; + ?.StoreType; } /// @@ -1516,9 +1519,9 @@ protected virtual string GetColumnType( /// Store/database type of the column. /// The command builder to use to add the SQL fragment. protected virtual void DefaultValue( - [CanBeNull] object defaultValue, - [CanBeNull] string defaultValueSql, - [CanBeNull] string columnType, + [CanBeNull] object? defaultValue, + [CanBeNull] string? defaultValueSql, + [CanBeNull] string? columnType, [NotNull] MigrationCommandListBuilder builder) { Check.NotNull(builder, nameof(builder)); @@ -1554,7 +1557,7 @@ protected virtual void DefaultValue( /// The command builder to use to add the SQL fragment. protected virtual void CreateTableConstraints( [NotNull] CreateTableOperation operation, - [CanBeNull] IModel model, + [CanBeNull] IModel? model, [NotNull] MigrationCommandListBuilder builder) { Check.NotNull(operation, nameof(operation)); @@ -1574,7 +1577,7 @@ protected virtual void CreateTableConstraints( /// The command builder to use to add the SQL fragment. protected virtual void CreateTableForeignKeys( [NotNull] CreateTableOperation operation, - [CanBeNull] IModel model, + [CanBeNull] IModel? model, [NotNull] MigrationCommandListBuilder builder) { Check.NotNull(operation, nameof(operation)); @@ -1595,7 +1598,7 @@ protected virtual void CreateTableForeignKeys( /// The command builder to use to add the SQL fragment. protected virtual void ForeignKeyConstraint( [NotNull] AddForeignKeyOperation operation, - [CanBeNull] IModel model, + [CanBeNull] IModel? model, [NotNull] MigrationCommandListBuilder builder) { Check.NotNull(operation, nameof(operation)); @@ -1644,7 +1647,7 @@ protected virtual void ForeignKeyConstraint( /// The command builder to use to add the SQL fragment. protected virtual void CreateTablePrimaryKeyConstraint( [NotNull] CreateTableOperation operation, - [CanBeNull] IModel model, + [CanBeNull] IModel? model, [NotNull] MigrationCommandListBuilder builder) { Check.NotNull(operation, nameof(operation)); @@ -1665,7 +1668,7 @@ protected virtual void CreateTablePrimaryKeyConstraint( /// The command builder to use to add the SQL fragment. protected virtual void PrimaryKeyConstraint( [NotNull] AddPrimaryKeyOperation operation, - [CanBeNull] IModel model, + [CanBeNull] IModel? model, [NotNull] MigrationCommandListBuilder builder) { Check.NotNull(operation, nameof(operation)); @@ -1697,7 +1700,7 @@ protected virtual void PrimaryKeyConstraint( /// The command builder to use to add the SQL fragment. protected virtual void CreateTableUniqueConstraints( [NotNull] CreateTableOperation operation, - [CanBeNull] IModel model, + [CanBeNull] IModel? model, [NotNull] MigrationCommandListBuilder builder) { Check.NotNull(operation, nameof(operation)); @@ -1718,7 +1721,7 @@ protected virtual void CreateTableUniqueConstraints( /// The command builder to use to add the SQL fragment. protected virtual void UniqueConstraint( [NotNull] AddUniqueConstraintOperation operation, - [CanBeNull] IModel model, + [CanBeNull] IModel? model, [NotNull] MigrationCommandListBuilder builder) { Check.NotNull(operation, nameof(operation)); @@ -1750,7 +1753,7 @@ protected virtual void UniqueConstraint( /// The command builder to use to add the SQL fragment. protected virtual void CreateTableCheckConstraints( [NotNull] CreateTableOperation operation, - [CanBeNull] IModel model, + [CanBeNull] IModel? model, [NotNull] MigrationCommandListBuilder builder) { Check.NotNull(operation, nameof(operation)); @@ -1771,7 +1774,7 @@ protected virtual void CreateTableCheckConstraints( /// The command builder to use to add the SQL fragment. protected virtual void CheckConstraint( [NotNull] AddCheckConstraintOperation operation, - [CanBeNull] IModel model, + [CanBeNull] IModel? model, [NotNull] MigrationCommandListBuilder builder) { Check.NotNull(operation, nameof(operation)); @@ -1802,7 +1805,7 @@ protected virtual void CheckConstraint( /// The command builder to use to add the SQL fragment. protected virtual void IndexTraits( [NotNull] MigrationOperation operation, - [CanBeNull] IModel model, + [CanBeNull] IModel? model, [NotNull] MigrationCommandListBuilder builder) { } @@ -1815,7 +1818,7 @@ protected virtual void IndexTraits( /// The command builder to use to add the SQL fragment. protected virtual void IndexOptions( [NotNull] CreateIndexOperation operation, - [CanBeNull] IModel model, + [CanBeNull] IModel? model, [NotNull] MigrationCommandListBuilder builder) { if (!string.IsNullOrEmpty(operation.Filter)) @@ -1867,9 +1870,9 @@ protected virtual void ForeignKeyAction( /// The table name. /// The list of types, which may be empty if no types are mapped to the given table. [Obsolete("Use model?.GetRelationalModel().FindTable()")] - protected virtual IEnumerable FindEntityTypes( - [CanBeNull] IModel model, - [CanBeNull] string schema, + protected virtual IEnumerable? FindEntityTypes( + [CanBeNull] IModel? model, + [CanBeNull] string? schema, [NotNull] string tableName) => model?.GetRelationalModel().FindTable(Check.NotEmpty(tableName, nameof(tableName)), schema) ?.EntityTypeMappings.Select(m => m.EntityType); @@ -1890,13 +1893,13 @@ protected virtual IEnumerable FindEntityTypes( /// The column name. /// The property found, or if no property maps to the given column. [Obsolete("Use model?.GetRelationalModel().FindTable().FindColumn()")] - protected virtual IProperty FindProperty( - [CanBeNull] IModel model, - [CanBeNull] string schema, + protected virtual IProperty? FindProperty( + [CanBeNull] IModel? model, + [CanBeNull] string? schema, [NotNull] string tableName, [NotNull] string columnName) => model?.GetRelationalModel().FindTable(Check.NotEmpty(tableName, nameof(tableName)), schema) - .Columns.FirstOrDefault(c => c.Name == columnName)?.PropertyMappings.First().Property; + ?.Columns.FirstOrDefault(c => c.Name == columnName)?.PropertyMappings.First().Property; /// /// Generates a SQL fragment to terminate the SQL command. @@ -1933,7 +1936,7 @@ protected virtual string ColumnList([NotNull] string[] columns) /// , has /// no version specified, or was generated by an EF Core version prior to 1.1. /// - protected virtual bool IsOldColumnSupported([CanBeNull] IModel model) + protected virtual bool IsOldColumnSupported([CanBeNull] IModel? model) => TryGetVersion(model, out var version) && VersionComparer.Compare(version, "1.1.0") >= 0; /// @@ -1942,7 +1945,7 @@ protected virtual bool IsOldColumnSupported([CanBeNull] IModel model) /// /// The target model. /// if the legacy behavior is used. - protected virtual bool HasLegacyRenameOperations([CanBeNull] IModel model) + protected virtual bool HasLegacyRenameOperations([CanBeNull] IModel? model) => !TryGetVersion(model, out var version) || VersionComparer.Compare(version, "2.1.0") < 0; /// @@ -1952,7 +1955,7 @@ protected virtual bool HasLegacyRenameOperations([CanBeNull] IModel model) /// The target model. /// The version. /// if the version could be retrieved. - protected virtual bool TryGetVersion([CanBeNull] IModel model, out string version) + protected virtual bool TryGetVersion([CanBeNull] IModel? model, [NotNullWhen(true)] out string? version) { if (!(model?.GetProductVersion() is string versionString)) { diff --git a/src/EFCore.Relational/Migrations/MigrationsSqlGeneratorDependencies.cs b/src/EFCore.Relational/Migrations/MigrationsSqlGeneratorDependencies.cs index 4381134d0d6..fc6fbd536bf 100644 --- a/src/EFCore.Relational/Migrations/MigrationsSqlGeneratorDependencies.cs +++ b/src/EFCore.Relational/Migrations/MigrationsSqlGeneratorDependencies.cs @@ -9,6 +9,8 @@ using Microsoft.EntityFrameworkCore.Utilities; using Microsoft.Extensions.DependencyInjection; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Migrations { /// diff --git a/src/EFCore.Relational/Migrations/Operations/AddCheckConstraintOperation.cs b/src/EFCore.Relational/Migrations/Operations/AddCheckConstraintOperation.cs index 06e18ce1556..a6820bdaf2c 100644 --- a/src/EFCore.Relational/Migrations/Operations/AddCheckConstraintOperation.cs +++ b/src/EFCore.Relational/Migrations/Operations/AddCheckConstraintOperation.cs @@ -6,6 +6,8 @@ using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Migrations.Operations { /// @@ -17,17 +19,17 @@ public class AddCheckConstraintOperation : MigrationOperation, ITableMigrationOp /// /// The name of the check constraint. /// - public virtual string Name { get; [param: NotNull] set; } + public virtual string Name { get; [param: NotNull] set; } = null!; /// /// The table of the check constraint. /// - public virtual string Table { get; [param: NotNull] set; } + public virtual string Table { get; [param: NotNull] set; } = null!; /// /// The table schema that contains the check constraint, or if the default schema should be used. /// - public virtual string Schema { get; [param: CanBeNull] set; } + public virtual string? Schema { get; [param: CanBeNull] set; } /// /// The logical sql expression used in a CHECK constraint and returns TRUE or FALSE. @@ -35,7 +37,7 @@ public class AddCheckConstraintOperation : MigrationOperation, ITableMigrationOp /// but can reference other columns in the same table for the same row. /// The expression cannot reference an alias data type. /// - public virtual string Sql { get; [param: NotNull] set; } + public virtual string Sql { get; [param: NotNull] set; } = null!; /// /// Creates a new from the specified check constraint. @@ -51,7 +53,7 @@ public static AddCheckConstraintOperation CreateFrom([NotNull] ICheckConstraint Name = checkConstraint.Name, Sql = checkConstraint.Sql, Schema = checkConstraint.EntityType.GetSchema(), - Table = checkConstraint.EntityType.GetTableName() + Table = checkConstraint.EntityType.GetTableName()! }; operation.AddAnnotations(checkConstraint.GetAnnotations()); diff --git a/src/EFCore.Relational/Migrations/Operations/AddColumnOperation.cs b/src/EFCore.Relational/Migrations/Operations/AddColumnOperation.cs index c2da21f1c72..cc36baf24ad 100644 --- a/src/EFCore.Relational/Migrations/Operations/AddColumnOperation.cs +++ b/src/EFCore.Relational/Migrations/Operations/AddColumnOperation.cs @@ -3,6 +3,8 @@ using System.Diagnostics; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Migrations.Operations { /// diff --git a/src/EFCore.Relational/Migrations/Operations/AddForeignKeyOperation.cs b/src/EFCore.Relational/Migrations/Operations/AddForeignKeyOperation.cs index bb72990b918..a46dfee7441 100644 --- a/src/EFCore.Relational/Migrations/Operations/AddForeignKeyOperation.cs +++ b/src/EFCore.Relational/Migrations/Operations/AddForeignKeyOperation.cs @@ -7,6 +7,8 @@ using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Migrations.Operations { /// @@ -18,39 +20,39 @@ public class AddForeignKeyOperation : MigrationOperation, ITableMigrationOperati /// /// The name of the foreign key constraint. /// - public virtual string Name { get; [param: NotNull] set; } + public virtual string Name { get; [param: NotNull] set; } = null!; /// /// The schema that contains the table, or if the default schema should be used. /// - public virtual string Schema { get; [param: CanBeNull] set; } + public virtual string? Schema { get; [param: CanBeNull] set; } /// /// The table to which the foreign key should be added. /// - public virtual string Table { get; [param: NotNull] set; } + public virtual string Table { get; [param: NotNull] set; } = null!; /// /// The ordered-list of column names for the columns that make up the foreign key. /// - public virtual string[] Columns { get; [param: NotNull] set; } + public virtual string[] Columns { get; [param: NotNull] set; } = null!; /// /// The schema that contains the table to which this foreign key is constrained, /// or if the default schema should be used. /// - public virtual string PrincipalSchema { get; [param: CanBeNull] set; } + public virtual string? PrincipalSchema { get; [param: CanBeNull] set; } /// /// The table to which the foreign key is constrained. /// - public virtual string PrincipalTable { get; [param: NotNull] set; } + public virtual string PrincipalTable { get; [param: NotNull] set; } = null!; /// /// The ordered-list of column names for the columns to which the columns that make up this foreign key are constrained, or /// to constrain to the primary key columns. /// - public virtual string[] PrincipalColumns { get; [param: CanBeNull] set; } + public virtual string[]? PrincipalColumns { get; [param: CanBeNull] set; } /// /// The to use for updates. diff --git a/src/EFCore.Relational/Migrations/Operations/AddPrimaryKeyOperation.cs b/src/EFCore.Relational/Migrations/Operations/AddPrimaryKeyOperation.cs index 462ffb64c37..bf0fc461d03 100644 --- a/src/EFCore.Relational/Migrations/Operations/AddPrimaryKeyOperation.cs +++ b/src/EFCore.Relational/Migrations/Operations/AddPrimaryKeyOperation.cs @@ -7,6 +7,8 @@ using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Migrations.Operations { /// @@ -18,22 +20,22 @@ public class AddPrimaryKeyOperation : MigrationOperation, ITableMigrationOperati /// /// The schema that contains the table, or if the default schema should be used. /// - public virtual string Schema { get; [param: CanBeNull] set; } + public virtual string? Schema { get; [param: CanBeNull] set; } /// /// The table to which the key should be added. /// - public virtual string Table { get; [param: NotNull] set; } + public virtual string Table { get; [param: NotNull] set; } = null!; /// /// The name of the foreign key constraint. /// - public virtual string Name { get; [param: NotNull] set; } + public virtual string Name { get; [param: NotNull] set; } = null!; /// /// The ordered-list of column names for the columns that make up the primary key. /// - public virtual string[] Columns { get; [param: NotNull] set; } + public virtual string[] Columns { get; [param: NotNull] set; } = null!; /// /// Creates a new from the specified primary key. diff --git a/src/EFCore.Relational/Migrations/Operations/AddUniqueConstraintOperation.cs b/src/EFCore.Relational/Migrations/Operations/AddUniqueConstraintOperation.cs index f8d98924801..08ff7bf980b 100644 --- a/src/EFCore.Relational/Migrations/Operations/AddUniqueConstraintOperation.cs +++ b/src/EFCore.Relational/Migrations/Operations/AddUniqueConstraintOperation.cs @@ -7,6 +7,8 @@ using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Migrations.Operations { /// @@ -18,22 +20,22 @@ public class AddUniqueConstraintOperation : MigrationOperation, ITableMigrationO /// /// The schema that contains the table, or if the default schema should be used. /// - public virtual string Schema { get; [param: CanBeNull] set; } + public virtual string? Schema { get; [param: CanBeNull] set; } /// /// The table to which the constraint should be added. /// - public virtual string Table { get; [param: NotNull] set; } + public virtual string Table { get; [param: NotNull] set; } = null!; /// /// The name of the constraint. /// - public virtual string Name { get; [param: NotNull] set; } + public virtual string Name { get; [param: NotNull] set; } = null!; /// /// The ordered-list of column names for the columns that make up the constraint. /// - public virtual string[] Columns { get; [param: NotNull] set; } + public virtual string[] Columns { get; [param: NotNull] set; } = null!; /// /// Creates a new from the specified unique constraint. diff --git a/src/EFCore.Relational/Migrations/Operations/AlterColumnOperation.cs b/src/EFCore.Relational/Migrations/Operations/AlterColumnOperation.cs index cbe2b5c18ce..146b59b248e 100644 --- a/src/EFCore.Relational/Migrations/Operations/AlterColumnOperation.cs +++ b/src/EFCore.Relational/Migrations/Operations/AlterColumnOperation.cs @@ -5,6 +5,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Metadata; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Migrations.Operations { /// diff --git a/src/EFCore.Relational/Migrations/Operations/AlterDatabaseOperation.cs b/src/EFCore.Relational/Migrations/Operations/AlterDatabaseOperation.cs index 06788b549ad..6176e15e07e 100644 --- a/src/EFCore.Relational/Migrations/Operations/AlterDatabaseOperation.cs +++ b/src/EFCore.Relational/Migrations/Operations/AlterDatabaseOperation.cs @@ -4,6 +4,8 @@ using System.Diagnostics; using Microsoft.EntityFrameworkCore.Metadata; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Migrations.Operations { /// diff --git a/src/EFCore.Relational/Migrations/Operations/AlterSequenceOperation.cs b/src/EFCore.Relational/Migrations/Operations/AlterSequenceOperation.cs index 426744b2095..91a128dca7c 100644 --- a/src/EFCore.Relational/Migrations/Operations/AlterSequenceOperation.cs +++ b/src/EFCore.Relational/Migrations/Operations/AlterSequenceOperation.cs @@ -5,6 +5,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Metadata; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Migrations.Operations { /// @@ -16,12 +18,12 @@ public class AlterSequenceOperation : SequenceOperation, IAlterMigrationOperatio /// /// The schema that contains the sequence, or if the default schema should be used. /// - public virtual string Schema { get; [param: CanBeNull] set; } + public virtual string? Schema { get; [param: CanBeNull] set; } /// /// The name of the sequence. /// - public virtual string Name { get; [param: NotNull] set; } + public virtual string Name { get; [param: NotNull] set; } = null!; /// /// An operation representing the sequence as it was before being altered. diff --git a/src/EFCore.Relational/Migrations/Operations/AlterTableOperation.cs b/src/EFCore.Relational/Migrations/Operations/AlterTableOperation.cs index 93b0fe155f3..ddc1e79dc99 100644 --- a/src/EFCore.Relational/Migrations/Operations/AlterTableOperation.cs +++ b/src/EFCore.Relational/Migrations/Operations/AlterTableOperation.cs @@ -5,6 +5,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Metadata; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Migrations.Operations { /// diff --git a/src/EFCore.Relational/Migrations/Operations/Builders/AlterOperationBuilder.cs b/src/EFCore.Relational/Migrations/Operations/Builders/AlterOperationBuilder.cs index 49797b7b31d..69339918499 100644 --- a/src/EFCore.Relational/Migrations/Operations/Builders/AlterOperationBuilder.cs +++ b/src/EFCore.Relational/Migrations/Operations/Builders/AlterOperationBuilder.cs @@ -4,6 +4,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Migrations.Operations.Builders { /// diff --git a/src/EFCore.Relational/Migrations/Operations/Builders/ColumnsBuilder.cs b/src/EFCore.Relational/Migrations/Operations/Builders/ColumnsBuilder.cs index 04f6d8b654d..3eb6335519d 100644 --- a/src/EFCore.Relational/Migrations/Operations/Builders/ColumnsBuilder.cs +++ b/src/EFCore.Relational/Migrations/Operations/Builders/ColumnsBuilder.cs @@ -5,6 +5,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Migrations.Operations.Builders { /// @@ -51,18 +53,18 @@ public ColumnsBuilder([NotNull] CreateTableOperation createTableOperation) /// Whether the value of the computed column is stored in the database or not. /// The same builder so that multiple calls can be chained. public virtual OperationBuilder Column( - [CanBeNull] string type = null, + [CanBeNull] string? type = null, bool? unicode = null, int? maxLength = null, bool rowVersion = false, - [CanBeNull] string name = null, + [CanBeNull] string? name = null, bool nullable = false, - [CanBeNull] object defaultValue = null, - [CanBeNull] string defaultValueSql = null, - [CanBeNull] string computedColumnSql = null, + [CanBeNull] object? defaultValue = null, + [CanBeNull] string? defaultValueSql = null, + [CanBeNull] string? computedColumnSql = null, bool? fixedLength = null, - [CanBeNull] string comment = null, - [CanBeNull] string collation = null, + [CanBeNull] string? comment = null, + [CanBeNull] string? collation = null, int? precision = null, int? scale = null, bool? stored = null) @@ -71,7 +73,7 @@ public virtual OperationBuilder Column( { Schema = _createTableOperation.Schema, Table = _createTableOperation.Name, - Name = name, + Name = name!, ClrType = typeof(T), ColumnType = type, IsUnicode = unicode, @@ -101,7 +103,7 @@ public virtual OperationBuilder Column( /// A string that represents the current object. [EditorBrowsable(EditorBrowsableState.Never)] public override string ToString() - => base.ToString(); + => base.ToString()!; /// /// Determines whether the specified object is equal to the current object. @@ -109,7 +111,7 @@ public override string ToString() /// The object to compare with the current object. /// if the specified object is equal to the current object; otherwise, . [EditorBrowsable(EditorBrowsableState.Never)] - public override bool Equals(object obj) + public override bool Equals(object? obj) => base.Equals(obj); /// diff --git a/src/EFCore.Relational/Migrations/Operations/Builders/CreateTableBuilder.cs b/src/EFCore.Relational/Migrations/Operations/Builders/CreateTableBuilder.cs index a7493eb0cb3..6aacaac805d 100644 --- a/src/EFCore.Relational/Migrations/Operations/Builders/CreateTableBuilder.cs +++ b/src/EFCore.Relational/Migrations/Operations/Builders/CreateTableBuilder.cs @@ -10,6 +10,8 @@ using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Migrations.Operations.Builders { /// @@ -52,7 +54,7 @@ public virtual OperationBuilder ForeignKey( [NotNull] Expression> column, [NotNull] string principalTable, [NotNull] string principalColumn, - [CanBeNull] string principalSchema = null, + [CanBeNull] string? principalSchema = null, ReferentialAction onUpdate = ReferentialAction.NoAction, ReferentialAction onDelete = ReferentialAction.NoAction) => ForeignKey( @@ -80,7 +82,7 @@ public virtual OperationBuilder ForeignKey( [NotNull] Expression> columns, [NotNull] string principalTable, [NotNull] string[] principalColumns, - [CanBeNull] string principalSchema = null, + [CanBeNull] string? principalSchema = null, ReferentialAction onUpdate = ReferentialAction.NoAction, ReferentialAction onDelete = ReferentialAction.NoAction) { diff --git a/src/EFCore.Relational/Migrations/Operations/Builders/OperationBuilder.cs b/src/EFCore.Relational/Migrations/Operations/Builders/OperationBuilder.cs index 5d934d34b3a..dccbb448df1 100644 --- a/src/EFCore.Relational/Migrations/Operations/Builders/OperationBuilder.cs +++ b/src/EFCore.Relational/Migrations/Operations/Builders/OperationBuilder.cs @@ -6,6 +6,8 @@ using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Migrations.Operations.Builders { /// @@ -60,7 +62,7 @@ public virtual OperationBuilder Annotation( /// A string that represents the current object. [EditorBrowsable(EditorBrowsableState.Never)] public override string ToString() - => base.ToString(); + => base.ToString()!; /// /// Determines whether the specified object is equal to the current object. @@ -68,7 +70,7 @@ public override string ToString() /// The object to compare with the current object. /// if the specified object is equal to the current object; otherwise, . [EditorBrowsable(EditorBrowsableState.Never)] - public override bool Equals(object obj) + public override bool Equals(object? obj) => base.Equals(obj); /// diff --git a/src/EFCore.Relational/Migrations/Operations/ColumnOperation.cs b/src/EFCore.Relational/Migrations/Operations/ColumnOperation.cs index 96c147f6952..7c11daaabab 100644 --- a/src/EFCore.Relational/Migrations/Operations/ColumnOperation.cs +++ b/src/EFCore.Relational/Migrations/Operations/ColumnOperation.cs @@ -4,6 +4,8 @@ using System; using JetBrains.Annotations; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Migrations.Operations { /// @@ -15,27 +17,27 @@ public abstract class ColumnOperation : MigrationOperation, ITableMigrationOpera /// /// The name of the column. /// - public virtual string Name { get; [param: NotNull] set; } + public virtual string Name { get; [param: NotNull] set; } = null!; /// /// The schema that contains the table, or if the default schema should be used. /// - public virtual string Schema { get; [param: CanBeNull] set; } + public virtual string? Schema { get; [param: CanBeNull] set; } /// /// The table which contains the column. /// - public virtual string Table { get; [param: NotNull] set; } + public virtual string Table { get; [param: NotNull] set; } = null!; /// /// The CLR of the property or properties mapped to the column. /// - public virtual Type ClrType { get; [param: NotNull] set; } + public virtual Type ClrType { get; [param: NotNull] set; } = null!; /// /// The store type of the column--for example, 'nvarchar(max)'. /// - public virtual string ColumnType { get; [param: CanBeNull] set; } + public virtual string? ColumnType { get; [param: CanBeNull] set; } /// /// Indicates whether or not the column can contain Unicode data, or if this is not specified or does @@ -81,19 +83,19 @@ public abstract class ColumnOperation : MigrationOperation, ITableMigrationOpera /// The default value for rows inserted without an explicit value for this column, or /// if there is no default. /// - public virtual object DefaultValue { get; [param: CanBeNull] set; } + public virtual object? DefaultValue { get; [param: CanBeNull] set; } /// /// The SQL expression to use as the default constraint when creating the column, /// or if there is no default constraint. /// - public virtual string DefaultValueSql { get; [param: CanBeNull] set; } + public virtual string? DefaultValueSql { get; [param: CanBeNull] set; } /// /// The SQL expression to use to compute the column value, if the column /// is not computed. /// - 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 @@ -104,11 +106,11 @@ public abstract class ColumnOperation : MigrationOperation, ITableMigrationOpera /// /// Comment for this column /// - public virtual string Comment { get; [param: CanBeNull] set; } + public virtual string? Comment { get; [param: CanBeNull] set; } /// /// The collation for this column, or if one hasn't been explicitly configured. /// - public virtual string Collation { get; [param: CanBeNull] set; } + public virtual string? Collation { get; [param: CanBeNull] set; } } } diff --git a/src/EFCore.Relational/Migrations/Operations/CreateIndexOperation.cs b/src/EFCore.Relational/Migrations/Operations/CreateIndexOperation.cs index 60e31c06861..3d4aac9c47b 100644 --- a/src/EFCore.Relational/Migrations/Operations/CreateIndexOperation.cs +++ b/src/EFCore.Relational/Migrations/Operations/CreateIndexOperation.cs @@ -1,12 +1,15 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using System.Diagnostics; using System.Linq; using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Migrations.Operations { /// @@ -23,27 +26,27 @@ public class CreateIndexOperation : MigrationOperation, ITableMigrationOperation /// /// The name of the index. /// - public virtual string Name { get; [param: NotNull] set; } + public virtual string Name { get; [param: NotNull] set; } = null!; /// /// The schema that contains the index, or if the default schema should be used. /// - public virtual string Schema { get; [param: CanBeNull] set; } + public virtual string? Schema { get; [param: CanBeNull] set; } /// /// The table that contains the index. /// - public virtual string Table { get; [param: NotNull] set; } + public virtual string Table { get; [param: NotNull] set; } = null!; /// /// The ordered list of column names for the column that make up the index. /// - public virtual string[] Columns { get; [param: NotNull] set; } + public virtual string[] Columns { get; [param: NotNull] set; } = null!; /// /// An expression to use as the index filter. /// - public virtual string Filter { get; [param: CanBeNull] set; } + public virtual string? Filter { get; [param: CanBeNull] set; } /// /// Creates a new from the specified index. diff --git a/src/EFCore.Relational/Migrations/Operations/CreateSequenceOperation.cs b/src/EFCore.Relational/Migrations/Operations/CreateSequenceOperation.cs index 53f1924bbd9..c6cac107a44 100644 --- a/src/EFCore.Relational/Migrations/Operations/CreateSequenceOperation.cs +++ b/src/EFCore.Relational/Migrations/Operations/CreateSequenceOperation.cs @@ -5,6 +5,8 @@ using System.Diagnostics; using JetBrains.Annotations; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Migrations.Operations { /// @@ -16,17 +18,17 @@ public class CreateSequenceOperation : SequenceOperation /// /// The schema that contains the sequence, or if the default schema should be used. /// - public virtual string Schema { get; [param: CanBeNull] set; } + public virtual string? Schema { get; [param: CanBeNull] set; } /// /// The name of the sequence. /// - public virtual string Name { get; [param: NotNull] set; } + public virtual string Name { get; [param: NotNull] set; } = null!; /// /// The CLR of values returned from the sequence. /// - public virtual Type ClrType { get; [param: NotNull] set; } + public virtual Type ClrType { get; [param: NotNull] set; } = null!; /// /// The value at which the sequence will start counting, defaulting to 1. diff --git a/src/EFCore.Relational/Migrations/Operations/CreateTableOperation.cs b/src/EFCore.Relational/Migrations/Operations/CreateTableOperation.cs index f14d7405e71..17caf093ae3 100644 --- a/src/EFCore.Relational/Migrations/Operations/CreateTableOperation.cs +++ b/src/EFCore.Relational/Migrations/Operations/CreateTableOperation.cs @@ -5,6 +5,8 @@ using System.Diagnostics; using JetBrains.Annotations; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Migrations.Operations { /// @@ -16,7 +18,7 @@ public class CreateTableOperation : TableOperation /// /// The representing the creation of the primary key for the table. /// - public virtual AddPrimaryKeyOperation PrimaryKey { get; [param: CanBeNull] set; } + public virtual AddPrimaryKeyOperation? PrimaryKey { get; [param: CanBeNull] set; } /// /// An ordered list of for adding columns to the table. diff --git a/src/EFCore.Relational/Migrations/Operations/DatabaseOperation.cs b/src/EFCore.Relational/Migrations/Operations/DatabaseOperation.cs index 2e873777d6f..d1fd67a6e00 100644 --- a/src/EFCore.Relational/Migrations/Operations/DatabaseOperation.cs +++ b/src/EFCore.Relational/Migrations/Operations/DatabaseOperation.cs @@ -3,6 +3,8 @@ using JetBrains.Annotations; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Migrations.Operations { /// @@ -14,6 +16,6 @@ public abstract class DatabaseOperation : MigrationOperation /// /// The collation for the database, or to use the default collation of the instance of SQL Server. /// - public virtual string Collation { get; [param: CanBeNull] set; } + public virtual string? Collation { get; [param: CanBeNull] set; } } } diff --git a/src/EFCore.Relational/Migrations/Operations/DeleteDataOperation.cs b/src/EFCore.Relational/Migrations/Operations/DeleteDataOperation.cs index 3a06916fc13..c768a457101 100644 --- a/src/EFCore.Relational/Migrations/Operations/DeleteDataOperation.cs +++ b/src/EFCore.Relational/Migrations/Operations/DeleteDataOperation.cs @@ -10,6 +10,8 @@ using Microsoft.EntityFrameworkCore.Update; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Migrations.Operations { /// @@ -21,30 +23,30 @@ public class DeleteDataOperation : MigrationOperation, ITableMigrationOperation /// /// The table from which data will be deleted. /// - public virtual string Table { get; [param: NotNull] set; } + public virtual string Table { get; [param: NotNull] set; } = null!; /// /// The schema that contains the table, or if the default schema should be used. /// - public virtual string Schema { get; [param: CanBeNull] set; } + public virtual string? Schema { get; [param: CanBeNull] set; } /// /// A list of column names that represent the columns that will be used to identify /// the rows that should be deleted. /// - public virtual string[] KeyColumns { get; [param: NotNull] set; } + public virtual string[] KeyColumns { get; [param: NotNull] set; } = null!; /// /// A list of store types for the columns that will be used to identify /// the rows that should be deleted. /// - public virtual string[] KeyColumnTypes { get; [param: NotNull] set; } + public virtual string[]? KeyColumnTypes { get; [param: CanBeNull] set; } /// /// The rows to be deleted, represented as a list of key value arrays where each /// value in the array corresponds to a column in the property. /// - public virtual object[,] KeyValues { get; [param: NotNull] set; } + public virtual object?[,] KeyValues { get; [param: NotNull] set; } = null!; /// /// Generates the commands that correspond to this operation. diff --git a/src/EFCore.Relational/Migrations/Operations/DropCheckConstraintOperation.cs b/src/EFCore.Relational/Migrations/Operations/DropCheckConstraintOperation.cs index 49b4a7dfbaf..740be4e21f9 100644 --- a/src/EFCore.Relational/Migrations/Operations/DropCheckConstraintOperation.cs +++ b/src/EFCore.Relational/Migrations/Operations/DropCheckConstraintOperation.cs @@ -4,6 +4,8 @@ using System.Diagnostics; using JetBrains.Annotations; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Migrations.Operations { /// @@ -15,16 +17,16 @@ public class DropCheckConstraintOperation : MigrationOperation, ITableMigrationO /// /// The name of the constraint. /// - public virtual string Name { get; [param: NotNull] set; } + public virtual string Name { get; [param: NotNull] set; } = null!; /// /// The schema that contains the table, or if the default schema should be used. /// - public virtual string Schema { get; [param: CanBeNull] set; } + public virtual string? Schema { get; [param: CanBeNull] set; } /// /// The table that contains the constraint. /// - public virtual string Table { get; [param: NotNull] set; } + public virtual string Table { get; [param: NotNull] set; } = null!; } } diff --git a/src/EFCore.Relational/Migrations/Operations/DropColumnOperation.cs b/src/EFCore.Relational/Migrations/Operations/DropColumnOperation.cs index 0e34977afb7..56bf1b13924 100644 --- a/src/EFCore.Relational/Migrations/Operations/DropColumnOperation.cs +++ b/src/EFCore.Relational/Migrations/Operations/DropColumnOperation.cs @@ -4,6 +4,8 @@ using System.Diagnostics; using JetBrains.Annotations; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Migrations.Operations { /// @@ -22,16 +24,16 @@ public DropColumnOperation() /// /// The name of the column. /// - public virtual string Name { get; [param: NotNull] set; } + public virtual string Name { get; [param: NotNull] set; } = null!; /// /// The schema that contains the table, or if the default schema should be used. /// - public virtual string Schema { get; [param: CanBeNull] set; } + public virtual string? Schema { get; [param: CanBeNull] set; } /// /// The table that contains that column. /// - public virtual string Table { get; [param: NotNull] set; } + public virtual string Table { get; [param: NotNull] set; } = null!; } } diff --git a/src/EFCore.Relational/Migrations/Operations/DropForeignKeyOperation.cs b/src/EFCore.Relational/Migrations/Operations/DropForeignKeyOperation.cs index 76152506c83..59c42af7825 100644 --- a/src/EFCore.Relational/Migrations/Operations/DropForeignKeyOperation.cs +++ b/src/EFCore.Relational/Migrations/Operations/DropForeignKeyOperation.cs @@ -4,6 +4,8 @@ using System.Diagnostics; using JetBrains.Annotations; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Migrations.Operations { /// @@ -15,16 +17,16 @@ public class DropForeignKeyOperation : MigrationOperation, ITableMigrationOperat /// /// The name of the foreign key constraint. /// - public virtual string Name { get; [param: NotNull] set; } + public virtual string Name { get; [param: NotNull] set; } = null!; /// /// The schema that contains the table, or if the default schema should be used. /// - public virtual string Schema { get; [param: CanBeNull] set; } + public virtual string? Schema { get; [param: CanBeNull] set; } /// /// The table that contains the foreign key constraint. /// - public virtual string Table { get; [param: NotNull] set; } + public virtual string Table { get; [param: NotNull] set; } = null!; } } diff --git a/src/EFCore.Relational/Migrations/Operations/DropIndexOperation.cs b/src/EFCore.Relational/Migrations/Operations/DropIndexOperation.cs index 8f2821faed5..f6982d1c42d 100644 --- a/src/EFCore.Relational/Migrations/Operations/DropIndexOperation.cs +++ b/src/EFCore.Relational/Migrations/Operations/DropIndexOperation.cs @@ -4,27 +4,29 @@ using System.Diagnostics; using JetBrains.Annotations; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Migrations.Operations { /// /// A for dropping an existing index. /// [DebuggerDisplay("DROP INDEX {Name}")] - public class DropIndexOperation : MigrationOperation, ITableMigrationOperation + public class DropIndexOperation : MigrationOperation { /// /// The name of the index. /// - public virtual string Name { get; [param: NotNull] set; } + public virtual string Name { get; [param: NotNull] set; } = null!; /// /// The schema that contains the table, or if the default schema should be used. /// - public virtual string Schema { get; [param: CanBeNull] set; } + public virtual string? Schema { get; [param: CanBeNull] set; } /// /// The table that contains the index. /// - public virtual string Table { get; [param: CanBeNull] set; } + public virtual string? Table { get; [param: CanBeNull] set; } } } diff --git a/src/EFCore.Relational/Migrations/Operations/DropPrimaryKeyOperation.cs b/src/EFCore.Relational/Migrations/Operations/DropPrimaryKeyOperation.cs index 09c110c3047..eb6aa7c9333 100644 --- a/src/EFCore.Relational/Migrations/Operations/DropPrimaryKeyOperation.cs +++ b/src/EFCore.Relational/Migrations/Operations/DropPrimaryKeyOperation.cs @@ -4,6 +4,8 @@ using System.Diagnostics; using JetBrains.Annotations; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Migrations.Operations { /// @@ -15,16 +17,16 @@ public class DropPrimaryKeyOperation : MigrationOperation, ITableMigrationOperat /// /// The name of the primary key constraint. /// - public virtual string Name { get; [param: NotNull] set; } + public virtual string Name { get; [param: NotNull] set; } = null!; /// /// The schema that contains the table, or if the default schema should be used. /// - public virtual string Schema { get; [param: CanBeNull] set; } + public virtual string? Schema { get; [param: CanBeNull] set; } /// /// The table that contains the primary key. /// - public virtual string Table { get; [param: NotNull] set; } + public virtual string Table { get; [param: NotNull] set; } = null!; } } diff --git a/src/EFCore.Relational/Migrations/Operations/DropSchemaOperation.cs b/src/EFCore.Relational/Migrations/Operations/DropSchemaOperation.cs index fd368c3a538..8435733c47c 100644 --- a/src/EFCore.Relational/Migrations/Operations/DropSchemaOperation.cs +++ b/src/EFCore.Relational/Migrations/Operations/DropSchemaOperation.cs @@ -4,6 +4,8 @@ using System.Diagnostics; using JetBrains.Annotations; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Migrations.Operations { /// @@ -15,6 +17,6 @@ public class DropSchemaOperation : MigrationOperation /// /// The name of the schema. /// - public virtual string Name { get; [param: NotNull] set; } + public virtual string Name { get; [param: NotNull] set; } = null!; } } diff --git a/src/EFCore.Relational/Migrations/Operations/DropSequenceOperation.cs b/src/EFCore.Relational/Migrations/Operations/DropSequenceOperation.cs index 9a453eb1483..1ee025b37c1 100644 --- a/src/EFCore.Relational/Migrations/Operations/DropSequenceOperation.cs +++ b/src/EFCore.Relational/Migrations/Operations/DropSequenceOperation.cs @@ -4,6 +4,8 @@ using System.Diagnostics; using JetBrains.Annotations; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Migrations.Operations { /// @@ -15,11 +17,11 @@ public class DropSequenceOperation : MigrationOperation /// /// The name of the sequence. /// - public virtual string Name { get; [param: NotNull] set; } + public virtual string Name { get; [param: NotNull] set; } = null!; /// /// The schema that contains the sequence, or if the default schema should be used. /// - public virtual string Schema { get; [param: CanBeNull] set; } + public virtual string? Schema { get; [param: CanBeNull] set; } } } diff --git a/src/EFCore.Relational/Migrations/Operations/DropTableOperation.cs b/src/EFCore.Relational/Migrations/Operations/DropTableOperation.cs index b67dc4610b2..f90d4ef93a0 100644 --- a/src/EFCore.Relational/Migrations/Operations/DropTableOperation.cs +++ b/src/EFCore.Relational/Migrations/Operations/DropTableOperation.cs @@ -4,6 +4,8 @@ using System.Diagnostics; using JetBrains.Annotations; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Migrations.Operations { /// @@ -22,12 +24,12 @@ public DropTableOperation() /// /// The name of the table. /// - public virtual string Name { get; [param: NotNull] set; } + public virtual string Name { get; [param: NotNull] set; } = null!; /// /// The schema that contains the table, or if the default schema should be used. /// - public virtual string Schema { get; [param: CanBeNull] set; } + public virtual string? Schema { get; [param: CanBeNull] set; } /// string ITableMigrationOperation.Table diff --git a/src/EFCore.Relational/Migrations/Operations/DropUniqueConstraintOperation.cs b/src/EFCore.Relational/Migrations/Operations/DropUniqueConstraintOperation.cs index 0ed7580df67..ab6ee9c0d60 100644 --- a/src/EFCore.Relational/Migrations/Operations/DropUniqueConstraintOperation.cs +++ b/src/EFCore.Relational/Migrations/Operations/DropUniqueConstraintOperation.cs @@ -4,6 +4,8 @@ using System.Diagnostics; using JetBrains.Annotations; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Migrations.Operations { /// @@ -15,16 +17,16 @@ public class DropUniqueConstraintOperation : MigrationOperation, ITableMigration /// /// The name of the constraint. /// - public virtual string Name { get; [param: NotNull] set; } + public virtual string Name { get; [param: NotNull] set; } = null!; /// /// The schema that contains the table, or if the default schema should be used. /// - public virtual string Schema { get; [param: CanBeNull] set; } + public virtual string? Schema { get; [param: CanBeNull] set; } /// /// The table that contains the constraint. /// - public virtual string Table { get; [param: NotNull] set; } + public virtual string Table { get; [param: NotNull] set; } = null!; } } diff --git a/src/EFCore.Relational/Migrations/Operations/EnsureSchemaOperation.cs b/src/EFCore.Relational/Migrations/Operations/EnsureSchemaOperation.cs index 90a3992ca66..1e0f322534e 100644 --- a/src/EFCore.Relational/Migrations/Operations/EnsureSchemaOperation.cs +++ b/src/EFCore.Relational/Migrations/Operations/EnsureSchemaOperation.cs @@ -4,6 +4,8 @@ using System.Diagnostics; using JetBrains.Annotations; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Migrations.Operations { /// @@ -16,6 +18,6 @@ public class EnsureSchemaOperation : MigrationOperation /// /// The name of the schema. /// - public virtual string Name { get; [param: NotNull] set; } + public virtual string Name { get; [param: NotNull] set; } = null!; } } diff --git a/src/EFCore.Relational/Migrations/Operations/IAlterMigrationOperation.cs b/src/EFCore.Relational/Migrations/Operations/IAlterMigrationOperation.cs index ef45d6f4ad6..d054dc5e684 100644 --- a/src/EFCore.Relational/Migrations/Operations/IAlterMigrationOperation.cs +++ b/src/EFCore.Relational/Migrations/Operations/IAlterMigrationOperation.cs @@ -3,6 +3,8 @@ using Microsoft.EntityFrameworkCore.Metadata; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Migrations.Operations { /// diff --git a/src/EFCore.Relational/Migrations/Operations/ITableMigrationOperation.cs b/src/EFCore.Relational/Migrations/Operations/ITableMigrationOperation.cs index 31dece4caf2..a0a6ca6439e 100644 --- a/src/EFCore.Relational/Migrations/Operations/ITableMigrationOperation.cs +++ b/src/EFCore.Relational/Migrations/Operations/ITableMigrationOperation.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.Migrations.Operations { /// @@ -11,7 +13,7 @@ public interface ITableMigrationOperation /// /// The schema that contains the table, or if the default schema should be used. /// - string Schema { get; } + string? Schema { get; } /// /// The table that contains the target of this operation. diff --git a/src/EFCore.Relational/Migrations/Operations/InsertDataOperation.cs b/src/EFCore.Relational/Migrations/Operations/InsertDataOperation.cs index 1f5322d403c..e0afe622eec 100644 --- a/src/EFCore.Relational/Migrations/Operations/InsertDataOperation.cs +++ b/src/EFCore.Relational/Migrations/Operations/InsertDataOperation.cs @@ -10,6 +10,8 @@ using Microsoft.EntityFrameworkCore.Update; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Migrations.Operations { /// @@ -21,28 +23,28 @@ public class InsertDataOperation : MigrationOperation, ITableMigrationOperation /// /// The name of the table into which data will be inserted. /// - public virtual string Table { get; [param: NotNull] set; } + public virtual string Table { get; [param: NotNull] set; } = null!; /// /// The schema that contains the table, or if the default schema should be used. /// - public virtual string Schema { get; [param: CanBeNull] set; } + public virtual string? Schema { get; [param: CanBeNull] set; } /// /// A list of column names that represent the columns into which data will be inserted. /// - public virtual string[] Columns { get; [param: NotNull] set; } + public virtual string[] Columns { get; [param: NotNull] set; } = null!; /// /// A list of store types for the columns into which data will be inserted. /// - public virtual string[] ColumnTypes { get; [param: NotNull] set; } + public virtual string[]? ColumnTypes { get; [param: CanBeNull] set; } /// /// The data to be inserted, represented as a list of value arrays where each /// value in the array corresponds to a column in the property. /// - public virtual object[,] Values { get; [param: NotNull] set; } + public virtual object?[,] Values { get; [param: NotNull] set; } = null!; /// /// Generates the commands that correspond to this operation. diff --git a/src/EFCore.Relational/Migrations/Operations/MigrationOperation.cs b/src/EFCore.Relational/Migrations/Operations/MigrationOperation.cs index ca6b69f276f..1d912ca153c 100644 --- a/src/EFCore.Relational/Migrations/Operations/MigrationOperation.cs +++ b/src/EFCore.Relational/Migrations/Operations/MigrationOperation.cs @@ -3,6 +3,8 @@ using Microsoft.EntityFrameworkCore.Infrastructure; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Migrations.Operations { /// diff --git a/src/EFCore.Relational/Migrations/Operations/RenameColumnOperation.cs b/src/EFCore.Relational/Migrations/Operations/RenameColumnOperation.cs index e5ecaeebd73..4b1dd51f502 100644 --- a/src/EFCore.Relational/Migrations/Operations/RenameColumnOperation.cs +++ b/src/EFCore.Relational/Migrations/Operations/RenameColumnOperation.cs @@ -4,6 +4,8 @@ using System.Diagnostics; using JetBrains.Annotations; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Migrations.Operations { /// @@ -15,21 +17,21 @@ public class RenameColumnOperation : MigrationOperation, ITableMigrationOperatio /// /// The old name of the column. /// - public virtual string Name { get; [param: NotNull] set; } + public virtual string Name { get; [param: NotNull] set; } = null!; /// /// The schema that contains the table, or if the default schema should be used. /// - public virtual string Schema { get; [param: NotNull] set; } + public virtual string? Schema { get; [param: CanBeNull] set; } /// /// The name of the table that contains the column. /// - public virtual string Table { get; [param: CanBeNull] set; } + public virtual string Table { get; [param: NotNull] set; } = null!; /// /// The new name for the column. /// - public virtual string NewName { get; [param: NotNull] set; } + public virtual string NewName { get; [param: NotNull] set; } = null!; } } diff --git a/src/EFCore.Relational/Migrations/Operations/RenameIndexOperation.cs b/src/EFCore.Relational/Migrations/Operations/RenameIndexOperation.cs index 5d2a65e7651..798649976b8 100644 --- a/src/EFCore.Relational/Migrations/Operations/RenameIndexOperation.cs +++ b/src/EFCore.Relational/Migrations/Operations/RenameIndexOperation.cs @@ -4,32 +4,34 @@ using System.Diagnostics; using JetBrains.Annotations; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Migrations.Operations { /// /// A for renaming an existing index. /// [DebuggerDisplay("ALTER INDEX {Name} RENAME TO {NewName}")] - public class RenameIndexOperation : MigrationOperation, ITableMigrationOperation + public class RenameIndexOperation : MigrationOperation { /// /// The old name of the index. /// - public virtual string Name { get; [param: NotNull] set; } + public virtual string Name { get; [param: NotNull] set; } = null!; /// /// The new name for the index. /// - public virtual string NewName { get; [param: NotNull] set; } + public virtual string NewName { get; [param: NotNull] set; } = null!; /// /// The schema that contains the table, or if the default schema should be used. /// - public virtual string Schema { get; [param: CanBeNull] set; } + public virtual string? Schema { get; [param: CanBeNull] set; } /// /// The name of the table that contains the index. /// - public virtual string Table { get; [param: CanBeNull] set; } + public virtual string? Table { get; [param: CanBeNull] set; } } } diff --git a/src/EFCore.Relational/Migrations/Operations/RenameSequenceOperation.cs b/src/EFCore.Relational/Migrations/Operations/RenameSequenceOperation.cs index b63b2dc7800..05a8c8fc777 100644 --- a/src/EFCore.Relational/Migrations/Operations/RenameSequenceOperation.cs +++ b/src/EFCore.Relational/Migrations/Operations/RenameSequenceOperation.cs @@ -4,6 +4,8 @@ using System.Diagnostics; using JetBrains.Annotations; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Migrations.Operations { /// @@ -15,21 +17,21 @@ public class RenameSequenceOperation : MigrationOperation /// /// The old name of the sequence. /// - public virtual string Name { get; [param: NotNull] set; } + public virtual string Name { get; [param: NotNull] set; } = null!; /// /// The schema that contains the sequence, or if the default schema should be used. /// - public virtual string Schema { get; [param: CanBeNull] set; } + public virtual string? Schema { get; [param: CanBeNull] set; } /// /// The new sequence name or if only the schema has changed. /// - public virtual string NewName { get; [param: CanBeNull] set; } + public virtual string? NewName { get; [param: CanBeNull] set; } /// /// The new schema name or if only the name has changed. /// - public virtual string NewSchema { get; [param: CanBeNull] set; } + public virtual string? NewSchema { get; [param: CanBeNull] set; } } } diff --git a/src/EFCore.Relational/Migrations/Operations/RenameTableOperation.cs b/src/EFCore.Relational/Migrations/Operations/RenameTableOperation.cs index 05415587d5a..9167651e63f 100644 --- a/src/EFCore.Relational/Migrations/Operations/RenameTableOperation.cs +++ b/src/EFCore.Relational/Migrations/Operations/RenameTableOperation.cs @@ -4,6 +4,8 @@ using System.Diagnostics; using JetBrains.Annotations; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Migrations.Operations { /// @@ -15,22 +17,22 @@ public class RenameTableOperation : MigrationOperation, ITableMigrationOperation /// /// The schema that contains the table, or if the default schema should be used. /// - public virtual string Schema { get; [param: CanBeNull] set; } + public virtual string? Schema { get; [param: CanBeNull] set; } /// /// The old name of the table. /// - public virtual string Name { get; [param: NotNull] set; } + public virtual string Name { get; [param: NotNull] set; } = null!; /// - /// The new table name or if only the schema has changed. + /// The new schema name, or to use the default schema. /// - public virtual string NewSchema { get; [param: CanBeNull] set; } + public virtual string? NewSchema { get; [param: CanBeNull] set; } /// /// The new table name or if only the schema has changed. /// - public virtual string NewName { get; [param: CanBeNull] set; } + public virtual string? NewName { get; [param: CanBeNull] set; } /// string ITableMigrationOperation.Table diff --git a/src/EFCore.Relational/Migrations/Operations/RestartSequenceOperation.cs b/src/EFCore.Relational/Migrations/Operations/RestartSequenceOperation.cs index f000304fb33..79224c563f2 100644 --- a/src/EFCore.Relational/Migrations/Operations/RestartSequenceOperation.cs +++ b/src/EFCore.Relational/Migrations/Operations/RestartSequenceOperation.cs @@ -4,6 +4,8 @@ using System.Diagnostics; using JetBrains.Annotations; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Migrations.Operations { /// @@ -15,12 +17,12 @@ public class RestartSequenceOperation : MigrationOperation /// /// The name of the sequence. /// - public virtual string Name { get; [param: NotNull] set; } + public virtual string Name { get; [param: NotNull] set; } = null!; /// /// The schema that contains the sequence, or if the default schema should be used. /// - public virtual string Schema { get; [param: CanBeNull] set; } + public virtual string? Schema { get; [param: CanBeNull] set; } /// /// The value at which the sequence should re-start, defaulting to 1. diff --git a/src/EFCore.Relational/Migrations/Operations/SequenceOperation.cs b/src/EFCore.Relational/Migrations/Operations/SequenceOperation.cs index 87747772c08..7dec769e904 100644 --- a/src/EFCore.Relational/Migrations/Operations/SequenceOperation.cs +++ b/src/EFCore.Relational/Migrations/Operations/SequenceOperation.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.Migrations.Operations { /// diff --git a/src/EFCore.Relational/Migrations/Operations/SqlOperation.cs b/src/EFCore.Relational/Migrations/Operations/SqlOperation.cs index 03de5a72e05..660c0d56a9d 100644 --- a/src/EFCore.Relational/Migrations/Operations/SqlOperation.cs +++ b/src/EFCore.Relational/Migrations/Operations/SqlOperation.cs @@ -4,6 +4,8 @@ using System.Diagnostics; using JetBrains.Annotations; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Migrations.Operations { /// @@ -15,7 +17,7 @@ public class SqlOperation : MigrationOperation /// /// The SQL string to be executed to perform this operation. /// - public virtual string Sql { get; [param: NotNull] set; } + public virtual string Sql { get; [param: NotNull] set; } = null!; /// /// Indicates whether or not transactions will be suppressed while executing the SQL. diff --git a/src/EFCore.Relational/Migrations/Operations/TableOperation.cs b/src/EFCore.Relational/Migrations/Operations/TableOperation.cs index a1fcf71a15e..7b9f92e8595 100644 --- a/src/EFCore.Relational/Migrations/Operations/TableOperation.cs +++ b/src/EFCore.Relational/Migrations/Operations/TableOperation.cs @@ -3,6 +3,8 @@ using JetBrains.Annotations; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Migrations.Operations { /// @@ -14,17 +16,17 @@ public abstract class TableOperation : MigrationOperation, ITableMigrationOperat /// /// The name of the table. /// - public virtual string Name { get; [param: NotNull] set; } + public virtual string Name { get; [param: NotNull] set; } = null!; /// /// The schema that contains the table, or if the default schema should be used. /// - public virtual string Schema { get; [param: CanBeNull] set; } + public virtual string? Schema { get; [param: CanBeNull] set; } /// /// Comment for this table /// - public virtual string Comment { get; [param: CanBeNull] set; } + public virtual string? Comment { get; [param: CanBeNull] set; } /// string ITableMigrationOperation.Table diff --git a/src/EFCore.Relational/Migrations/Operations/UpdateDataOperation.cs b/src/EFCore.Relational/Migrations/Operations/UpdateDataOperation.cs index aa60705c20a..548919f5fb9 100644 --- a/src/EFCore.Relational/Migrations/Operations/UpdateDataOperation.cs +++ b/src/EFCore.Relational/Migrations/Operations/UpdateDataOperation.cs @@ -11,6 +11,8 @@ using Microsoft.EntityFrameworkCore.Update; using Microsoft.EntityFrameworkCore.Utilities; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Migrations.Operations { /// @@ -22,46 +24,46 @@ public class UpdateDataOperation : MigrationOperation, ITableMigrationOperation /// /// The name of the table in which data will be updated. /// - public virtual string Table { get; [param: NotNull] set; } + public virtual string Table { get; [param: NotNull] set; } = null!; /// /// The schema that contains the table, or if the default schema should be used. /// - public virtual string Schema { get; [param: CanBeNull] set; } + public virtual string? Schema { get; [param: CanBeNull] set; } /// /// A list of column names that represent the columns that will be used to identify /// the rows that should be updated. /// - public virtual string[] KeyColumns { get; [param: NotNull] set; } + public virtual string[] KeyColumns { get; [param: NotNull] set; } = null!; /// /// A list of store types for the columns that will be used to identify /// the rows that should be updated. /// - public virtual string[] KeyColumnTypes { get; [param: NotNull] set; } + public virtual string[]? KeyColumnTypes { get; [param: CanBeNull] set; } /// /// The rows to be updated, represented as a list of key value arrays where each /// value in the array corresponds to a column in the property. /// - public virtual object[,] KeyValues { get; [param: NotNull] set; } + public virtual object?[,] KeyValues { get; [param: NotNull] set; } = null!; /// /// A list of column names that represent the columns that contain data to be updated. /// - public virtual string[] Columns { get; [param: NotNull] set; } + public virtual string[] Columns { get; [param: NotNull] set; } = null!; /// /// A list of store types for the columns in which data will be updated. /// - public virtual string[] ColumnTypes { get; [param: NotNull] set; } + public virtual string[]? ColumnTypes { get; [param: CanBeNull] set; } /// /// The data to be updated, represented as a list of value arrays where each /// value in the array corresponds to a column in the property. /// - public virtual object[,] Values { get; [param: NotNull] set; } + public virtual object?[,] Values { get; [param: NotNull] set; } = null!; /// /// Generates the commands that correspond to this operation. diff --git a/src/EFCore.Relational/Migrations/ReferentialAction.cs b/src/EFCore.Relational/Migrations/ReferentialAction.cs index 49ab27f4f45..e8b38fcb40e 100644 --- a/src/EFCore.Relational/Migrations/ReferentialAction.cs +++ b/src/EFCore.Relational/Migrations/ReferentialAction.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.Migrations { /// diff --git a/src/EFCore.SqlServer/Extensions/SqlServerMigrationBuilderExtensions.cs b/src/EFCore.SqlServer/Extensions/SqlServerMigrationBuilderExtensions.cs index dde5965e112..1bd3420bbd0 100644 --- a/src/EFCore.SqlServer/Extensions/SqlServerMigrationBuilderExtensions.cs +++ b/src/EFCore.SqlServer/Extensions/SqlServerMigrationBuilderExtensions.cs @@ -5,6 +5,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.SqlServer.Infrastructure.Internal; +#nullable enable + // ReSharper disable once CheckNamespace namespace Microsoft.EntityFrameworkCore.Migrations { diff --git a/src/EFCore.SqlServer/Migrations/Internal/SqlServerHistoryRepository.cs b/src/EFCore.SqlServer/Migrations/Internal/SqlServerHistoryRepository.cs index d3ff87d4411..6191edd39a9 100644 --- a/src/EFCore.SqlServer/Migrations/Internal/SqlServerHistoryRepository.cs +++ b/src/EFCore.SqlServer/Migrations/Internal/SqlServerHistoryRepository.cs @@ -10,6 +10,8 @@ using Microsoft.EntityFrameworkCore.Utilities; using Microsoft.Extensions.DependencyInjection; +#nullable enable + namespace Microsoft.EntityFrameworkCore.SqlServer.Migrations.Internal { /// @@ -65,7 +67,7 @@ protected override string ExistsSql /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - protected override bool InterpretExistsResult(object value) + protected override bool InterpretExistsResult(object? value) => value != DBNull.Value; /// @@ -89,7 +91,7 @@ public override string GetCreateIfNotExistsScript() using (var reader = new StringReader(GetCreateScript())) { var first = true; - string line; + string? line; while ((line = reader.ReadLine()) != null) { if (first) diff --git a/src/EFCore.SqlServer/Migrations/Internal/SqlServerMigrationsAnnotationProvider.cs b/src/EFCore.SqlServer/Migrations/Internal/SqlServerMigrationsAnnotationProvider.cs index 76a0b5888a1..e766baf2f45 100644 --- a/src/EFCore.SqlServer/Migrations/Internal/SqlServerMigrationsAnnotationProvider.cs +++ b/src/EFCore.SqlServer/Migrations/Internal/SqlServerMigrationsAnnotationProvider.cs @@ -10,6 +10,8 @@ using Microsoft.EntityFrameworkCore.SqlServer.Metadata.Internal; using Microsoft.Extensions.DependencyInjection; +#nullable enable + namespace Microsoft.EntityFrameworkCore.SqlServer.Migrations.Internal { /// diff --git a/src/EFCore.SqlServer/Migrations/Operations/SqlServerCreateDatabaseOperation.cs b/src/EFCore.SqlServer/Migrations/Operations/SqlServerCreateDatabaseOperation.cs index 00f83e0ab4c..3d2b285a65c 100644 --- a/src/EFCore.SqlServer/Migrations/Operations/SqlServerCreateDatabaseOperation.cs +++ b/src/EFCore.SqlServer/Migrations/Operations/SqlServerCreateDatabaseOperation.cs @@ -4,6 +4,8 @@ using System.Diagnostics; using JetBrains.Annotations; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Migrations.Operations { /// @@ -15,11 +17,11 @@ public class SqlServerCreateDatabaseOperation : DatabaseOperation /// /// The name of the database. /// - public virtual string Name { get; [param: NotNull] set; } + public virtual string Name { get; [param: NotNull] set; } = null!; /// /// The filename to use for the database, or to let SQL Server choose. /// - public virtual string FileName { get; [param: CanBeNull] set; } + public virtual string? FileName { get; [param: CanBeNull] set; } } } diff --git a/src/EFCore.SqlServer/Migrations/Operations/SqlServerDropDatabaseOperation.cs b/src/EFCore.SqlServer/Migrations/Operations/SqlServerDropDatabaseOperation.cs index 2716c065d3d..e7826b96e88 100644 --- a/src/EFCore.SqlServer/Migrations/Operations/SqlServerDropDatabaseOperation.cs +++ b/src/EFCore.SqlServer/Migrations/Operations/SqlServerDropDatabaseOperation.cs @@ -3,6 +3,8 @@ using JetBrains.Annotations; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Migrations.Operations { /// @@ -13,6 +15,6 @@ public class SqlServerDropDatabaseOperation : MigrationOperation /// /// The name of the database. /// - public virtual string Name { get; [param: NotNull] set; } + public virtual string Name { get; [param: NotNull] set; } = null!; } } diff --git a/src/EFCore.SqlServer/Migrations/SqlServerMigrationsSqlGenerator.cs b/src/EFCore.SqlServer/Migrations/SqlServerMigrationsSqlGenerator.cs index 417cc968d7f..c5c9e6733f4 100644 --- a/src/EFCore.SqlServer/Migrations/SqlServerMigrationsSqlGenerator.cs +++ b/src/EFCore.SqlServer/Migrations/SqlServerMigrationsSqlGenerator.cs @@ -19,6 +19,8 @@ using Microsoft.EntityFrameworkCore.Utilities; using Microsoft.Extensions.DependencyInjection; +#nullable enable + // ReSharper disable once CheckNamespace namespace Microsoft.EntityFrameworkCore.Migrations { @@ -35,7 +37,7 @@ namespace Microsoft.EntityFrameworkCore.Migrations /// public class SqlServerMigrationsSqlGenerator : MigrationsSqlGenerator { - private IReadOnlyList _operations; + private IReadOnlyList _operations = null!; private int _variableCounter; /// @@ -59,7 +61,7 @@ public SqlServerMigrationsSqlGenerator( /// The list of commands to be executed or scripted. public override IReadOnlyList Generate( IReadOnlyList operations, - IModel model = null, + IModel? model = null, MigrationsSqlGenerationOptions options = MigrationsSqlGenerationOptions.Default) { _operations = operations; @@ -69,7 +71,7 @@ public override IReadOnlyList Generate( } finally { - _operations = null; + _operations = null!; } } @@ -88,7 +90,7 @@ public override IReadOnlyList Generate( /// The operation. /// The target model which may be if the operations exist without a model. /// The command builder to use to build the commands. - protected override void Generate(MigrationOperation operation, IModel model, MigrationCommandListBuilder builder) + protected override void Generate(MigrationOperation operation, IModel? model, MigrationCommandListBuilder builder) { Check.NotNull(operation, nameof(operation)); Check.NotNull(builder, nameof(builder)); @@ -108,7 +110,7 @@ protected override void Generate(MigrationOperation operation, IModel model, Mig } /// - protected override void Generate(AddCheckConstraintOperation operation, IModel model, MigrationCommandListBuilder builder) + protected override void Generate(AddCheckConstraintOperation operation, IModel? model, MigrationCommandListBuilder builder) => GenerateExecWhenIdempotent(builder, b => base.Generate(operation, model, b)); /// @@ -121,7 +123,7 @@ protected override void Generate(AddCheckConstraintOperation operation, IModel m /// Indicates whether or not to terminate the command after generating SQL for the operation. protected override void Generate( AddColumnOperation operation, - IModel model, + IModel? model, MigrationCommandListBuilder builder, bool terminate) { @@ -186,7 +188,7 @@ protected override void Generate( /// Indicates whether or not to terminate the command after generating SQL for the operation. protected override void Generate( AddForeignKeyOperation operation, - IModel model, + IModel? model, MigrationCommandListBuilder builder, bool terminate = true) { @@ -210,7 +212,7 @@ protected override void Generate( /// Indicates whether or not to terminate the command after generating SQL for the operation. protected override void Generate( AddPrimaryKeyOperation operation, - IModel model, + IModel? model, MigrationCommandListBuilder builder, bool terminate = true) { @@ -233,13 +235,13 @@ protected override void Generate( /// The command builder to use to build the commands. protected override void Generate( AlterColumnOperation operation, - IModel model, + IModel? model, MigrationCommandListBuilder builder) { Check.NotNull(operation, nameof(operation)); Check.NotNull(builder, nameof(builder)); - IEnumerable indexesToRebuild = null; + IEnumerable? indexesToRebuild = null; var column = model?.GetRelationalModel().FindTable(operation.Table, operation.Schema) ?.Columns.FirstOrDefault(c => c.Name == operation.Name); @@ -429,7 +431,7 @@ protected override void Generate( if (narrowed) { - CreateIndexes(indexesToRebuild, builder); + CreateIndexes(indexesToRebuild!, builder); } builder.EndCommand(suppressTransaction: IsMemoryOptimized(operation, model, operation.Schema, operation.Table)); @@ -444,7 +446,7 @@ protected override void Generate( /// The command builder to use to build the commands. protected override void Generate( RenameIndexOperation operation, - IModel model, + IModel? model, MigrationCommandListBuilder builder) { Check.NotNull(operation, nameof(operation)); @@ -472,7 +474,7 @@ protected override void Generate( /// The operation. /// The target model which may be if the operations exist without a model. /// The command builder to use to build the commands. - protected override void Generate(RenameSequenceOperation operation, IModel model, MigrationCommandListBuilder builder) + protected override void Generate(RenameSequenceOperation operation, IModel? model, MigrationCommandListBuilder builder) { Check.NotNull(operation, nameof(operation)); Check.NotNull(builder, nameof(builder)); @@ -508,7 +510,7 @@ protected override void Generate(RenameSequenceOperation operation, IModel model /// The command builder to use to build the commands. protected override void Generate( RestartSequenceOperation operation, - IModel model, + IModel? model, MigrationCommandListBuilder builder) { Check.NotNull(operation, nameof(operation)); @@ -534,7 +536,7 @@ protected override void Generate( /// Indicates whether or not to terminate the command after generating SQL for the operation. protected override void Generate( CreateTableOperation operation, - IModel model, + IModel? model, MigrationCommandListBuilder builder, bool terminate = true) { @@ -594,7 +596,7 @@ protected override void Generate( /// The command builder to use to build the commands. protected override void Generate( RenameTableOperation operation, - IModel model, + IModel? model, MigrationCommandListBuilder builder) { Check.NotNull(operation, nameof(operation)); @@ -632,7 +634,7 @@ protected override void Generate( /// Indicates whether or not to terminate the command after generating SQL for the operation. protected override void Generate( DropTableOperation operation, - IModel model, + IModel? model, MigrationCommandListBuilder builder, bool terminate = true) { @@ -656,7 +658,7 @@ protected override void Generate( /// Indicates whether or not to terminate the command after generating SQL for the operation. protected override void Generate( CreateIndexOperation operation, - IModel model, + IModel? model, MigrationCommandListBuilder builder, bool terminate = true) { @@ -763,7 +765,7 @@ protected override void Generate( /// Indicates whether or not to terminate the command after generating SQL for the operation. protected override void Generate( DropPrimaryKeyOperation operation, - IModel model, + IModel? model, MigrationCommandListBuilder builder, bool terminate = true) { @@ -784,7 +786,7 @@ protected override void Generate( /// The operation. /// The target model which may be if the operations exist without a model. /// The command builder to use to build the commands. - protected override void Generate(EnsureSchemaOperation operation, IModel model, MigrationCommandListBuilder builder) + protected override void Generate(EnsureSchemaOperation operation, IModel? model, MigrationCommandListBuilder builder) { Check.NotNull(operation, nameof(operation)); Check.NotNull(builder, nameof(builder)); @@ -819,7 +821,7 @@ protected override void Generate(EnsureSchemaOperation operation, IModel model, /// The command builder to use to build the commands. protected override void Generate( CreateSequenceOperation operation, - IModel model, + IModel? model, MigrationCommandListBuilder builder) { Check.NotNull(operation, nameof(operation)); @@ -858,7 +860,7 @@ protected override void Generate( /// The command builder to use to build the commands. protected virtual void Generate( [NotNull] SqlServerCreateDatabaseOperation operation, - [CanBeNull] IModel model, + [CanBeNull] IModel? model, [NotNull] MigrationCommandListBuilder builder) { Check.NotNull(operation, nameof(operation)); @@ -952,7 +954,7 @@ private static string ExpandFileName(string fileName) /// The command builder to use to build the commands. protected virtual void Generate( [NotNull] SqlServerDropDatabaseOperation operation, - [CanBeNull] IModel model, + [CanBeNull] IModel? model, [NotNull] MigrationCommandListBuilder builder) { Check.NotNull(operation, nameof(operation)); @@ -990,7 +992,7 @@ protected virtual void Generate( /// The command builder to use to build the commands. protected override void Generate( AlterDatabaseOperation operation, - IModel model, + IModel? model, MigrationCommandListBuilder builder) { Check.NotNull(operation, nameof(operation)); @@ -1012,9 +1014,16 @@ protected override void Generate( { builder .AppendLine("BEGIN") - .AppendLine("DECLARE @db_name nvarchar(max) = DB_NAME();") + .AppendLine("DECLARE @db_name nvarchar(max) = DB_NAME();"); + + if (operation.Collation == null) + { + builder.AppendLine("DECLARE @defaultCollation nvarchar(max) = CAST(SERVERPROPERTY('Collation') AS nvarchar(max));"); + } + + builder .Append("EXEC(N'ALTER DATABASE [' + @db_name + '] COLLATE ") - .Append(operation.Collation) + .Append(operation.Collation ?? "' + @defaultCollation + N'") .AppendLine(";');") .AppendLine("END") .AppendLine(); @@ -1110,7 +1119,7 @@ protected override void Generate( /// The operation. /// The target model which may be if the operations exist without a model. /// The command builder to use to build the commands. - protected override void Generate(AlterTableOperation operation, IModel model, MigrationCommandListBuilder builder) + protected override void Generate(AlterTableOperation operation, IModel? model, MigrationCommandListBuilder builder) { if (IsMemoryOptimized(operation) ^ IsMemoryOptimized(operation.OldTable)) @@ -1150,7 +1159,7 @@ protected override void Generate(AlterTableOperation operation, IModel model, Mi /// Indicates whether or not to terminate the command after generating SQL for the operation. protected override void Generate( DropForeignKeyOperation operation, - IModel model, + IModel? model, MigrationCommandListBuilder builder, bool terminate = true) { @@ -1174,19 +1183,24 @@ protected override void Generate( /// Indicates whether or not to terminate the command after generating SQL for the operation. protected override void Generate( DropIndexOperation operation, - IModel model, + IModel? model, MigrationCommandListBuilder builder, bool terminate) { Check.NotNull(operation, nameof(operation)); Check.NotNull(builder, nameof(builder)); + if (string.IsNullOrEmpty(operation.Table)) + { + throw new InvalidOperationException(SqlServerStrings.IndexTableRequired); + } + var memoryOptimized = IsMemoryOptimized(operation, model, operation.Schema, operation.Table); if (memoryOptimized) { builder .Append("ALTER TABLE ") - .Append(Dependencies.SqlGenerationHelper.DelimitIdentifier(operation.Table, operation.Schema)) + .Append(Dependencies.SqlGenerationHelper.DelimitIdentifier(operation.Table!, operation.Schema)) .Append(" DROP INDEX ") .Append(Dependencies.SqlGenerationHelper.DelimitIdentifier(operation.Name)); } @@ -1217,7 +1231,7 @@ protected override void Generate( /// Indicates whether or not to terminate the command after generating SQL for the operation. protected override void Generate( DropColumnOperation operation, - IModel model, + IModel? model, MigrationCommandListBuilder builder, bool terminate = true) { @@ -1244,7 +1258,7 @@ protected override void Generate( /// The command builder to use to build the commands. protected override void Generate( RenameColumnOperation operation, - IModel model, + IModel? model, MigrationCommandListBuilder builder) { Check.NotNull(operation, nameof(operation)); @@ -1267,7 +1281,7 @@ protected override void Generate( /// The operation. /// The target model which may be if the operations exist without a model. /// The command builder to use to build the commands. - protected override void Generate(SqlOperation operation, IModel model, MigrationCommandListBuilder builder) + protected override void Generate(SqlOperation operation, IModel? model, MigrationCommandListBuilder builder) { Check.NotNull(operation, nameof(operation)); Check.NotNull(builder, nameof(builder)); @@ -1328,7 +1342,7 @@ protected override void Generate(SqlOperation operation, IModel model, Migration /// Indicates whether or not to terminate the command after generating SQL for the operation. protected override void Generate( InsertDataOperation operation, - IModel model, + IModel? model, MigrationCommandListBuilder builder, bool terminate = true) { @@ -1389,11 +1403,11 @@ private void GenerateIdentityInsert(MigrationCommandListBuilder builder, InsertD } /// - protected override void Generate(DeleteDataOperation operation, IModel model, MigrationCommandListBuilder builder) + protected override void Generate(DeleteDataOperation operation, IModel? model, MigrationCommandListBuilder builder) => GenerateExecWhenIdempotent(builder, b => base.Generate(operation, model, b)); /// - protected override void Generate(UpdateDataOperation operation, IModel model, MigrationCommandListBuilder builder) + protected override void Generate(UpdateDataOperation operation, IModel? model, MigrationCommandListBuilder builder) => GenerateExecWhenIdempotent(builder, b => base.Generate(operation, model, b)); /// @@ -1405,10 +1419,10 @@ protected override void Generate(UpdateDataOperation operation, IModel model, Mi /// The target model which may be if the operations exist without a model. /// The command builder to use to add the SQL fragment. protected override void SequenceOptions( - string schema, + string? schema, string name, SequenceOperation operation, - IModel model, + IModel? model, MigrationCommandListBuilder builder) { Check.NotEmpty(name, nameof(name)); @@ -1454,11 +1468,11 @@ protected override void SequenceOptions( /// The target model which may be if the operations exist without a model. /// The command builder to use to add the SQL fragment. protected override void ColumnDefinition( - string schema, + string? schema, string table, string name, ColumnOperation operation, - IModel model, + IModel? model, MigrationCommandListBuilder builder) { Check.NotEmpty(name, nameof(name)); @@ -1472,7 +1486,7 @@ protected override void ColumnDefinition( return; } - var columnType = operation.ColumnType ?? GetColumnType(schema, table, name, operation, model); + var columnType = operation.ColumnType ?? GetColumnType(schema, table, name, operation, model)!; builder .Append(Dependencies.SqlGenerationHelper.DelimitIdentifier(name)) .Append(" ") @@ -1522,11 +1536,11 @@ protected override void ColumnDefinition( /// The target model which may be if the operations exist without a model. /// The command builder to use to add the SQL fragment. protected override void ComputedColumnDefinition( - string schema, + string? schema, string table, string name, ColumnOperation operation, - IModel model, + IModel? model, MigrationCommandListBuilder builder) { Check.NotEmpty(name, nameof(name)); @@ -1537,7 +1551,7 @@ protected override void ComputedColumnDefinition( builder .Append(" AS ") - .Append(operation.ComputedColumnSql); + .Append(operation.ComputedColumnSql!); if (operation.IsStored == true) { @@ -1574,7 +1588,7 @@ protected virtual void Rename( protected virtual void Rename( [NotNull] string name, [NotNull] string newName, - [CanBeNull] string type, + [CanBeNull] string? type, [NotNull] MigrationCommandListBuilder builder) { Check.NotEmpty(name, nameof(name)); @@ -1607,8 +1621,8 @@ protected virtual void Rename( /// The name of the item to transfer. /// The command builder to use to build the commands. protected virtual void Transfer( - [CanBeNull] string newSchema, - [CanBeNull] string schema, + [CanBeNull] string? newSchema, + [CanBeNull] string? schema, [NotNull] string name, [NotNull] MigrationCommandListBuilder builder) { @@ -1646,7 +1660,7 @@ protected virtual void Transfer( /// The operation. /// The target model which may be if the operations exist without a model. /// The command builder to use to add the SQL fragment. - protected override void IndexTraits(MigrationOperation operation, IModel model, MigrationCommandListBuilder builder) + protected override void IndexTraits(MigrationOperation operation, IModel? model, MigrationCommandListBuilder builder) { Check.NotNull(operation, nameof(operation)); Check.NotNull(builder, nameof(builder)); @@ -1664,7 +1678,7 @@ protected override void IndexTraits(MigrationOperation operation, IModel model, /// The operation. /// The target model which may be if the operations exist without a model. /// The command builder to use to add the SQL fragment. - protected override void IndexOptions(CreateIndexOperation operation, IModel model, MigrationCommandListBuilder builder) + protected override void IndexOptions(CreateIndexOperation operation, IModel? model, MigrationCommandListBuilder builder) { if (operation[SqlServerAnnotationNames.Include] is IReadOnlyList includeColumns && includeColumns.Count > 0) @@ -1738,7 +1752,7 @@ protected override void ForeignKeyAction(ReferentialAction referentialAction, Mi /// The column. /// The command builder to use to add the SQL fragment. protected virtual void DropDefaultConstraint( - [CanBeNull] string schema, + [CanBeNull] string? schema, [NotNull] string tableName, [NotNull] string columnName, [NotNull] MigrationCommandListBuilder builder) @@ -1789,7 +1803,7 @@ protected virtual void DropDefaultConstraint( /// The operation which may require a rebuild. /// The list of indexes affected. protected virtual IEnumerable GetIndexesToRebuild( - [CanBeNull] IColumn column, + [CanBeNull] IColumn? column, [NotNull] MigrationOperation currentOperation) { Check.NotNull(currentOperation, nameof(currentOperation)); @@ -1884,10 +1898,10 @@ protected virtual void CreateIndexes( /// protected virtual void AddDescription( [NotNull] MigrationCommandListBuilder builder, - [CanBeNull] string description, - [CanBeNull] string schema, + [CanBeNull] string? description, + [CanBeNull] string? schema, [NotNull] string table, - [CanBeNull] string column = null, + [CanBeNull] string? column = null, bool omitVariableDeclarations = false) { var stringTypeMapping = Dependencies.TypeMappingSource.GetMapping(typeof(string)); @@ -1936,7 +1950,7 @@ protected virtual void AddDescription( builder.AppendLine(Dependencies.SqlGenerationHelper.StatementTerminator); - string Literal(string s) + string Literal(string? s) => stringTypeMapping.GenerateSqlLiteral(s); } @@ -1954,9 +1968,9 @@ string Literal(string s) /// protected virtual void DropDescription( [NotNull] MigrationCommandListBuilder builder, - [CanBeNull] string schema, + [CanBeNull] string? schema, [NotNull] string table, - [CanBeNull] string column = null, + [CanBeNull] string? column = null, bool omitVariableDeclarations = false) { var stringTypeMapping = Dependencies.TypeMappingSource.GetMapping(typeof(string)); @@ -2010,13 +2024,13 @@ string Literal(string s) /// /// The target model. /// if a filter should be generated. - protected virtual bool UseLegacyIndexFilters([CanBeNull] IModel model) + protected virtual bool UseLegacyIndexFilters([CanBeNull] IModel? model) => !TryGetVersion(model, out var version) || VersionComparer.Compare(version, "2.0.0") < 0; private string IntegerConstant(long value) => string.Format(CultureInfo.InvariantCulture, "{0}", value); - private bool IsMemoryOptimized(Annotatable annotatable, IModel model, string schema, string tableName) + private bool IsMemoryOptimized(Annotatable annotatable, IModel? model, string? schema, string tableName) => annotatable[SqlServerAnnotationNames.MemoryOptimized] as bool? ?? model?.GetRelationalModel().FindTable(tableName, schema)?[SqlServerAnnotationNames.MemoryOptimized] as bool? == true; diff --git a/src/EFCore.SqlServer/Properties/SqlServerStrings.Designer.cs b/src/EFCore.SqlServer/Properties/SqlServerStrings.Designer.cs index cda31d33f13..3f310ff0f11 100644 --- a/src/EFCore.SqlServer/Properties/SqlServerStrings.Designer.cs +++ b/src/EFCore.SqlServer/Properties/SqlServerStrings.Designer.cs @@ -165,7 +165,7 @@ public static string IncompatibleTableMemoryOptimizedMismatch([CanBeNull] object table, entityType, otherEntityType, memoryOptimizedEntityType, nonMemoryOptimizedEntityType); /// - /// SQL Server requires the table name to be specified for rename index operations. Specify table name in the call to 'MigrationBuilder.RenameIndex'. + /// SQL Server requires the table name to be specified for index operations. Specify table name in calls to 'MigrationBuilder.RenameIndex' and 'DropIndex'. /// public static string IndexTableRequired => GetString("IndexTableRequired"); diff --git a/src/EFCore.SqlServer/Properties/SqlServerStrings.resx b/src/EFCore.SqlServer/Properties/SqlServerStrings.resx index e7d536dd503..4dfc644ac23 100644 --- a/src/EFCore.SqlServer/Properties/SqlServerStrings.resx +++ b/src/EFCore.SqlServer/Properties/SqlServerStrings.resx @@ -172,7 +172,7 @@ Cannot use table '{table}' for entity type '{entityType}' since it is being used for entity type '{otherEntityType}' and entity type '{memoryOptimizedEntityType}' is marked as memory-optimized, but entity type '{nonMemoryOptimizedEntityType}' is not. - SQL Server requires the table name to be specified for rename index operations. Specify table name in the call to 'MigrationBuilder.RenameIndex'. + SQL Server requires the table name to be specified for index operations. Specify table name in calls to 'MigrationBuilder.RenameIndex' and 'DropIndex'. The expression passed to the 'propertyReference' parameter of the 'FreeText' method is not a valid reference to a property. The expression must represent a reference to a full-text indexed property on the object referenced in the from clause: 'from e in context.Entities where EF.Functions.FreeText(e.SomeProperty, textToSearchFor) select e' diff --git a/src/EFCore.Sqlite.Core/Extensions/SqliteMigrationBuilderExtensions.cs b/src/EFCore.Sqlite.Core/Extensions/SqliteMigrationBuilderExtensions.cs index 1caef32905d..c012043e40a 100644 --- a/src/EFCore.Sqlite.Core/Extensions/SqliteMigrationBuilderExtensions.cs +++ b/src/EFCore.Sqlite.Core/Extensions/SqliteMigrationBuilderExtensions.cs @@ -5,6 +5,8 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Sqlite.Infrastructure.Internal; +#nullable enable + // ReSharper disable once CheckNamespace namespace Microsoft.EntityFrameworkCore.Migrations { diff --git a/src/EFCore.Sqlite.Core/Migrations/Internal/SqliteHistoryRepository.cs b/src/EFCore.Sqlite.Core/Migrations/Internal/SqliteHistoryRepository.cs index a8be9359ee5..eed2d646986 100644 --- a/src/EFCore.Sqlite.Core/Migrations/Internal/SqliteHistoryRepository.cs +++ b/src/EFCore.Sqlite.Core/Migrations/Internal/SqliteHistoryRepository.cs @@ -8,6 +8,8 @@ using Microsoft.EntityFrameworkCore.Storage; using Microsoft.Extensions.DependencyInjection; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Sqlite.Migrations.Internal { /// @@ -61,8 +63,8 @@ protected override string ExistsSql /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - protected override bool InterpretExistsResult(object value) - => (long)value != 0; + protected override bool InterpretExistsResult(object? value) + => (long)value! != 0L; /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to diff --git a/src/EFCore.Sqlite.Core/Migrations/SqliteMigrationsSqlGenerator.cs b/src/EFCore.Sqlite.Core/Migrations/SqliteMigrationsSqlGenerator.cs index 95932d3e502..8871ddb0589 100644 --- a/src/EFCore.Sqlite.Core/Migrations/SqliteMigrationsSqlGenerator.cs +++ b/src/EFCore.Sqlite.Core/Migrations/SqliteMigrationsSqlGenerator.cs @@ -17,6 +17,8 @@ using Microsoft.EntityFrameworkCore.Utilities; using Microsoft.Extensions.DependencyInjection; +#nullable enable + namespace Microsoft.EntityFrameworkCore.Migrations { /// @@ -57,7 +59,7 @@ public override IReadOnlyList Generate( MigrationsSqlGenerationOptions options = MigrationsSqlGenerationOptions.Default) => base.Generate(RewriteOperations(operations, model), model, options); - private bool IsSpatialiteColumn(AddColumnOperation operation, IModel model) + private bool IsSpatialiteColumn(AddColumnOperation operation, IModel? model) => SqliteTypeMappingSource.IsSpatialiteType( operation.ColumnType ?? GetColumnType( @@ -65,14 +67,14 @@ private bool IsSpatialiteColumn(AddColumnOperation operation, IModel model) operation.Table, operation.Name, operation, - model)); + model)!); private IReadOnlyList RewriteOperations( IReadOnlyList migrationOperations, IModel? model) { var operations = new List(); - var rebuilds = new Dictionary<(string Table, string Schema), RebuildContext>(); + var rebuilds = new Dictionary<(string Table, string? Schema), RebuildContext>(); foreach (var operation in migrationOperations) { switch (operation) @@ -155,8 +157,10 @@ private IReadOnlyList RewriteOperations( case RenameIndexOperation renameIndexOperation: { - var index = model?.GetRelationalModel().FindTable(renameIndexOperation.Table, renameIndexOperation.Schema) - ?.Indexes.FirstOrDefault(i => i.Name == renameIndexOperation.NewName); + var index = renameIndexOperation.Table != null + ? model?.GetRelationalModel().FindTable(renameIndexOperation.Table, renameIndexOperation.Schema) + ?.Indexes.FirstOrDefault(i => i.Name == renameIndexOperation.NewName) + : null; if (index != null) { operations.Add( @@ -216,7 +220,7 @@ private IReadOnlyList RewriteOperations( { if (rebuilds.Remove((renameTableOperation.Name, renameTableOperation.Schema), out var rebuild)) { - rebuilds.Add((renameTableOperation.NewName, renameTableOperation.NewSchema), rebuild); + rebuilds.Add((renameTableOperation.NewName ?? renameTableOperation.Name, renameTableOperation.NewSchema), rebuild); } operations.Add(renameTableOperation); @@ -269,7 +273,7 @@ private IReadOnlyList RewriteOperations( } } - var skippedRebuilds = new List<(string Table, string Schema)>(); + var skippedRebuilds = new List<(string Table, string? Schema)>(); var indexesToRebuild = new List(); foreach (var rebuild in rebuilds) { @@ -477,7 +481,7 @@ private IReadOnlyList RewriteOperations( /// The operation. /// The target model which may be if the operations exist without a model. /// The command builder to use to build the commands. - protected override void Generate(AlterDatabaseOperation operation, IModel model, MigrationCommandListBuilder builder) + protected override void Generate(AlterDatabaseOperation operation, IModel? model, MigrationCommandListBuilder builder) { if (operation[SqliteAnnotationNames.InitSpatialMetaData] as bool? != true || operation.OldDatabase[SqliteAnnotationNames.InitSpatialMetaData] as bool? == true) @@ -499,7 +503,7 @@ protected override void Generate(AlterDatabaseOperation operation, IModel model, /// The target model which may be if the operations exist without a model. /// The command builder to use to build the commands. /// Indicates whether or not to terminate the command after generating SQL for the operation. - protected override void Generate(AddColumnOperation operation, IModel model, MigrationCommandListBuilder builder, bool terminate) + protected override void Generate(AddColumnOperation operation, IModel? model, MigrationCommandListBuilder builder, bool terminate) { if (!IsSpatialiteColumn(operation, model)) { @@ -555,7 +559,7 @@ protected override void Generate(AddColumnOperation operation, IModel model, Mig /// Indicates whether or not to terminate the command after generating SQL for the operation. protected override void Generate( DropIndexOperation operation, - IModel model, + IModel? model, MigrationCommandListBuilder builder, bool terminate) { @@ -581,7 +585,7 @@ protected override void Generate( /// The operation. /// The target model which may be if the operations exist without a model. /// The command builder to use to build the commands. - protected override void Generate(RenameIndexOperation operation, IModel model, MigrationCommandListBuilder builder) + protected override void Generate(RenameIndexOperation operation, IModel? model, MigrationCommandListBuilder builder) => throw new NotSupportedException( SqliteStrings.InvalidMigrationOperation(operation.GetType().ShortDisplayName())); @@ -592,7 +596,7 @@ protected override void Generate(RenameIndexOperation operation, IModel model, M /// The operation. /// The target model which may be if the operations exist without a model. /// The command builder to use to build the commands. - protected override void Generate(RenameTableOperation operation, IModel model, MigrationCommandListBuilder builder) + protected override void Generate(RenameTableOperation operation, IModel? model, MigrationCommandListBuilder builder) { Check.NotNull(operation, nameof(operation)); Check.NotNull(builder, nameof(builder)); @@ -617,7 +621,7 @@ protected override void Generate(RenameTableOperation operation, IModel model, M /// The operation. /// The target model which may be if the operations exist without a model. /// The command builder to use to build the commands. - protected override void Generate(RenameColumnOperation operation, IModel model, MigrationCommandListBuilder builder) + protected override void Generate(RenameColumnOperation operation, IModel? model, MigrationCommandListBuilder builder) { Check.NotNull(operation, nameof(operation)); Check.NotNull(builder, nameof(builder)); @@ -643,7 +647,7 @@ protected override void Generate(RenameColumnOperation operation, IModel model, /// Indicates whether or not to terminate the command after generating SQL for the operation. protected override void Generate( CreateTableOperation operation, - IModel model, + IModel? model, MigrationCommandListBuilder builder, bool terminate = true) { @@ -724,7 +728,7 @@ protected override void Generate( /// The command builder to use to add the SQL fragment. protected override void CreateTableColumns( CreateTableOperation operation, - IModel model, + IModel? model, MigrationCommandListBuilder builder) { Check.NotNull(operation, nameof(operation)); @@ -742,7 +746,7 @@ protected override void CreateTableColumns( private void CreateTableColumnsWithComments( CreateTableOperation operation, - IModel model, + IModel? model, MigrationCommandListBuilder builder) { for (var i = 0; i < operation.Columns.Count; i++) @@ -778,11 +782,11 @@ private void CreateTableColumnsWithComments( /// The target model which may be if the operations exist without a model. /// The command builder to use to add the SQL fragment. protected override void ColumnDefinition( - string schema, + string? schema, string table, string name, ColumnOperation operation, - IModel model, + IModel? model, MigrationCommandListBuilder builder) { base.ColumnDefinition(schema, table, name, operation, model, builder); @@ -822,7 +826,7 @@ protected override void ColumnDefinition( /// Indicates whether or not to terminate the command after generating SQL for the operation. protected override void Generate( AddForeignKeyOperation operation, - IModel model, + IModel? model, MigrationCommandListBuilder builder, bool terminate = true) => throw new NotSupportedException( @@ -838,7 +842,7 @@ protected override void Generate( /// Indicates whether or not to terminate the command after generating SQL for the operation. protected override void Generate( AddPrimaryKeyOperation operation, - IModel model, + IModel? model, MigrationCommandListBuilder builder, bool terminate = true) => throw new NotSupportedException( @@ -851,7 +855,7 @@ protected override void Generate( /// The operation. /// The target model which may be if the operations exist without a model. /// The command builder to use to build the commands. - protected override void Generate(AddUniqueConstraintOperation operation, IModel model, MigrationCommandListBuilder builder) + protected override void Generate(AddUniqueConstraintOperation operation, IModel? model, MigrationCommandListBuilder builder) => throw new NotSupportedException( SqliteStrings.InvalidMigrationOperation(operation.GetType().ShortDisplayName())); @@ -862,7 +866,7 @@ protected override void Generate(AddUniqueConstraintOperation operation, IModel /// The operation. /// The target model which may be if the operations exist without a model. /// The command builder to use to build the commands. - protected override void Generate(AddCheckConstraintOperation operation, IModel model, MigrationCommandListBuilder builder) + protected override void Generate(AddCheckConstraintOperation operation, IModel? model, MigrationCommandListBuilder builder) => throw new NotSupportedException( SqliteStrings.InvalidMigrationOperation(operation.GetType().ShortDisplayName())); @@ -876,7 +880,7 @@ protected override void Generate(AddCheckConstraintOperation operation, IModel m /// Indicates whether or not to terminate the command after generating SQL for the operation. protected override void Generate( DropColumnOperation operation, - IModel model, + IModel? model, MigrationCommandListBuilder builder, bool terminate = true) => throw new NotSupportedException( @@ -892,7 +896,7 @@ protected override void Generate( /// Indicates whether or not to terminate the command after generating SQL for the operation. protected override void Generate( DropForeignKeyOperation operation, - IModel model, + IModel? model, MigrationCommandListBuilder builder, bool terminate = true) => throw new NotSupportedException( @@ -908,7 +912,7 @@ protected override void Generate( /// Indicates whether or not to terminate the command after generating SQL for the operation. protected override void Generate( DropPrimaryKeyOperation operation, - IModel model, + IModel? model, MigrationCommandListBuilder builder, bool terminate = true) => throw new NotSupportedException( @@ -921,7 +925,7 @@ protected override void Generate( /// The operation. /// The target model which may be if the operations exist without a model. /// The command builder to use to build the commands. - protected override void Generate(DropUniqueConstraintOperation operation, IModel model, MigrationCommandListBuilder builder) + protected override void Generate(DropUniqueConstraintOperation operation, IModel? model, MigrationCommandListBuilder builder) => throw new NotSupportedException( SqliteStrings.InvalidMigrationOperation(operation.GetType().ShortDisplayName())); @@ -932,7 +936,7 @@ protected override void Generate(DropUniqueConstraintOperation operation, IModel /// The operation. /// The target model which may be if the operations exist without a model. /// The command builder to use to build the commands. - protected override void Generate(DropCheckConstraintOperation operation, IModel model, MigrationCommandListBuilder builder) + protected override void Generate(DropCheckConstraintOperation operation, IModel? model, MigrationCommandListBuilder builder) => throw new NotSupportedException( SqliteStrings.InvalidMigrationOperation(operation.GetType().ShortDisplayName())); @@ -943,7 +947,7 @@ protected override void Generate(DropCheckConstraintOperation operation, IModel /// The operation. /// The target model which may be if the operations exist without a model. /// The command builder to use to build the commands. - protected override void Generate(AlterColumnOperation operation, IModel model, MigrationCommandListBuilder builder) + protected override void Generate(AlterColumnOperation operation, IModel? model, MigrationCommandListBuilder builder) => throw new NotSupportedException( SqliteStrings.InvalidMigrationOperation(operation.GetType().ShortDisplayName())); @@ -957,18 +961,18 @@ protected override void Generate(AlterColumnOperation operation, IModel model, M /// The target model which may be if the operations exist without a model. /// The command builder to use to add the SQL fragment. protected override void ComputedColumnDefinition( - string schema, + string? schema, string table, string name, ColumnOperation operation, - IModel model, + IModel? model, MigrationCommandListBuilder builder) { builder.Append(Dependencies.SqlGenerationHelper.DelimitIdentifier(name)); builder .Append(" AS (") - .Append(operation.ComputedColumnSql) + .Append(operation.ComputedColumnSql!) .Append(")"); if (operation.IsStored == true) @@ -994,7 +998,7 @@ protected override void ComputedColumnDefinition( /// The operation. /// The target model which may be if the operations exist without a model. /// The command builder to use to build the commands. - protected override void Generate(EnsureSchemaOperation operation, IModel model, MigrationCommandListBuilder builder) + protected override void Generate(EnsureSchemaOperation operation, IModel? model, MigrationCommandListBuilder builder) { } @@ -1004,7 +1008,7 @@ protected override void Generate(EnsureSchemaOperation operation, IModel model, /// The operation. /// The target model which may be if the operations exist without a model. /// The command builder to use to build the commands. - protected override void Generate(DropSchemaOperation operation, IModel model, MigrationCommandListBuilder builder) + protected override void Generate(DropSchemaOperation operation, IModel? model, MigrationCommandListBuilder builder) { } @@ -1018,7 +1022,7 @@ protected override void Generate(DropSchemaOperation operation, IModel model, Mi /// The operation. /// The target model which may be if the operations exist without a model. /// The command builder to use to build the commands. - protected override void Generate(RestartSequenceOperation operation, IModel model, MigrationCommandListBuilder builder) + protected override void Generate(RestartSequenceOperation operation, IModel? model, MigrationCommandListBuilder builder) => throw new NotSupportedException(SqliteStrings.SequencesNotSupported); /// @@ -1027,7 +1031,7 @@ protected override void Generate(RestartSequenceOperation operation, IModel mode /// The operation. /// The target model which may be if the operations exist without a model. /// The command builder to use to build the commands. - protected override void Generate(CreateSequenceOperation operation, IModel model, MigrationCommandListBuilder builder) + protected override void Generate(CreateSequenceOperation operation, IModel? model, MigrationCommandListBuilder builder) => throw new NotSupportedException(SqliteStrings.SequencesNotSupported); /// @@ -1036,7 +1040,7 @@ protected override void Generate(CreateSequenceOperation operation, IModel model /// The operation. /// The target model which may be if the operations exist without a model. /// The command builder to use to build the commands. - protected override void Generate(RenameSequenceOperation operation, IModel model, MigrationCommandListBuilder builder) + protected override void Generate(RenameSequenceOperation operation, IModel? model, MigrationCommandListBuilder builder) => throw new NotSupportedException(SqliteStrings.SequencesNotSupported); /// @@ -1045,7 +1049,7 @@ protected override void Generate(RenameSequenceOperation operation, IModel model /// The operation. /// The target model which may be if the operations exist without a model. /// The command builder to use to build the commands. - protected override void Generate(AlterSequenceOperation operation, IModel model, MigrationCommandListBuilder builder) + protected override void Generate(AlterSequenceOperation operation, IModel? model, MigrationCommandListBuilder builder) => throw new NotSupportedException(SqliteStrings.SequencesNotSupported); /// @@ -1054,7 +1058,7 @@ protected override void Generate(AlterSequenceOperation operation, IModel model, /// The operation. /// The target model which may be if the operations exist without a model. /// The command builder to use to build the commands. - protected override void Generate(DropSequenceOperation operation, IModel model, MigrationCommandListBuilder builder) + protected override void Generate(DropSequenceOperation operation, IModel? model, MigrationCommandListBuilder builder) => throw new NotSupportedException(SqliteStrings.SequencesNotSupported); #endregion diff --git a/test/EFCore.Relational.Tests/RelationalEventIdTest.cs b/test/EFCore.Relational.Tests/RelationalEventIdTest.cs index b383c0eb70d..3e45a72409c 100644 --- a/test/EFCore.Relational.Tests/RelationalEventIdTest.cs +++ b/test/EFCore.Relational.Tests/RelationalEventIdTest.cs @@ -120,6 +120,7 @@ private class FakeDbContext : DbContext { } + [Migration("00000000000000_FakeMigration")] private class FakeMigration : Migration { protected override void Up(MigrationBuilder migrationBuilder) diff --git a/test/EFCore.SqlServer.FunctionalTests/Migrations/SqlServerMigrationsSqlGeneratorTest.cs b/test/EFCore.SqlServer.FunctionalTests/Migrations/SqlServerMigrationsSqlGeneratorTest.cs index ec74184cbef..484ea65a49f 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Migrations/SqlServerMigrationsSqlGeneratorTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Migrations/SqlServerMigrationsSqlGeneratorTest.cs @@ -499,6 +499,29 @@ public virtual void AlterDatabaseOperation_collation() Sql); } + [ConditionalFact] + public virtual void AlterDatabaseOperation_collation_to_default() + { + Generate( + new AlterDatabaseOperation + { + Collation = null, + OldDatabase = + { + Collation = "SQL_Latin1_General_CP1_CI_AS" + } + }); + + AssertSql( + @"BEGIN +DECLARE @db_name nvarchar(max) = DB_NAME(); +DECLARE @defaultCollation nvarchar(max) = CAST(SERVERPROPERTY('Collation') AS nvarchar(max)); +EXEC(N'ALTER DATABASE [' + @db_name + '] COLLATE ' + @defaultCollation + N';'); +END + +"); + } + [ConditionalFact] public virtual void AlterDatabaseOperation_memory_optimized() { @@ -527,6 +550,20 @@ public virtual void DropDatabaseOperation() "); } + [ConditionalFact] + public virtual void DropIndexOperations_throws_when_no_table() + { + var migrationBuilder = new MigrationBuilder("SqlServer"); + + migrationBuilder.DropIndex( + name: "IX_Name"); + + var ex = Assert.Throws( + () => Generate(migrationBuilder.Operations.ToArray())); + + Assert.Equal(SqlServerStrings.IndexTableRequired, ex.Message); + } + [ConditionalFact] public virtual void MoveSequenceOperation_legacy() {