From f9b6d7cba1dc47c695b72b196c060141a6362ce7 Mon Sep 17 00:00:00 2001 From: lajones Date: Thu, 4 Jun 2020 15:47:43 -0700 Subject: [PATCH] Some missed NotNulls. --- .../Extensions/RelationalIndexExtensions.cs | 28 +++++++++---------- .../Metadata/Builders/EntityTypeBuilder.cs | 7 +++-- .../Metadata/Builders/EntityTypeBuilder`.cs | 4 +-- src/EFCore/Metadata/IConventionEntityType.cs | 2 +- src/EFCore/Metadata/Internal/EntityType.cs | 10 +++---- src/EFCore/Metadata/Internal/Index.cs | 28 ++++++++++--------- 6 files changed, 42 insertions(+), 37 deletions(-) diff --git a/src/EFCore.Relational/Extensions/RelationalIndexExtensions.cs b/src/EFCore.Relational/Extensions/RelationalIndexExtensions.cs index a36c7732a2d..8a1c4256e8c 100644 --- a/src/EFCore.Relational/Extensions/RelationalIndexExtensions.cs +++ b/src/EFCore.Relational/Extensions/RelationalIndexExtensions.cs @@ -19,31 +19,31 @@ namespace Microsoft.EntityFrameworkCore public static class RelationalIndexExtensions { /// - /// Returns the name of the index on the database. + /// Returns the name of the index in the database. /// /// The index. - /// The name of the index on the database. + /// The name of the index in the database. public static string GetDatabaseName([NotNull] this IIndex index) => (string)index[RelationalAnnotationNames.Name] ?? index.Name ?? index.GetDefaultDatabaseName(); /// - /// Returns the name of the index on the database. + /// Returns the name of the index in the database. /// /// The index. - /// The name of the index on the database. + /// The name of the index in the database. [Obsolete("Use GetDatabaseName() instead")] public static string GetName([NotNull] this IIndex index) => GetDatabaseName(index); /// - /// Returns the name of the index on the database. + /// Returns the name of the index in the database. /// /// The index. /// The table name. /// The schema. - /// The name of the index on the database. + /// The name of the index in the database. public static string GetDatabaseName( [NotNull] this IIndex index, [NotNull] string tableName, @@ -127,7 +127,7 @@ public static string GetDefaultDatabaseName( } /// - /// Sets the name of the index on the database. + /// Sets the name of the index in the database. /// /// The index. /// The value to set. @@ -139,7 +139,7 @@ public static void SetDatabaseName([NotNull] this IMutableIndex index, [CanBeNul } /// - /// Sets the name of the index on the database. + /// Sets the name of the index in the database. /// /// The index. /// The value to set. @@ -148,7 +148,7 @@ public static void SetName([NotNull] this IMutableIndex index, [CanBeNull] strin => SetDatabaseName(index, name); /// - /// Sets the name of the index on the database. + /// Sets the name of the index in the database. /// /// The index. /// The value to set. @@ -165,7 +165,7 @@ public static string SetDatabaseName([NotNull] this IConventionIndex index, [Can } /// - /// Sets the name of the index on the database. + /// Sets the name of the index in the database. /// /// The index. /// The value to set. @@ -176,18 +176,18 @@ public static string SetName([NotNull] this IConventionIndex index, [CanBeNull] => SetDatabaseName(index, name, fromDataAnnotation); /// - /// Gets the for the name of the index on the database. + /// Gets the for the name of the index in the database. /// /// The index. - /// The for the name of the index on the database. + /// The for the name of the index in the database. public static ConfigurationSource? GetDatabaseNameConfigurationSource([NotNull] this IConventionIndex index) => index.FindAnnotation(RelationalAnnotationNames.Name)?.GetConfigurationSource(); /// - /// Gets the for the name of the index on the database. + /// Gets the for the name of the index in the database. /// /// The index. - /// The for the name of the index on the database. + /// The for the name of the index in the database. [Obsolete("Use GetDatabaseNameConfigurationSource() instead.")] public static ConfigurationSource? GetNameConfigurationSource([NotNull] this IConventionIndex index) => GetDatabaseNameConfigurationSource(index); diff --git a/src/EFCore/Metadata/Builders/EntityTypeBuilder.cs b/src/EFCore/Metadata/Builders/EntityTypeBuilder.cs index e988e6bbeb0..a80c5056a06 100644 --- a/src/EFCore/Metadata/Builders/EntityTypeBuilder.cs +++ b/src/EFCore/Metadata/Builders/EntityTypeBuilder.cs @@ -279,9 +279,12 @@ public virtual IndexBuilder HasIndex([NotNull] params string[] propertyNames) /// An object that can be used to configure the index. public virtual IndexBuilder HasIndex( [NotNull] string[] propertyNames, - [CanBeNull] string name) + [NotNull] string name) => new IndexBuilder( - Builder.HasIndex(Check.NotEmpty(propertyNames, nameof(propertyNames)), name, ConfigurationSource.Explicit).Metadata); + Builder.HasIndex( + Check.NotEmpty(propertyNames, nameof(propertyNames)), + Check.NotEmpty(name, nameof(name)), + ConfigurationSource.Explicit).Metadata); /// /// diff --git a/src/EFCore/Metadata/Builders/EntityTypeBuilder`.cs b/src/EFCore/Metadata/Builders/EntityTypeBuilder`.cs index 7833c28159f..691b7750612 100644 --- a/src/EFCore/Metadata/Builders/EntityTypeBuilder`.cs +++ b/src/EFCore/Metadata/Builders/EntityTypeBuilder`.cs @@ -256,7 +256,7 @@ public virtual IndexBuilder HasIndex([NotNull] Expression An object that can be used to configure the index. public virtual IndexBuilder HasIndex( [NotNull] Expression> indexExpression, - [CanBeNull] string name) + [NotNull] string name) => new IndexBuilder( Builder.HasIndex( Check.NotNull(indexExpression, nameof(indexExpression)).GetMemberAccessList(), @@ -286,7 +286,7 @@ public virtual IndexBuilder HasIndex( /// An object that can be used to configure the index. public new virtual IndexBuilder HasIndex( [NotNull] string[] propertyNames, - [CanBeNull] string name) + [NotNull] string name) => new IndexBuilder( Builder.HasIndex( Check.NotEmpty(propertyNames, nameof(propertyNames)), diff --git a/src/EFCore/Metadata/IConventionEntityType.cs b/src/EFCore/Metadata/IConventionEntityType.cs index c299f5ac77a..f69b2641e32 100644 --- a/src/EFCore/Metadata/IConventionEntityType.cs +++ b/src/EFCore/Metadata/IConventionEntityType.cs @@ -312,7 +312,7 @@ IConventionIndex AddIndex( /// The newly created index. IConventionIndex AddIndex( [NotNull] IReadOnlyList properties, - [CanBeNull] string name, + [NotNull] string name, bool fromDataAnnotation = false); /// diff --git a/src/EFCore/Metadata/Internal/EntityType.cs b/src/EFCore/Metadata/Internal/EntityType.cs index 6c2c49deecf..1f55aa40ace 100644 --- a/src/EFCore/Metadata/Internal/EntityType.cs +++ b/src/EFCore/Metadata/Internal/EntityType.cs @@ -1860,7 +1860,7 @@ public virtual Index AddIndex( /// public virtual Index AddIndex( [NotNull] Property property, - [CanBeNull] string name, + [NotNull] string name, ConfigurationSource configurationSource) => AddIndex( new[] { property }, name, configurationSource); @@ -1931,7 +1931,7 @@ public virtual Index AddIndex( return (Index)Model.ConventionDispatcher.OnIndexAdded(index.Builder)?.Metadata; } - private void CheckIndexProperties([NotNull] IReadOnlyList properties) + private void CheckIndexProperties(IReadOnlyList properties) { for (var i = 0; i < properties.Count; i++) { @@ -1952,7 +1952,7 @@ private void CheckIndexProperties([NotNull] IReadOnlyList properties) } } - private void UpdatePropertyIndexes([NotNull] IReadOnlyList properties, [NotNull] Index index) + private void UpdatePropertyIndexes(IReadOnlyList properties, Index index) { foreach (var property in properties) { @@ -2039,7 +2039,7 @@ public virtual Index FindDeclaredIndex([NotNull] IReadOnlyList proper /// doing so can result in application failures when updating to a new Entity Framework Core release. /// public virtual Index FindDeclaredIndex([NotNull] string name) - => _namedIndexes.TryGetValue(name, out var index) + => _namedIndexes.TryGetValue(Check.NotEmpty(name, nameof(name)), out var index) ? index : null; @@ -2077,7 +2077,7 @@ public virtual IEnumerable FindIndexesInHierarchy([NotNull] IReadOnlyList /// doing so can result in application failures when updating to a new Entity Framework Core release. /// public virtual IEnumerable FindIndexesInHierarchy([NotNull] string name) - => ToEnumerable(FindIndex(name)).Concat(FindDerivedIndexes(name)); + => ToEnumerable(FindIndex(Check.NotEmpty(name, nameof(name)))).Concat(FindDerivedIndexes(name)); /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to diff --git a/src/EFCore/Metadata/Internal/Index.cs b/src/EFCore/Metadata/Internal/Index.cs index 1aca822d460..bc96931311d 100644 --- a/src/EFCore/Metadata/Internal/Index.cs +++ b/src/EFCore/Metadata/Internal/Index.cs @@ -40,8 +40,16 @@ public Index( [NotNull] IReadOnlyList properties, [NotNull] EntityType declaringEntityType, ConfigurationSource configurationSource) - : this(properties, null, declaringEntityType, configurationSource) { + Check.NotEmpty(properties, nameof(properties)); + Check.HasNoNulls(properties, nameof(properties)); + Check.NotNull(declaringEntityType, nameof(declaringEntityType)); + + Properties = properties; + DeclaringEntityType = declaringEntityType; + _configurationSource = configurationSource; + + Builder = new InternalIndexBuilder(this, declaringEntityType.Model.Builder); } /// @@ -51,21 +59,15 @@ public Index( /// doing so can result in application failures when updating to a new Entity Framework Core release. /// public Index( - [NotNull] IReadOnlyList properties, - [CanBeNull] string name, - [NotNull] EntityType declaringEntityType, - ConfigurationSource configurationSource) + [NotNull] IReadOnlyList properties, + [NotNull] string name, + [NotNull] EntityType declaringEntityType, + ConfigurationSource configurationSource) + : this(properties, declaringEntityType, configurationSource) { - Check.NotEmpty(properties, nameof(properties)); - Check.HasNoNulls(properties, nameof(properties)); - Check.NotNull(declaringEntityType, nameof(declaringEntityType)); + Check.NotEmpty(name, nameof(name)); - Properties = properties; Name = name; - DeclaringEntityType = declaringEntityType; - _configurationSource = configurationSource; - - Builder = new InternalIndexBuilder(this, declaringEntityType.Model.Builder); } ///