diff --git a/All.sln.DotSettings b/All.sln.DotSettings
index 237a053d2fc..057325cb8fc 100644
--- a/All.sln.DotSettings
+++ b/All.sln.DotSettings
@@ -230,4 +230,5 @@ Licensed under the Apache License, Version 2.0. See License.txt in the project r
True
True
True
+ True
True
\ No newline at end of file
diff --git a/src/EFCore.Abstractions/Properties/AbstractionsStrings.Designer.cs b/src/EFCore.Abstractions/Properties/AbstractionsStrings.Designer.cs
index fd0fdab4432..7aa43dede24 100644
--- a/src/EFCore.Abstractions/Properties/AbstractionsStrings.Designer.cs
+++ b/src/EFCore.Abstractions/Properties/AbstractionsStrings.Designer.cs
@@ -34,7 +34,7 @@ public static string ArgumentIsEmpty([CanBeNull] object? argumentName)
///
/// The number argument '{argumentName}' cannot be negative number.
///
- public static string ArgumentIsNegativeNumber([CanBeNull] object argumentName)
+ public static string ArgumentIsNegativeNumber([CanBeNull] object? argumentName)
=> string.Format(
GetString("ArgumentIsNegativeNumber", nameof(argumentName)),
argumentName);
diff --git a/src/EFCore.Cosmos/Extensions/CosmosEntityTypeBuilderExtensions.cs b/src/EFCore.Cosmos/Extensions/CosmosEntityTypeBuilderExtensions.cs
index 9f3c918835f..3608f20fac5 100644
--- a/src/EFCore.Cosmos/Extensions/CosmosEntityTypeBuilderExtensions.cs
+++ b/src/EFCore.Cosmos/Extensions/CosmosEntityTypeBuilderExtensions.cs
@@ -10,6 +10,8 @@
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Microsoft.EntityFrameworkCore.Utilities;
+#nullable enable
+
// ReSharper disable once CheckNamespace
namespace Microsoft.EntityFrameworkCore
{
@@ -26,7 +28,7 @@ public static class CosmosEntityTypeBuilderExtensions
/// The same builder instance so that multiple calls can be chained.
public static EntityTypeBuilder ToContainer(
[NotNull] this EntityTypeBuilder entityTypeBuilder,
- [CanBeNull] string name)
+ [CanBeNull] string? name)
{
Check.NotNull(entityTypeBuilder, nameof(entityTypeBuilder));
Check.NullButNotEmpty(name, nameof(name));
@@ -45,7 +47,7 @@ public static EntityTypeBuilder ToContainer(
/// The same builder instance so that multiple calls can be chained.
public static EntityTypeBuilder ToContainer(
[NotNull] this EntityTypeBuilder entityTypeBuilder,
- [CanBeNull] string name)
+ [CanBeNull] string? name)
where TEntity : class
=> (EntityTypeBuilder)ToContainer((EntityTypeBuilder)entityTypeBuilder, name);
@@ -59,9 +61,9 @@ public static EntityTypeBuilder ToContainer(
/// The same builder instance if the configuration was applied,
/// otherwise.
///
- public static IConventionEntityTypeBuilder ToContainer(
+ public static IConventionEntityTypeBuilder? ToContainer(
[NotNull] this IConventionEntityTypeBuilder entityTypeBuilder,
- [CanBeNull] string name,
+ [CanBeNull] string? name,
bool fromDataAnnotation = false)
{
if (!entityTypeBuilder.CanSetContainer(name, fromDataAnnotation))
@@ -84,7 +86,7 @@ public static IConventionEntityTypeBuilder ToContainer(
/// if the configuration can be applied.
public static bool CanSetContainer(
[NotNull] this IConventionEntityTypeBuilder entityTypeBuilder,
- [CanBeNull] string name,
+ [CanBeNull] string? name,
bool fromDataAnnotation = false)
{
Check.NotNull(entityTypeBuilder, nameof(entityTypeBuilder));
@@ -101,7 +103,7 @@ public static bool CanSetContainer(
/// The same builder instance so that multiple calls can be chained.
public static OwnedNavigationBuilder ToJsonProperty(
[NotNull] this OwnedNavigationBuilder entityTypeBuilder,
- [CanBeNull] string name)
+ [CanBeNull] string? name)
{
entityTypeBuilder.OwnedEntityType.SetContainingPropertyName(name);
@@ -116,7 +118,7 @@ public static OwnedNavigationBuilder ToJsonProperty(
/// The same builder instance so that multiple calls can be chained.
public static OwnedNavigationBuilder ToJsonProperty(
[NotNull] this OwnedNavigationBuilder entityTypeBuilder,
- [CanBeNull] string name)
+ [CanBeNull] string? name)
where TEntity : class
where TDependentEntity : class
{
@@ -135,9 +137,9 @@ public static OwnedNavigationBuilder ToJsonProperty otherwise.
///
- public static IConventionEntityTypeBuilder ToJsonProperty(
+ public static IConventionEntityTypeBuilder? ToJsonProperty(
[NotNull] this IConventionEntityTypeBuilder entityTypeBuilder,
- [CanBeNull] string name,
+ [CanBeNull] string? name,
bool fromDataAnnotation = false)
{
if (!entityTypeBuilder.CanSetJsonProperty(name, fromDataAnnotation))
@@ -160,7 +162,7 @@ public static IConventionEntityTypeBuilder ToJsonProperty(
/// if the configuration can be applied.
public static bool CanSetJsonProperty(
[NotNull] this IConventionEntityTypeBuilder entityTypeBuilder,
- [CanBeNull] string name,
+ [CanBeNull] string? name,
bool fromDataAnnotation = false)
{
Check.NotNull(entityTypeBuilder, nameof(entityTypeBuilder));
@@ -177,7 +179,7 @@ public static bool CanSetJsonProperty(
/// The same builder instance so that multiple calls can be chained.
public static EntityTypeBuilder HasPartitionKey(
[NotNull] this EntityTypeBuilder entityTypeBuilder,
- [CanBeNull] string name)
+ [CanBeNull] string? name)
{
entityTypeBuilder.Metadata.SetPartitionKeyPropertyName(name);
@@ -192,7 +194,7 @@ public static EntityTypeBuilder HasPartitionKey(
/// The same builder instance so that multiple calls can be chained.
public static EntityTypeBuilder HasPartitionKey(
[NotNull] this EntityTypeBuilder entityTypeBuilder,
- [CanBeNull] string name)
+ [CanBeNull] string? name)
where TEntity : class
{
entityTypeBuilder.Metadata.SetPartitionKeyPropertyName(name);
@@ -228,9 +230,9 @@ public static EntityTypeBuilder HasPartitionKey(
/// The same builder instance if the configuration was applied,
/// otherwise.
///
- public static IConventionEntityTypeBuilder HasPartitionKey(
+ public static IConventionEntityTypeBuilder? HasPartitionKey(
[NotNull] this IConventionEntityTypeBuilder entityTypeBuilder,
- [CanBeNull] string name,
+ [CanBeNull] string? name,
bool fromDataAnnotation = false)
{
if (!entityTypeBuilder.CanSetPartitionKey(name, fromDataAnnotation))
@@ -253,7 +255,7 @@ public static IConventionEntityTypeBuilder HasPartitionKey(
/// if the configuration can be applied.
public static bool CanSetPartitionKey(
[NotNull] this IConventionEntityTypeBuilder entityTypeBuilder,
- [CanBeNull] string name,
+ [CanBeNull] string? name,
bool fromDataAnnotation = false)
{
Check.NotNull(entityTypeBuilder, nameof(entityTypeBuilder));
diff --git a/src/EFCore.Cosmos/Extensions/CosmosEntityTypeExtensions.cs b/src/EFCore.Cosmos/Extensions/CosmosEntityTypeExtensions.cs
index 06df02876a3..45df40bf3e2 100644
--- a/src/EFCore.Cosmos/Extensions/CosmosEntityTypeExtensions.cs
+++ b/src/EFCore.Cosmos/Extensions/CosmosEntityTypeExtensions.cs
@@ -6,6 +6,8 @@
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Utilities;
+#nullable enable
+
// ReSharper disable once CheckNamespace
namespace Microsoft.EntityFrameworkCore
{
@@ -19,13 +21,13 @@ public static class CosmosEntityTypeExtensions
///
/// The entity type to get the container name for.
/// The name of the container to which the entity type is mapped.
- public static string GetContainer([NotNull] this IEntityType entityType)
+ public static string? GetContainer([NotNull] this IEntityType entityType)
=> entityType.BaseType != null
? entityType.GetRootType().GetContainer()
- : (string)entityType[CosmosAnnotationNames.ContainerName]
+ : (string?)entityType[CosmosAnnotationNames.ContainerName]
?? GetDefaultContainer(entityType);
- private static string GetDefaultContainer(IEntityType entityType)
+ private static string? GetDefaultContainer(IEntityType entityType)
=> entityType.IsOwned()
? null
: entityType.Model.GetDefaultContainer()
@@ -36,7 +38,7 @@ private static string GetDefaultContainer(IEntityType entityType)
///
/// The entity type to set the container name for.
/// The name to set.
- public static void SetContainer([NotNull] this IMutableEntityType entityType, [CanBeNull] string name)
+ public static void SetContainer([NotNull] this IMutableEntityType entityType, [CanBeNull] string? name)
=> entityType.SetOrRemoveAnnotation(
CosmosAnnotationNames.ContainerName,
Check.NullButNotEmpty(name, nameof(name)));
@@ -49,7 +51,7 @@ public static void SetContainer([NotNull] this IMutableEntityType entityType, [C
/// Indicates whether the configuration was specified using a data annotation.
public static void SetContainer(
[NotNull] this IConventionEntityType entityType,
- [CanBeNull] string name,
+ [CanBeNull] string? name,
bool fromDataAnnotation = false)
=> entityType.SetOrRemoveAnnotation(
CosmosAnnotationNames.ContainerName,
@@ -70,19 +72,19 @@ public static void SetContainer(
///
/// The entity type to get the containing property name for.
/// The name of the parent property to which the entity type is mapped.
- public static string GetContainingPropertyName([NotNull] this IEntityType entityType)
+ public static string? GetContainingPropertyName([NotNull] this IEntityType entityType)
=> entityType[CosmosAnnotationNames.PropertyName] as string
?? GetDefaultContainingPropertyName(entityType);
- private static string GetDefaultContainingPropertyName(IEntityType entityType)
- => entityType.FindOwnership()?.PrincipalToDependent.Name;
+ private static string? GetDefaultContainingPropertyName(IEntityType entityType)
+ => entityType.FindOwnership()?.PrincipalToDependent!.Name;
///
/// Sets the name of the parent property to which the entity type is mapped.
///
/// The entity type to set the containing property name for.
/// The name to set.
- public static void SetContainingPropertyName([NotNull] this IMutableEntityType entityType, [CanBeNull] string name)
+ public static void SetContainingPropertyName([NotNull] this IMutableEntityType entityType, [CanBeNull] string? name)
=> entityType.SetOrRemoveAnnotation(
CosmosAnnotationNames.PropertyName,
Check.NullButNotEmpty(name, nameof(name)));
@@ -95,7 +97,7 @@ public static void SetContainingPropertyName([NotNull] this IMutableEntityType e
/// Indicates whether the configuration was specified using a data annotation.
public static void SetContainingPropertyName(
[NotNull] this IConventionEntityType entityType,
- [CanBeNull] string name,
+ [CanBeNull] string? name,
bool fromDataAnnotation = false)
=> entityType.SetOrRemoveAnnotation(
CosmosAnnotationNames.PropertyName,
@@ -116,7 +118,7 @@ public static void SetContainingPropertyName(
///
/// The entity type to get the partition key property name for.
/// The name of the partition key property.
- public static string GetPartitionKeyPropertyName([NotNull] this IEntityType entityType)
+ public static string? GetPartitionKeyPropertyName([NotNull] this IEntityType entityType)
=> entityType[CosmosAnnotationNames.PartitionKeyName] as string;
///
@@ -124,7 +126,7 @@ public static string GetPartitionKeyPropertyName([NotNull] this IEntityType enti
///
/// The entity type to set the partition key property name for.
/// The name to set.
- public static void SetPartitionKeyPropertyName([NotNull] this IMutableEntityType entityType, [CanBeNull] string name)
+ public static void SetPartitionKeyPropertyName([NotNull] this IMutableEntityType entityType, [CanBeNull] string? name)
=> entityType.SetOrRemoveAnnotation(
CosmosAnnotationNames.PartitionKeyName,
Check.NullButNotEmpty(name, nameof(name)));
@@ -137,7 +139,7 @@ public static void SetPartitionKeyPropertyName([NotNull] this IMutableEntityType
/// Indicates whether the configuration was specified using a data annotation.
public static void SetPartitionKeyPropertyName(
[NotNull] this IConventionEntityType entityType,
- [CanBeNull] string name,
+ [CanBeNull] string? name,
bool fromDataAnnotation = false)
=> entityType.SetOrRemoveAnnotation(
CosmosAnnotationNames.PartitionKeyName,
@@ -158,7 +160,7 @@ public static void SetPartitionKeyPropertyName(
///
/// The entity type to get the etag property name for.
/// The name of the etag property.
- public static string GetETagPropertyName([NotNull] this IEntityType entityType)
+ public static string? GetETagPropertyName([NotNull] this IEntityType entityType)
=> entityType[CosmosAnnotationNames.ETagName] as string;
///
@@ -166,7 +168,7 @@ public static string GetETagPropertyName([NotNull] this IEntityType entityType)
///
/// The entity type to set the etag property name for.
/// The name to set.
- public static void SetETagPropertyName([NotNull] this IMutableEntityType entityType, [CanBeNull] string name)
+ public static void SetETagPropertyName([NotNull] this IMutableEntityType entityType, [CanBeNull] string? name)
=> entityType.SetOrRemoveAnnotation(
CosmosAnnotationNames.ETagName,
Check.NullButNotEmpty(name, nameof(name)));
@@ -179,7 +181,7 @@ public static void SetETagPropertyName([NotNull] this IMutableEntityType entityT
/// Indicates whether the configuration was specified using a data annotation.
public static void SetETagPropertyName(
[NotNull] this IConventionEntityType entityType,
- [CanBeNull] string name,
+ [CanBeNull] string? name,
bool fromDataAnnotation = false)
=> entityType.SetOrRemoveAnnotation(
CosmosAnnotationNames.ETagName,
@@ -200,7 +202,7 @@ public static void SetETagPropertyName(
///
/// The entity type to get the etag property for.
/// The mapped to etag, or null if no property is mapped to etag.
- public static IProperty GetETagProperty([NotNull] this IEntityType entityType)
+ public static IProperty? GetETagProperty([NotNull] this IEntityType entityType)
{
Check.NotNull(entityType, nameof(entityType));
var etagPropertyName = entityType.GetETagPropertyName();
diff --git a/src/EFCore.Cosmos/Extensions/CosmosModelBuilderExtensions.cs b/src/EFCore.Cosmos/Extensions/CosmosModelBuilderExtensions.cs
index 7accac5d79b..595de88ab78 100644
--- a/src/EFCore.Cosmos/Extensions/CosmosModelBuilderExtensions.cs
+++ b/src/EFCore.Cosmos/Extensions/CosmosModelBuilderExtensions.cs
@@ -6,6 +6,8 @@
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Microsoft.EntityFrameworkCore.Utilities;
+#nullable enable
+
// ReSharper disable once CheckNamespace
namespace Microsoft.EntityFrameworkCore
{
@@ -23,7 +25,7 @@ public static class CosmosModelBuilderExtensions
/// The same builder instance so that multiple calls can be chained.
public static ModelBuilder HasDefaultContainer(
[NotNull] this ModelBuilder modelBuilder,
- [CanBeNull] string name)
+ [CanBeNull] string? name)
{
Check.NotNull(modelBuilder, nameof(modelBuilder));
Check.NullButNotEmpty(name, nameof(name));
@@ -44,9 +46,9 @@ public static ModelBuilder HasDefaultContainer(
/// The same builder instance if the configuration was applied,
/// otherwise.
///
- public static IConventionModelBuilder HasDefaultContainer(
+ public static IConventionModelBuilder? HasDefaultContainer(
[NotNull] this IConventionModelBuilder modelBuilder,
- [CanBeNull] string name,
+ [CanBeNull] string? name,
bool fromDataAnnotation = false)
{
if (!modelBuilder.CanSetDefaultContainer(name, fromDataAnnotation))
@@ -68,7 +70,7 @@ public static IConventionModelBuilder HasDefaultContainer(
/// if the given container name can be set as default.
public static bool CanSetDefaultContainer(
[NotNull] this IConventionModelBuilder modelBuilder,
- [CanBeNull] string name,
+ [CanBeNull] string? name,
bool fromDataAnnotation = false)
{
Check.NotNull(modelBuilder, nameof(modelBuilder));
diff --git a/src/EFCore.Cosmos/Extensions/CosmosModelExtensions.cs b/src/EFCore.Cosmos/Extensions/CosmosModelExtensions.cs
index c88a8e7ab89..80b4de7d1a2 100644
--- a/src/EFCore.Cosmos/Extensions/CosmosModelExtensions.cs
+++ b/src/EFCore.Cosmos/Extensions/CosmosModelExtensions.cs
@@ -6,6 +6,8 @@
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Utilities;
+#nullable enable
+
// ReSharper disable once CheckNamespace
namespace Microsoft.EntityFrameworkCore
{
@@ -19,15 +21,15 @@ public static class CosmosModelExtensions
///
/// The model.
/// The default container name.
- public static string GetDefaultContainer([NotNull] this IModel model)
- => (string)model[CosmosAnnotationNames.ContainerName];
+ public static string? GetDefaultContainer([NotNull] this IModel model)
+ => (string?)model[CosmosAnnotationNames.ContainerName];
///
/// Sets the default container name.
///
/// The model.
/// The name to set.
- public static void SetDefaultContainer([NotNull] this IMutableModel model, [CanBeNull] string name)
+ public static void SetDefaultContainer([NotNull] this IMutableModel model, [CanBeNull] string? name)
=> model.SetOrRemoveAnnotation(
CosmosAnnotationNames.ContainerName,
Check.NullButNotEmpty(name, nameof(name)));
@@ -39,9 +41,9 @@ public static void SetDefaultContainer([NotNull] this IMutableModel model, [CanB
/// The name to set.
/// Indicates whether the configuration was specified using a data annotation.
/// The configured value.
- public static string SetDefaultContainer(
+ public static string? SetDefaultContainer(
[NotNull] this IConventionModel model,
- [CanBeNull] string name,
+ [CanBeNull] string? name,
bool fromDataAnnotation = false)
{
model.SetOrRemoveAnnotation(
diff --git a/src/EFCore.Cosmos/Extensions/CosmosPropertyBuilderExtensions.cs b/src/EFCore.Cosmos/Extensions/CosmosPropertyBuilderExtensions.cs
index d1b56328812..bf67189b9f3 100644
--- a/src/EFCore.Cosmos/Extensions/CosmosPropertyBuilderExtensions.cs
+++ b/src/EFCore.Cosmos/Extensions/CosmosPropertyBuilderExtensions.cs
@@ -6,6 +6,8 @@
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Microsoft.EntityFrameworkCore.Utilities;
+#nullable enable
+
// ReSharper disable once CheckNamespace
namespace Microsoft.EntityFrameworkCore
{
@@ -60,9 +62,9 @@ public static PropertyBuilder ToJsonProperty(
/// The same builder instance if the configuration was applied,
/// otherwise.
///
- public static IConventionPropertyBuilder ToJsonProperty(
+ public static IConventionPropertyBuilder? ToJsonProperty(
[NotNull] this IConventionPropertyBuilder propertyBuilder,
- [CanBeNull] string name,
+ [CanBeNull] string? name,
bool fromDataAnnotation = false)
{
if (!propertyBuilder.CanSetJsonProperty(name, fromDataAnnotation))
@@ -84,7 +86,7 @@ public static IConventionPropertyBuilder ToJsonProperty(
/// if the property name can be set.
public static bool CanSetJsonProperty(
[NotNull] this IConventionPropertyBuilder propertyBuilder,
- [CanBeNull] string name,
+ [CanBeNull] string? name,
bool fromDataAnnotation = false)
=> propertyBuilder.CanSetAnnotation(CosmosAnnotationNames.PropertyName, name, fromDataAnnotation);
diff --git a/src/EFCore.Cosmos/Extensions/CosmosPropertyExtensions.cs b/src/EFCore.Cosmos/Extensions/CosmosPropertyExtensions.cs
index 8db108e8e7b..4fb7a1a0f88 100644
--- a/src/EFCore.Cosmos/Extensions/CosmosPropertyExtensions.cs
+++ b/src/EFCore.Cosmos/Extensions/CosmosPropertyExtensions.cs
@@ -6,6 +6,8 @@
using Microsoft.EntityFrameworkCore.Cosmos.Metadata.Internal;
using Microsoft.EntityFrameworkCore.Metadata;
+#nullable enable
+
// ReSharper disable once CheckNamespace
namespace Microsoft.EntityFrameworkCore
{
@@ -20,7 +22,7 @@ public static class CosmosPropertyExtensions
/// The property.
/// Returns the property name that the property is mapped to when targeting Cosmos.
public static string GetJsonPropertyName([NotNull] this IProperty property)
- => (string)property[CosmosAnnotationNames.PropertyName]
+ => (string?)property[CosmosAnnotationNames.PropertyName]
?? GetDefaultJsonPropertyName(property);
private static string GetDefaultJsonPropertyName(IProperty property)
@@ -49,7 +51,7 @@ private static string GetDefaultJsonPropertyName(IProperty property)
///
/// The property.
/// The name to set.
- public static void SetJsonPropertyName([NotNull] this IMutableProperty property, [CanBeNull] string name)
+ public static void SetJsonPropertyName([NotNull] this IMutableProperty property, [CanBeNull] string? name)
=> property.SetOrRemoveAnnotation(
CosmosAnnotationNames.PropertyName,
name);
@@ -61,9 +63,9 @@ public static void SetJsonPropertyName([NotNull] this IMutableProperty property,
/// The name to set.
/// Indicates whether the configuration was specified using a data annotation.
/// The configured value.
- public static string SetJsonPropertyName(
+ public static string? SetJsonPropertyName(
[NotNull] this IConventionProperty property,
- [CanBeNull] string name,
+ [CanBeNull] string? name,
bool fromDataAnnotation = false)
{
property.SetOrRemoveAnnotation(
diff --git a/src/EFCore.Cosmos/Infrastructure/Internal/CosmosModelValidator.cs b/src/EFCore.Cosmos/Infrastructure/Internal/CosmosModelValidator.cs
index de494eb5868..94f4a0be63a 100644
--- a/src/EFCore.Cosmos/Infrastructure/Internal/CosmosModelValidator.cs
+++ b/src/EFCore.Cosmos/Infrastructure/Internal/CosmosModelValidator.cs
@@ -139,7 +139,7 @@ protected virtual void ValidateSharedContainerCompatibility(
firstEntityType = entityType;
}
- if (entityType.ClrType?.IsInstantiable() == true
+ if (entityType.ClrType.IsInstantiable()
&& entityType.GetContainingPropertyName() == null)
{
if (entityType.GetDiscriminatorProperty() == null)
diff --git a/src/EFCore.Cosmos/Metadata/Conventions/ContextContainerConvention.cs b/src/EFCore.Cosmos/Metadata/Conventions/ContextContainerConvention.cs
index 5b60b827613..3eb63c1b40f 100644
--- a/src/EFCore.Cosmos/Metadata/Conventions/ContextContainerConvention.cs
+++ b/src/EFCore.Cosmos/Metadata/Conventions/ContextContainerConvention.cs
@@ -6,6 +6,8 @@
using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure;
using Microsoft.EntityFrameworkCore.Utilities;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Metadata.Conventions
{
///
diff --git a/src/EFCore.Cosmos/Metadata/Conventions/CosmosDiscriminatorConvention.cs b/src/EFCore.Cosmos/Metadata/Conventions/CosmosDiscriminatorConvention.cs
index 378a2029759..a1278f188b1 100644
--- a/src/EFCore.Cosmos/Metadata/Conventions/CosmosDiscriminatorConvention.cs
+++ b/src/EFCore.Cosmos/Metadata/Conventions/CosmosDiscriminatorConvention.cs
@@ -8,6 +8,8 @@
using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure;
using Microsoft.EntityFrameworkCore.Utilities;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Metadata.Conventions
{
///
@@ -101,8 +103,8 @@ public virtual void ProcessForeignKeyRemoved(
/// Additional information associated with convention execution.
public override void ProcessEntityTypeBaseTypeChanged(
IConventionEntityTypeBuilder entityTypeBuilder,
- IConventionEntityType newBaseType,
- IConventionEntityType oldBaseType,
+ IConventionEntityType? newBaseType,
+ IConventionEntityType? oldBaseType,
IConventionContext context)
{
if (entityTypeBuilder.Metadata.BaseType != newBaseType)
@@ -110,7 +112,7 @@ public override void ProcessEntityTypeBaseTypeChanged(
return;
}
- IConventionDiscriminatorBuilder discriminator = null;
+ IConventionDiscriminatorBuilder? discriminator = null;
var entityType = entityTypeBuilder.Metadata;
if (newBaseType == null)
{
@@ -121,7 +123,10 @@ public override void ProcessEntityTypeBaseTypeChanged(
}
else
{
- discriminator = newBaseType.GetRootType().Builder?.HasDiscriminator(typeof(string));
+ var rootType = newBaseType.GetRootType();
+ discriminator = rootType.IsInModel
+ ? rootType.Builder.HasDiscriminator(typeof(string))
+ : null;
if (newBaseType.BaseType == null)
{
diff --git a/src/EFCore.Cosmos/Metadata/Conventions/CosmosKeyDiscoveryConvention.cs b/src/EFCore.Cosmos/Metadata/Conventions/CosmosKeyDiscoveryConvention.cs
index 1adb526121e..cb40a0d7dbb 100644
--- a/src/EFCore.Cosmos/Metadata/Conventions/CosmosKeyDiscoveryConvention.cs
+++ b/src/EFCore.Cosmos/Metadata/Conventions/CosmosKeyDiscoveryConvention.cs
@@ -8,6 +8,8 @@
using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure;
using Microsoft.EntityFrameworkCore.Utilities;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Metadata.Conventions
{
///
@@ -38,8 +40,8 @@ public CosmosKeyDiscoveryConvention([NotNull] ProviderConventionSetBuilderDepend
public virtual void ProcessEntityTypeAnnotationChanged(
IConventionEntityTypeBuilder entityTypeBuilder,
string name,
- IConventionAnnotation annotation,
- IConventionAnnotation oldAnnotation,
+ IConventionAnnotation? annotation,
+ IConventionAnnotation? oldAnnotation,
IConventionContext context)
{
Check.NotNull(entityTypeBuilder, nameof(entityTypeBuilder));
diff --git a/src/EFCore.Cosmos/Metadata/Conventions/ETagPropertyConvention.cs b/src/EFCore.Cosmos/Metadata/Conventions/ETagPropertyConvention.cs
index eda65264cea..0e8fa5e9f87 100644
--- a/src/EFCore.Cosmos/Metadata/Conventions/ETagPropertyConvention.cs
+++ b/src/EFCore.Cosmos/Metadata/Conventions/ETagPropertyConvention.cs
@@ -4,6 +4,8 @@
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Microsoft.EntityFrameworkCore.Metadata.Conventions;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Cosmos.Metadata.Conventions
{
///
diff --git a/src/EFCore.Cosmos/Metadata/Conventions/Internal/CosmosConventionSetBuilder.cs b/src/EFCore.Cosmos/Metadata/Conventions/Internal/CosmosConventionSetBuilder.cs
index c22c2a314c5..75c961ca288 100644
--- a/src/EFCore.Cosmos/Metadata/Conventions/Internal/CosmosConventionSetBuilder.cs
+++ b/src/EFCore.Cosmos/Metadata/Conventions/Internal/CosmosConventionSetBuilder.cs
@@ -7,6 +7,8 @@
using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure;
using Microsoft.Extensions.DependencyInjection;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Cosmos.Metadata.Conventions.Internal
{
///
@@ -100,7 +102,7 @@ public override ConventionSet CreateConventionSet()
public static ModelBuilder CreateModelBuilder()
{
using var serviceScope = CreateServiceScope();
- using var context = serviceScope.ServiceProvider.GetService();
+ using var context = serviceScope.ServiceProvider.GetRequiredService();
return new ModelBuilder(ConventionSet.CreateConventionSet(context), context.GetService());
}
diff --git a/src/EFCore.Cosmos/Metadata/Conventions/StoreKeyConvention.cs b/src/EFCore.Cosmos/Metadata/Conventions/StoreKeyConvention.cs
index 7cd6dbcedbd..2741e6294b4 100644
--- a/src/EFCore.Cosmos/Metadata/Conventions/StoreKeyConvention.cs
+++ b/src/EFCore.Cosmos/Metadata/Conventions/StoreKeyConvention.cs
@@ -11,6 +11,8 @@
using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure;
using Newtonsoft.Json.Linq;
+#nullable enable
+
// ReSharper disable once CheckNamespace
namespace Microsoft.EntityFrameworkCore.Metadata.Conventions
{
@@ -76,8 +78,8 @@ public StoreKeyConvention([NotNull] ProviderConventionSetBuilderDependencies dep
private static void ProcessIdProperty(IConventionEntityTypeBuilder entityTypeBuilder)
{
- IConventionKey newKey = null;
- IConventionProperty idProperty = null;
+ IConventionKey? newKey = null;
+ IConventionProperty? idProperty;
var entityType = entityTypeBuilder.Metadata;
if (entityType.BaseType == null
&& entityType.IsDocumentRoot()
@@ -94,11 +96,11 @@ private static void ProcessIdProperty(IConventionEntityTypeBuilder entityTypeBui
{
if (idProperty.IsPrimaryKey())
{
- idProperty.Builder.HasValueGenerator((Type)null);
+ idProperty.Builder.HasValueGenerator((Type?)null);
}
else
{
- idProperty.Builder.HasValueGenerator((_, __) => new IdValueGenerator());
+ idProperty.Builder.HasValueGenerator((_, _) => new IdValueGenerator());
}
}
@@ -222,8 +224,8 @@ public virtual void ProcessKeyRemoved(
///
public virtual void ProcessEntityTypePrimaryKeyChanged(
IConventionEntityTypeBuilder entityTypeBuilder,
- IConventionKey newPrimaryKey,
- IConventionKey previousPrimaryKey,
+ IConventionKey? newPrimaryKey,
+ IConventionKey? previousPrimaryKey,
IConventionContext context)
{
if ((newPrimaryKey != null && newPrimaryKey.Properties.Any(p => p.GetJsonPropertyName() == IdPropertyJsonName))
@@ -236,8 +238,8 @@ public virtual void ProcessEntityTypePrimaryKeyChanged(
///
public virtual void ProcessEntityTypeBaseTypeChanged(
IConventionEntityTypeBuilder entityTypeBuilder,
- IConventionEntityType newBaseType,
- IConventionEntityType oldBaseType,
+ IConventionEntityType? newBaseType,
+ IConventionEntityType? oldBaseType,
IConventionContext context)
{
if (entityTypeBuilder.Metadata.BaseType == newBaseType)
@@ -251,8 +253,8 @@ public virtual void ProcessEntityTypeBaseTypeChanged(
public virtual void ProcessEntityTypeAnnotationChanged(
IConventionEntityTypeBuilder entityTypeBuilder,
string name,
- IConventionAnnotation annotation,
- IConventionAnnotation oldAnnotation,
+ IConventionAnnotation? annotation,
+ IConventionAnnotation? oldAnnotation,
IConventionContext context)
{
if (name == CosmosAnnotationNames.ContainerName
@@ -263,7 +265,7 @@ public virtual void ProcessEntityTypeAnnotationChanged(
}
else if (name == CosmosAnnotationNames.PartitionKeyName)
{
- var oldName = (string)oldAnnotation?.Value;
+ var oldName = (string?)oldAnnotation?.Value;
if (oldName != null)
{
var oldPartitionKeyProperty = entityTypeBuilder.Metadata.FindProperty(oldName);
@@ -284,12 +286,12 @@ public virtual void ProcessEntityTypeAnnotationChanged(
public virtual void ProcessPropertyAnnotationChanged(
IConventionPropertyBuilder propertyBuilder,
string name,
- IConventionAnnotation annotation,
- IConventionAnnotation oldAnnotation,
+ IConventionAnnotation? annotation,
+ IConventionAnnotation? oldAnnotation,
IConventionContext context)
{
if (name == CosmosAnnotationNames.PropertyName
- && (string)annotation?.Value == IdPropertyJsonName
+ && (string?)annotation?.Value == IdPropertyJsonName
&& propertyBuilder.Metadata.Name != DefaultIdPropertyName)
{
var entityType = propertyBuilder.Metadata.DeclaringEntityType;
diff --git a/src/EFCore.Cosmos/Storage/Internal/CosmosTypeMapping.cs b/src/EFCore.Cosmos/Storage/Internal/CosmosTypeMapping.cs
index 299607ca4f8..162caa39dd9 100644
--- a/src/EFCore.Cosmos/Storage/Internal/CosmosTypeMapping.cs
+++ b/src/EFCore.Cosmos/Storage/Internal/CosmosTypeMapping.cs
@@ -7,6 +7,8 @@
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Cosmos.Storage.Internal
{
///
@@ -25,8 +27,8 @@ public class CosmosTypeMapping : CoreTypeMapping
///
public CosmosTypeMapping(
[NotNull] Type clrType,
- [CanBeNull] ValueComparer comparer = null,
- [CanBeNull] ValueComparer keyComparer = null)
+ [CanBeNull] ValueComparer? comparer = null,
+ [CanBeNull] ValueComparer? keyComparer = null)
: base(
new CoreTypeMappingParameters(
clrType,
@@ -53,7 +55,7 @@ protected CosmosTypeMapping(CoreTypeMappingParameters parameters)
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
- public override CoreTypeMapping Clone(ValueConverter converter)
+ public override CoreTypeMapping Clone(ValueConverter? converter)
=> new CosmosTypeMapping(Parameters.WithComposedConverter(converter));
}
}
diff --git a/src/EFCore.InMemory/Extensions/InMemoryEntityTypeBuilderExtensions.cs b/src/EFCore.InMemory/Extensions/InMemoryEntityTypeBuilderExtensions.cs
index b0769362ca2..3235499d4db 100644
--- a/src/EFCore.InMemory/Extensions/InMemoryEntityTypeBuilderExtensions.cs
+++ b/src/EFCore.InMemory/Extensions/InMemoryEntityTypeBuilderExtensions.cs
@@ -9,6 +9,8 @@
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using Microsoft.EntityFrameworkCore.Utilities;
+#nullable enable
+
// ReSharper disable once CheckNamespace
namespace Microsoft.EntityFrameworkCore
{
@@ -44,9 +46,9 @@ public static EntityTypeBuilder ToInMemoryQuery(
///
/// The same builder instance if the query was set, otherwise.
///
- public static IConventionEntityTypeBuilder ToInMemoryQuery(
+ public static IConventionEntityTypeBuilder? ToInMemoryQuery(
[NotNull] this IConventionEntityTypeBuilder entityTypeBuilder,
- [CanBeNull] LambdaExpression query,
+ [CanBeNull] LambdaExpression? query,
bool fromDataAnnotation = false)
{
if (CanSetInMemoryQuery(entityTypeBuilder, query, fromDataAnnotation))
@@ -68,7 +70,7 @@ public static IConventionEntityTypeBuilder ToInMemoryQuery(
/// if the given in-memory query can be set.
public static bool CanSetInMemoryQuery(
[NotNull] this IConventionEntityTypeBuilder entityTypeBuilder,
- [CanBeNull] LambdaExpression query,
+ [CanBeNull] LambdaExpression? query,
bool fromDataAnnotation = false)
#pragma warning disable EF1001 // Internal EF Core API usage.
#pragma warning disable CS0612 // Type or member is obsolete
diff --git a/src/EFCore.InMemory/Extensions/InMemoryEntityTypeExtensions.cs b/src/EFCore.InMemory/Extensions/InMemoryEntityTypeExtensions.cs
index 9b6692bc19a..123181eabfc 100644
--- a/src/EFCore.InMemory/Extensions/InMemoryEntityTypeExtensions.cs
+++ b/src/EFCore.InMemory/Extensions/InMemoryEntityTypeExtensions.cs
@@ -7,6 +7,8 @@
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using Microsoft.EntityFrameworkCore.Utilities;
+#nullable enable
+
// ReSharper disable once CheckNamespace
namespace Microsoft.EntityFrameworkCore
{
@@ -20,10 +22,10 @@ public static class InMemoryEntityTypeExtensions
///
/// The entity type to get the in-memory query for.
/// The LINQ query used as the default source.
- public static LambdaExpression GetInMemoryQuery([NotNull] this IEntityType entityType)
+ public static LambdaExpression? GetInMemoryQuery([NotNull] this IEntityType entityType)
#pragma warning disable EF1001 // Internal EF Core API usage.
#pragma warning disable CS0612 // Type or member is obsolete
- => (LambdaExpression)Check.NotNull(entityType, nameof(entityType))[CoreAnnotationNames.DefiningQuery];
+ => (LambdaExpression?)Check.NotNull(entityType, nameof(entityType))[CoreAnnotationNames.DefiningQuery];
#pragma warning restore CS0612 // Type or member is obsolete
#pragma warning restore EF1001 // Internal EF Core API usage.
@@ -34,7 +36,7 @@ public static LambdaExpression GetInMemoryQuery([NotNull] this IEntityType entit
/// The LINQ query used as the default source.
public static void SetInMemoryQuery(
[NotNull] this IMutableEntityType entityType,
- [CanBeNull] LambdaExpression inMemoryQuery)
+ [CanBeNull] LambdaExpression? inMemoryQuery)
=> Check.NotNull(entityType, nameof(entityType))
#pragma warning disable EF1001 // Internal EF Core API usage.
#pragma warning disable CS0612 // Type or member is obsolete
@@ -49,11 +51,11 @@ public static void SetInMemoryQuery(
/// The LINQ query used as the default source.
/// Indicates whether the configuration was specified using a data annotation.
/// The configured entity type.
- public static LambdaExpression SetInMemoryQuery(
+ public static LambdaExpression? SetInMemoryQuery(
[NotNull] this IConventionEntityType entityType,
- [CanBeNull] LambdaExpression inMemoryQuery,
+ [CanBeNull] LambdaExpression? inMemoryQuery,
bool fromDataAnnotation = false)
- => (LambdaExpression)Check.NotNull(entityType, nameof(entityType))
+ => (LambdaExpression?)Check.NotNull(entityType, nameof(entityType))
#pragma warning disable EF1001 // Internal EF Core API usage.
#pragma warning disable CS0612 // Type or member is obsolete
.SetOrRemoveAnnotation(CoreAnnotationNames.DefiningQuery, inMemoryQuery, fromDataAnnotation)
diff --git a/src/EFCore.InMemory/Metadata/Conventions/DefiningQueryRewritingConvention.cs b/src/EFCore.InMemory/Metadata/Conventions/DefiningQueryRewritingConvention.cs
index 9b8593008c8..33f4699b7a9 100644
--- a/src/EFCore.InMemory/Metadata/Conventions/DefiningQueryRewritingConvention.cs
+++ b/src/EFCore.InMemory/Metadata/Conventions/DefiningQueryRewritingConvention.cs
@@ -7,6 +7,8 @@
using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure;
using Microsoft.EntityFrameworkCore.Query;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Metadata.Conventions
{
///
diff --git a/src/EFCore.InMemory/Metadata/Conventions/InMemoryConventionSetBuilder.cs b/src/EFCore.InMemory/Metadata/Conventions/InMemoryConventionSetBuilder.cs
index 0b32bf4c8b6..bb6f50c9b29 100644
--- a/src/EFCore.InMemory/Metadata/Conventions/InMemoryConventionSetBuilder.cs
+++ b/src/EFCore.InMemory/Metadata/Conventions/InMemoryConventionSetBuilder.cs
@@ -8,6 +8,8 @@
using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure;
using Microsoft.Extensions.DependencyInjection;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.InMemory.Metadata.Conventions
{
///
@@ -58,7 +60,7 @@ public override ConventionSet CreateConventionSet()
public static ConventionSet Build()
{
using var serviceScope = CreateServiceScope();
- using var context = serviceScope.ServiceProvider.GetService();
+ using var context = serviceScope.ServiceProvider.GetRequiredService();
return ConventionSet.CreateConventionSet(context);
}
@@ -75,7 +77,7 @@ public static ConventionSet Build()
public static ModelBuilder CreateModelBuilder()
{
using var serviceScope = CreateServiceScope();
- using var context = serviceScope.ServiceProvider.GetService();
+ using var context = serviceScope.ServiceProvider.GetRequiredService();
return new ModelBuilder(ConventionSet.CreateConventionSet(context), context.GetService());
}
diff --git a/src/EFCore.InMemory/Query/Internal/EntityProjectionExpression.cs b/src/EFCore.InMemory/Query/Internal/EntityProjectionExpression.cs
index f72a15f02cb..198ecb25e38 100644
--- a/src/EFCore.InMemory/Query/Internal/EntityProjectionExpression.cs
+++ b/src/EFCore.InMemory/Query/Internal/EntityProjectionExpression.cs
@@ -57,7 +57,7 @@ public EntityProjectionExpression(
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
public override Type Type
- => EntityType.ClrType!;
+ => EntityType.ClrType;
///
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
diff --git a/src/EFCore.InMemory/Query/Internal/InMemoryExpressionTranslatingExpressionVisitor.cs b/src/EFCore.InMemory/Query/Internal/InMemoryExpressionTranslatingExpressionVisitor.cs
index 56699d24a69..eedee36d22a 100644
--- a/src/EFCore.InMemory/Query/Internal/InMemoryExpressionTranslatingExpressionVisitor.cs
+++ b/src/EFCore.InMemory/Query/Internal/InMemoryExpressionTranslatingExpressionVisitor.cs
@@ -1335,7 +1335,7 @@ when methodCallExpression.Method.IsGenericMethod
var parameterName = methodCallExpression.Arguments[1].GetConstantValue();
var lambda = Expression.Lambda(
Expression.Call(
- _parameterListValueExtractor.MakeGenericMethod(entityType.ClrType!, property.ClrType.MakeNullable()),
+ _parameterListValueExtractor.MakeGenericMethod(entityType.ClrType, property.ClrType.MakeNullable()),
QueryCompilationContext.QueryContextParameter,
Expression.Constant(parameterName, typeof(string)),
Expression.Constant(property, typeof(IProperty))),
@@ -1728,8 +1728,7 @@ private EntityReferenceExpression(EntityReferenceExpression entityReferenceExpre
public IEntityType EntityType { get; }
public override Type Type
- // No shadow entities at runtime
- => EntityType.ClrType!;
+ => EntityType.ClrType;
public override ExpressionType NodeType
=> ExpressionType.Extension;
diff --git a/src/EFCore.InMemory/Query/Internal/InMemoryQueryExpression.cs b/src/EFCore.InMemory/Query/Internal/InMemoryQueryExpression.cs
index 0ba21736128..60bf77b3c4f 100644
--- a/src/EFCore.InMemory/Query/Internal/InMemoryQueryExpression.cs
+++ b/src/EFCore.InMemory/Query/Internal/InMemoryQueryExpression.cs
@@ -237,7 +237,7 @@ public virtual int AddToProjection([NotNull] Expression expression)
///
public virtual int AddSubqueryProjection(
[NotNull] ShapedQueryExpression shapedQueryExpression,
- [CanBeNull] out Expression innerShaper)
+ [NotNull] out Expression innerShaper)
{
var subquery = (InMemoryQueryExpression)shapedQueryExpression.QueryExpression;
subquery.ApplyProjection();
@@ -698,7 +698,7 @@ public virtual void AddInnerJoin(
[NotNull] InMemoryQueryExpression innerQueryExpression,
[NotNull] LambdaExpression outerKeySelector,
[NotNull] LambdaExpression innerKeySelector,
- [CanBeNull] Type transparentIdentifierType)
+ [NotNull] Type transparentIdentifierType)
{
var outerParameter = Parameter(typeof(ValueBuffer), "outer");
var innerParameter = Parameter(typeof(ValueBuffer), "inner");
@@ -790,7 +790,7 @@ public virtual void AddLeftJoin(
[NotNull] InMemoryQueryExpression innerQueryExpression,
[NotNull] LambdaExpression outerKeySelector,
[NotNull] LambdaExpression innerKeySelector,
- [CanBeNull] Type transparentIdentifierType)
+ [NotNull] Type transparentIdentifierType)
{
// GroupJoin phase
var groupTransparentIdentifierType = TransparentIdentifierFactory.Create(
@@ -938,7 +938,7 @@ EntityProjectionExpression CopyEntityProjectionToOuter(EntityProjectionExpressio
///
public virtual void AddSelectMany(
[NotNull] InMemoryQueryExpression innerQueryExpression,
- [CanBeNull] Type transparentIdentifierType,
+ [NotNull] Type transparentIdentifierType,
bool innerNullable)
{
var outerParameter = Parameter(typeof(ValueBuffer), "outer");
diff --git a/src/EFCore.InMemory/Query/Internal/InMemoryShapedQueryCompilingExpressionVisitor.CustomShaperCompilingExpressionVisitor.cs b/src/EFCore.InMemory/Query/Internal/InMemoryShapedQueryCompilingExpressionVisitor.CustomShaperCompilingExpressionVisitor.cs
index a380edbd329..5135e4c3472 100644
--- a/src/EFCore.InMemory/Query/Internal/InMemoryShapedQueryCompilingExpressionVisitor.CustomShaperCompilingExpressionVisitor.cs
+++ b/src/EFCore.InMemory/Query/Internal/InMemoryShapedQueryCompilingExpressionVisitor.CustomShaperCompilingExpressionVisitor.cs
@@ -157,9 +157,9 @@ protected override Expression VisitExtension(Expression extensionExpression)
if (extensionExpression is IncludeExpression includeExpression)
{
var entityClrType = includeExpression.EntityExpression.Type;
- var includingClrType = includeExpression.Navigation.DeclaringEntityType.ClrType!;
+ var includingClrType = includeExpression.Navigation.DeclaringEntityType.ClrType;
var inverseNavigation = includeExpression.Navigation.Inverse;
- var relatedEntityClrType = includeExpression.Navigation.TargetEntityType.ClrType!;
+ var relatedEntityClrType = includeExpression.Navigation.TargetEntityType.ClrType;
if (includingClrType != entityClrType
&& includingClrType.IsAssignableFrom(entityClrType))
{
diff --git a/src/EFCore.InMemory/Query/Internal/ShaperExpressionProcessingExpressionVisitor.cs b/src/EFCore.InMemory/Query/Internal/ShaperExpressionProcessingExpressionVisitor.cs
index ecf886590f6..48423552517 100644
--- a/src/EFCore.InMemory/Query/Internal/ShaperExpressionProcessingExpressionVisitor.cs
+++ b/src/EFCore.InMemory/Query/Internal/ShaperExpressionProcessingExpressionVisitor.cs
@@ -78,7 +78,7 @@ protected override Expression VisitExtension(Expression extensionExpression)
var key = GenerateKey((ProjectionBindingExpression)entityShaperExpression.ValueBufferExpression);
if (!_mapping.TryGetValue(key, out var variable))
{
- variable = Expression.Parameter(entityShaperExpression.EntityType.ClrType!);
+ variable = Expression.Parameter(entityShaperExpression.EntityType.ClrType);
_variables.Add(variable);
_expressions.Add(Expression.Assign(variable, entityShaperExpression));
_mapping[key] = variable;
diff --git a/src/EFCore.InMemory/Storage/Internal/InMemoryTypeMapping.cs b/src/EFCore.InMemory/Storage/Internal/InMemoryTypeMapping.cs
index 8aaf0412724..f2f284f2e24 100644
--- a/src/EFCore.InMemory/Storage/Internal/InMemoryTypeMapping.cs
+++ b/src/EFCore.InMemory/Storage/Internal/InMemoryTypeMapping.cs
@@ -7,6 +7,8 @@
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.InMemory.Storage.Internal
{
///
@@ -25,8 +27,8 @@ public class InMemoryTypeMapping : CoreTypeMapping
///
public InMemoryTypeMapping(
[NotNull] Type clrType,
- [CanBeNull] ValueComparer comparer = null,
- [CanBeNull] ValueComparer keyComparer = null)
+ [CanBeNull] ValueComparer? comparer = null,
+ [CanBeNull] ValueComparer? keyComparer = null)
: base(
new CoreTypeMappingParameters(
clrType,
@@ -47,7 +49,7 @@ private InMemoryTypeMapping(CoreTypeMappingParameters parameters)
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
- public override CoreTypeMapping Clone(ValueConverter converter)
+ public override CoreTypeMapping Clone(ValueConverter? converter)
=> new InMemoryTypeMapping(Parameters.WithComposedConverter(converter));
}
}
diff --git a/src/EFCore.Relational/Extensions/RelationalEntityTypeBuilderExtensions.cs b/src/EFCore.Relational/Extensions/RelationalEntityTypeBuilderExtensions.cs
index 2a0b7530109..c6120b98439 100644
--- a/src/EFCore.Relational/Extensions/RelationalEntityTypeBuilderExtensions.cs
+++ b/src/EFCore.Relational/Extensions/RelationalEntityTypeBuilderExtensions.cs
@@ -9,6 +9,9 @@
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using Microsoft.EntityFrameworkCore.Utilities;
+using CA = System.Diagnostics.CodeAnalysis;
+
+#nullable enable
// ReSharper disable once CheckNamespace
namespace Microsoft.EntityFrameworkCore
@@ -26,8 +29,8 @@ public static class RelationalEntityTypeBuilderExtensions
/// The same builder instance so that multiple calls can be chained.
public static EntityTypeBuilder ToTable(
[NotNull] this EntityTypeBuilder entityTypeBuilder,
- [CanBeNull] string name)
- => entityTypeBuilder.ToTable(name, (string)null);
+ [CanBeNull] string? name)
+ => entityTypeBuilder.ToTable(name, (string?)null);
///
/// Configures the table that the entity type maps to when targeting a relational database.
@@ -38,7 +41,7 @@ public static EntityTypeBuilder ToTable(
/// The same builder instance so that multiple calls can be chained.
public static EntityTypeBuilder ToTable(
[NotNull] this EntityTypeBuilder entityTypeBuilder,
- [CanBeNull] string name,
+ [NotNull] string name,
[NotNull] Action buildAction)
=> entityTypeBuilder.ToTable(name, null, buildAction);
@@ -51,9 +54,9 @@ public static EntityTypeBuilder ToTable(
/// The same builder instance so that multiple calls can be chained.
public static EntityTypeBuilder ToTable(
[NotNull] this EntityTypeBuilder entityTypeBuilder,
- [CanBeNull] string name)
+ [CanBeNull] string? name)
where TEntity : class
- => entityTypeBuilder.ToTable(name, (string)null);
+ => entityTypeBuilder.ToTable(name, (string?)null);
///
/// Configures the table that the entity type maps to when targeting a relational database.
@@ -65,7 +68,7 @@ public static EntityTypeBuilder ToTable(
/// The same builder instance so that multiple calls can be chained.
public static EntityTypeBuilder ToTable(
[NotNull] this EntityTypeBuilder entityTypeBuilder,
- [CanBeNull] string name,
+ [NotNull] string name,
[NotNull] Action buildAction)
where TEntity : class
=> entityTypeBuilder.ToTable(name, null, buildAction);
@@ -80,7 +83,7 @@ public static EntityTypeBuilder ToTable(
/// The same builder instance so that multiple calls can be chained.
public static EntityTypeBuilder ToTable(
[NotNull] this EntityTypeBuilder entityTypeBuilder,
- [CanBeNull] string name,
+ [NotNull] string name,
[NotNull] Action> buildAction)
where TEntity : class
=> entityTypeBuilder.ToTable(name, null, buildAction);
@@ -94,8 +97,8 @@ public static EntityTypeBuilder ToTable(
/// The same builder instance so that multiple calls can be chained.
public static EntityTypeBuilder ToTable(
[NotNull] this EntityTypeBuilder entityTypeBuilder,
- [CanBeNull] string name,
- [CanBeNull] string schema)
+ [CanBeNull] string? name,
+ [CanBeNull] string? schema)
{
entityTypeBuilder.Metadata.SetTableName(name);
entityTypeBuilder.Metadata.SetSchema(schema);
@@ -113,7 +116,7 @@ public static EntityTypeBuilder ToTable(
public static EntityTypeBuilder ToTable(
[NotNull] this EntityTypeBuilder entityTypeBuilder,
[NotNull] string name,
- [CanBeNull] string schema,
+ [CanBeNull] string? schema,
[NotNull] Action buildAction)
{
Check.NotNull(name, nameof(name));
@@ -138,7 +141,7 @@ public static EntityTypeBuilder ToTable(
public static EntityTypeBuilder ToTable(
[NotNull] this EntityTypeBuilder entityTypeBuilder,
[NotNull] string name,
- [CanBeNull] string schema,
+ [CanBeNull] string? schema,
[NotNull] Action buildAction)
where TEntity : class
=> (EntityTypeBuilder)((EntityTypeBuilder)entityTypeBuilder).ToTable(name, schema, buildAction);
@@ -153,8 +156,8 @@ public static EntityTypeBuilder ToTable(
/// The same builder instance so that multiple calls can be chained.
public static EntityTypeBuilder ToTable(
[NotNull] this EntityTypeBuilder entityTypeBuilder,
- [CanBeNull] string name,
- [CanBeNull] string schema)
+ [CanBeNull] string? name,
+ [CanBeNull] string? schema)
where TEntity : class
{
entityTypeBuilder.Metadata.SetTableName(name);
@@ -173,8 +176,8 @@ public static EntityTypeBuilder ToTable(
/// The same builder instance so that multiple calls can be chained.
public static EntityTypeBuilder ToTable(
[NotNull] this EntityTypeBuilder entityTypeBuilder,
- [CanBeNull] string name,
- [CanBeNull] string schema,
+ [NotNull] string name,
+ [CanBeNull] string? schema,
[NotNull] Action> buildAction)
where TEntity : class
{
@@ -196,7 +199,7 @@ public static EntityTypeBuilder ToTable(
/// The same builder instance so that multiple calls can be chained.
public static OwnedNavigationBuilder ToTable(
[NotNull] this OwnedNavigationBuilder referenceOwnershipBuilder,
- [CanBeNull] string name)
+ [CanBeNull] string? name)
=> ToTable(referenceOwnershipBuilder, name, schema: null, excludedFromMigrations: null);
///
@@ -208,7 +211,7 @@ public static OwnedNavigationBuilder ToTable(
/// The same builder instance so that multiple calls can be chained.
public static OwnedNavigationBuilder ToTable(
[NotNull] this OwnedNavigationBuilder referenceOwnershipBuilder,
- [CanBeNull] string name,
+ [CanBeNull] string? name,
bool excludedFromMigrations)
=> referenceOwnershipBuilder.ToTable(name, null, excludedFromMigrations);
@@ -222,7 +225,7 @@ public static OwnedNavigationBuilder ToTable(
/// The same builder instance so that multiple calls can be chained.
public static OwnedNavigationBuilder ToTable(
[NotNull] this OwnedNavigationBuilder referenceOwnershipBuilder,
- [CanBeNull] string name)
+ [CanBeNull] string? name)
where TEntity : class
where TRelatedEntity : class
=> (OwnedNavigationBuilder)ToTable(
@@ -239,7 +242,7 @@ public static OwnedNavigationBuilder ToTable The same builder instance so that multiple calls can be chained.
public static OwnedNavigationBuilder ToTable(
[NotNull] this OwnedNavigationBuilder referenceOwnershipBuilder,
- [CanBeNull] string name,
+ [CanBeNull] string? name,
bool excludedFromMigrations)
where TEntity : class
where TRelatedEntity : class
@@ -255,8 +258,8 @@ public static OwnedNavigationBuilder ToTable The same builder instance so that multiple calls can be chained.
public static OwnedNavigationBuilder ToTable(
[NotNull] this OwnedNavigationBuilder referenceOwnershipBuilder,
- [CanBeNull] string name,
- [CanBeNull] string schema)
+ [CanBeNull] string? name,
+ [CanBeNull] string? schema)
=> ToTable(referenceOwnershipBuilder, name, schema, excludedFromMigrations: null);
///
@@ -269,8 +272,8 @@ public static OwnedNavigationBuilder ToTable(
/// The same builder instance so that multiple calls can be chained.
public static OwnedNavigationBuilder ToTable(
[NotNull] this OwnedNavigationBuilder referenceOwnershipBuilder,
- [CanBeNull] string name,
- [CanBeNull] string schema,
+ [CanBeNull] string? name,
+ [CanBeNull] string? schema,
bool excludedFromMigrations)
{
Check.NotNull(referenceOwnershipBuilder, nameof(referenceOwnershipBuilder));
@@ -282,8 +285,8 @@ public static OwnedNavigationBuilder ToTable(
private static OwnedNavigationBuilder ToTable(
OwnedNavigationBuilder referenceOwnershipBuilder,
- string name,
- string schema,
+ string? name,
+ string? schema,
bool? excludedFromMigrations)
{
referenceOwnershipBuilder.OwnedEntityType.SetTableName(name);
@@ -308,8 +311,8 @@ private static OwnedNavigationBuilder ToTable(
/// The same builder instance so that multiple calls can be chained.
public static OwnedNavigationBuilder ToTable(
[NotNull] this OwnedNavigationBuilder referenceOwnershipBuilder,
- [CanBeNull] string name,
- [CanBeNull] string schema)
+ [CanBeNull] string? name,
+ [CanBeNull] string? schema)
where TEntity : class
where TRelatedEntity : class
=> (OwnedNavigationBuilder)ToTable(
@@ -327,8 +330,8 @@ public static OwnedNavigationBuilder ToTable The same builder instance so that multiple calls can be chained.
public static OwnedNavigationBuilder ToTable(
[NotNull] this OwnedNavigationBuilder referenceOwnershipBuilder,
- [CanBeNull] string name,
- [CanBeNull] string schema,
+ [CanBeNull] string? name,
+ [CanBeNull] string? schema,
bool excludedFromMigrations)
where TEntity : class
where TRelatedEntity : class
@@ -344,9 +347,9 @@ public static OwnedNavigationBuilder ToTable
/// The same builder instance if the configuration was applied, otherwise.
///
- public static IConventionEntityTypeBuilder ToTable(
+ public static IConventionEntityTypeBuilder? ToTable(
[NotNull] this IConventionEntityTypeBuilder entityTypeBuilder,
- [CanBeNull] string name,
+ [CanBeNull] string? name,
bool fromDataAnnotation = false)
{
if (!entityTypeBuilder.CanSetTable(name, fromDataAnnotation))
@@ -368,10 +371,10 @@ public static IConventionEntityTypeBuilder ToTable(
///
/// The same builder instance if the configuration was applied, otherwise.
///
- public static IConventionEntityTypeBuilder ToTable(
+ public static IConventionEntityTypeBuilder? ToTable(
[NotNull] this IConventionEntityTypeBuilder entityTypeBuilder,
- [CanBeNull] string name,
- [CanBeNull] string schema,
+ [CanBeNull] string? name,
+ [CanBeNull] string? schema,
bool fromDataAnnotation = false)
{
if (!entityTypeBuilder.CanSetTable(name, fromDataAnnotation)
@@ -395,7 +398,7 @@ public static IConventionEntityTypeBuilder ToTable(
/// if the configuration can be applied.
public static bool CanSetTable(
[NotNull] this IConventionEntityTypeBuilder entityTypeBuilder,
- [CanBeNull] string name,
+ [CanBeNull] string? name,
bool fromDataAnnotation = false)
{
Check.NullButNotEmpty(name, nameof(name));
@@ -412,9 +415,9 @@ public static bool CanSetTable(
///
/// The same builder instance if the configuration was applied, otherwise.
///
- public static IConventionEntityTypeBuilder ToSchema(
+ public static IConventionEntityTypeBuilder? ToSchema(
[NotNull] this IConventionEntityTypeBuilder entityTypeBuilder,
- [CanBeNull] string schema,
+ [CanBeNull] string? schema,
bool fromDataAnnotation = false)
{
if (!entityTypeBuilder.CanSetSchema(schema, fromDataAnnotation))
@@ -436,7 +439,7 @@ public static IConventionEntityTypeBuilder ToSchema(
/// if the configuration can be applied.
public static bool CanSetSchema(
[NotNull] this IConventionEntityTypeBuilder entityTypeBuilder,
- [CanBeNull] string schema,
+ [CanBeNull] string? schema,
bool fromDataAnnotation = false)
{
Check.NullButNotEmpty(schema, nameof(schema));
@@ -454,7 +457,7 @@ public static bool CanSetSchema(
/// The same builder instance if the configuration was applied,
/// otherwise.
///
- public static IConventionEntityTypeBuilder ExcludeTableFromMigrations(
+ public static IConventionEntityTypeBuilder? ExcludeTableFromMigrations(
[NotNull] this IConventionEntityTypeBuilder entityTypeBuilder,
bool? excludedFromMigrations,
bool fromDataAnnotation = false)
@@ -491,7 +494,7 @@ public static bool CanExcludeTableFromMigrations(
/// The same builder instance so that multiple calls can be chained.
public static EntityTypeBuilder ToView(
[NotNull] this EntityTypeBuilder entityTypeBuilder,
- [CanBeNull] string name)
+ [CanBeNull] string? name)
=> entityTypeBuilder.ToView(name, null);
///
@@ -503,7 +506,7 @@ public static EntityTypeBuilder ToView(
/// The same builder instance so that multiple calls can be chained.
public static EntityTypeBuilder ToView(
[NotNull] this EntityTypeBuilder entityTypeBuilder,
- [CanBeNull] string name)
+ [CanBeNull] string? name)
where TEntity : class
=> (EntityTypeBuilder)ToView((EntityTypeBuilder)entityTypeBuilder, name);
@@ -516,8 +519,8 @@ public static EntityTypeBuilder ToView(
/// The same builder instance so that multiple calls can be chained.
public static EntityTypeBuilder ToView(
[NotNull] this EntityTypeBuilder entityTypeBuilder,
- [CanBeNull] string name,
- [CanBeNull] string schema)
+ [CanBeNull] string? name,
+ [CanBeNull] string? schema)
{
Check.NotNull(entityTypeBuilder, nameof(entityTypeBuilder));
Check.NullButNotEmpty(name, nameof(name));
@@ -540,8 +543,8 @@ public static EntityTypeBuilder ToView(
/// The same builder instance so that multiple calls can be chained.
public static EntityTypeBuilder ToView(
[NotNull] this EntityTypeBuilder entityTypeBuilder,
- [CanBeNull] string name,
- [CanBeNull] string schema)
+ [CanBeNull] string? name,
+ [CanBeNull] string? schema)
where TEntity : class
=> (EntityTypeBuilder)ToView((EntityTypeBuilder)entityTypeBuilder, name, schema);
@@ -554,9 +557,9 @@ public static EntityTypeBuilder ToView(
///
/// The same builder instance if the configuration was applied, otherwise.
///
- public static IConventionEntityTypeBuilder ToView(
+ public static IConventionEntityTypeBuilder? ToView(
[NotNull] this IConventionEntityTypeBuilder entityTypeBuilder,
- [CanBeNull] string name,
+ [CanBeNull] string? name,
bool fromDataAnnotation = false)
{
if (!entityTypeBuilder.CanSetView(name, fromDataAnnotation))
@@ -578,10 +581,10 @@ public static IConventionEntityTypeBuilder ToView(
///
/// The same builder instance if the configuration was applied, otherwise.
///
- public static IConventionEntityTypeBuilder ToView(
+ public static IConventionEntityTypeBuilder? ToView(
[NotNull] this IConventionEntityTypeBuilder entityTypeBuilder,
- [CanBeNull] string name,
- [CanBeNull] string schema,
+ [CanBeNull] string? name,
+ [CanBeNull] string? schema,
bool fromDataAnnotation = false)
{
if (!entityTypeBuilder.CanSetView(name, fromDataAnnotation)
@@ -605,7 +608,7 @@ public static IConventionEntityTypeBuilder ToView(
/// if the configuration can be applied.
public static bool CanSetView(
[NotNull] this IConventionEntityTypeBuilder entityTypeBuilder,
- [CanBeNull] string name,
+ [CanBeNull] string? name,
bool fromDataAnnotation = false)
{
Check.NullButNotEmpty(name, nameof(name));
@@ -622,9 +625,9 @@ public static bool CanSetView(
///
/// The same builder instance if the configuration was applied, otherwise.
///
- public static IConventionEntityTypeBuilder ToViewSchema(
+ public static IConventionEntityTypeBuilder? ToViewSchema(
[NotNull] this IConventionEntityTypeBuilder entityTypeBuilder,
- [CanBeNull] string schema,
+ [CanBeNull] string? schema,
bool fromDataAnnotation = false)
{
if (!entityTypeBuilder.CanSetSchema(schema, fromDataAnnotation))
@@ -646,7 +649,7 @@ public static IConventionEntityTypeBuilder ToViewSchema(
/// if the configuration can be applied.
public static bool CanSetViewSchema(
[NotNull] this IConventionEntityTypeBuilder entityTypeBuilder,
- [CanBeNull] string schema,
+ [CanBeNull] string? schema,
bool fromDataAnnotation = false)
{
Check.NullButNotEmpty(schema, nameof(schema));
@@ -681,9 +684,9 @@ public static EntityTypeBuilder ToSqlQuery(
///
/// The same builder instance if the configuration was applied, otherwise.
///
- public static IConventionEntityTypeBuilder ToSqlQuery(
+ public static IConventionEntityTypeBuilder? ToSqlQuery(
[NotNull] this IConventionEntityTypeBuilder entityTypeBuilder,
- [CanBeNull] string name,
+ [CanBeNull] string? name,
bool fromDataAnnotation = false)
{
if (!entityTypeBuilder.CanSetSqlQuery(name, fromDataAnnotation))
@@ -707,7 +710,7 @@ public static IConventionEntityTypeBuilder ToSqlQuery(
/// if the configuration can be applied.
public static bool CanSetSqlQuery(
[NotNull] this IConventionEntityTypeBuilder entityTypeBuilder,
- [CanBeNull] string name,
+ [CanBeNull] string? name,
bool fromDataAnnotation = false)
{
Check.NullButNotEmpty(name, nameof(name));
@@ -723,12 +726,12 @@ public static bool CanSetSqlQuery(
/// The function configuration builder.
public static EntityTypeBuilder ToFunction(
[NotNull] this EntityTypeBuilder entityTypeBuilder,
- [CanBeNull] string name)
+ [CanBeNull] string? name)
{
Check.NotNull(entityTypeBuilder, nameof(entityTypeBuilder));
Check.NullButNotEmpty(name, nameof(name));
- CreateFunction(name, entityTypeBuilder.Metadata);
+ SetFunction(name, entityTypeBuilder.Metadata);
return entityTypeBuilder;
}
@@ -742,14 +745,14 @@ public static EntityTypeBuilder ToFunction(
/// The same builder instance so that multiple calls can be chained.
public static EntityTypeBuilder ToFunction(
[NotNull] this EntityTypeBuilder entityTypeBuilder,
- [CanBeNull] string name,
+ [NotNull] string name,
[NotNull] Action configureFunction)
{
Check.NotNull(entityTypeBuilder, nameof(entityTypeBuilder));
Check.NullButNotEmpty(name, nameof(name));
Check.NotNull(configureFunction, nameof(configureFunction));
- configureFunction(new TableValuedFunctionBuilder(CreateFunction(name, entityTypeBuilder.Metadata)));
+ configureFunction(new TableValuedFunctionBuilder(SetFunction(name, entityTypeBuilder.Metadata)));
return entityTypeBuilder;
}
@@ -763,7 +766,7 @@ public static EntityTypeBuilder ToFunction(
/// The function configuration builder.
public static EntityTypeBuilder ToFunction(
[NotNull] this EntityTypeBuilder entityTypeBuilder,
- [CanBeNull] string name)
+ [CanBeNull] string? name)
where TEntity : class
=> (EntityTypeBuilder)ToFunction((EntityTypeBuilder)entityTypeBuilder, name);
@@ -777,7 +780,7 @@ public static EntityTypeBuilder ToFunction(
/// The same builder instance so that multiple calls can be chained.
public static EntityTypeBuilder ToFunction(
[NotNull] this EntityTypeBuilder entityTypeBuilder,
- [CanBeNull] string name,
+ [NotNull] string name,
[NotNull] Action configureFunction)
where TEntity : class
=> (EntityTypeBuilder)ToFunction((EntityTypeBuilder)entityTypeBuilder, name, configureFunction);
@@ -790,12 +793,12 @@ public static EntityTypeBuilder ToFunction(
/// The function configuration builder.
public static OwnedNavigationBuilder ToFunction(
[NotNull] this OwnedNavigationBuilder ownedNavigationBuilder,
- [CanBeNull] string name)
+ [CanBeNull] string? name)
{
Check.NotNull(ownedNavigationBuilder, nameof(ownedNavigationBuilder));
Check.NullButNotEmpty(name, nameof(name));
- CreateFunction(name, ownedNavigationBuilder.OwnedEntityType);
+ SetFunction(name, ownedNavigationBuilder.OwnedEntityType);
return ownedNavigationBuilder;
}
@@ -809,14 +812,14 @@ public static OwnedNavigationBuilder ToFunction(
/// The same builder instance so that multiple calls can be chained.
public static OwnedNavigationBuilder ToFunction(
[NotNull] this OwnedNavigationBuilder ownedNavigationBuilder,
- [CanBeNull] string name,
+ [NotNull] string name,
[NotNull] Action configureFunction)
{
Check.NotNull(ownedNavigationBuilder, nameof(ownedNavigationBuilder));
Check.NullButNotEmpty(name, nameof(name));
Check.NotNull(configureFunction, nameof(configureFunction));
- configureFunction(new TableValuedFunctionBuilder(CreateFunction(name, ownedNavigationBuilder.OwnedEntityType)));
+ configureFunction(new TableValuedFunctionBuilder(SetFunction(name, ownedNavigationBuilder.OwnedEntityType)));
return ownedNavigationBuilder;
}
@@ -831,7 +834,7 @@ public static OwnedNavigationBuilder ToFunction(
/// The function configuration builder.
public static OwnedNavigationBuilder ToFunction(
[NotNull] this OwnedNavigationBuilder referenceOwnershipBuilder,
- [CanBeNull] string name)
+ [CanBeNull] string? name)
where TEntity : class
where TRelatedEntity : class
=> (OwnedNavigationBuilder)ToFunction((OwnedNavigationBuilder)referenceOwnershipBuilder, name);
@@ -847,21 +850,23 @@ public static OwnedNavigationBuilder ToFunction The same builder instance so that multiple calls can be chained.
public static OwnedNavigationBuilder ToFunction(
[NotNull] this OwnedNavigationBuilder referenceOwnershipBuilder,
- [CanBeNull] string name,
+ [NotNull] string name,
[NotNull] Action configureFunction)
where TEntity : class
where TRelatedEntity : class
=> (OwnedNavigationBuilder)ToFunction(
(OwnedNavigationBuilder)referenceOwnershipBuilder, name, configureFunction);
- private static IMutableDbFunction CreateFunction(string name, IMutableEntityType entityType)
+ [return: CA.NotNullIfNotNull("name")]
+ private static IMutableDbFunction? SetFunction(string? name, IMutableEntityType entityType)
{
entityType.SetFunctionName(name);
var model = entityType.Model;
- var function = model.FindDbFunction(name)
- ?? model.AddDbFunction(
- name, typeof(IQueryable<>).MakeGenericType(entityType.ClrType ?? typeof(Dictionary)));
+ var function = name is not null
+ ? model.FindDbFunction(name) ?? model.AddDbFunction(
+ name, typeof(IQueryable<>).MakeGenericType(entityType.ClrType ?? typeof(Dictionary)))
+ : null;
return function;
}
@@ -876,9 +881,9 @@ private static IMutableDbFunction CreateFunction(string name, IMutableEntityType
/// The same builder instance if the configuration was applied,
/// otherwise.
///
- public static IConventionEntityTypeBuilder ToFunction(
+ public static IConventionEntityTypeBuilder? ToFunction(
[NotNull] this IConventionEntityTypeBuilder entityTypeBuilder,
- [CanBeNull] string name,
+ [CanBeNull] string? name,
bool fromDataAnnotation = false)
{
if (!entityTypeBuilder.CanSetFunction(name, fromDataAnnotation))
@@ -889,7 +894,10 @@ public static IConventionEntityTypeBuilder ToFunction(
var entityType = entityTypeBuilder.Metadata;
entityType.SetFunctionName(name, fromDataAnnotation);
- entityType.Model.Builder.HasDbFunction(name, typeof(IQueryable<>).MakeGenericType(entityType.ClrType), fromDataAnnotation);
+ if (name is null)
+ {
+ entityType.Model.Builder.HasDbFunction(name, typeof(IQueryable<>).MakeGenericType(entityType.ClrType), fromDataAnnotation);
+ }
return entityTypeBuilder;
}
@@ -904,7 +912,7 @@ public static IConventionEntityTypeBuilder ToFunction(
/// if the configuration can be applied.
public static bool CanSetFunction(
[NotNull] this IConventionEntityTypeBuilder entityTypeBuilder,
- [CanBeNull] string name,
+ [CanBeNull] string? name,
bool fromDataAnnotation = false)
{
Check.NullButNotEmpty(name, nameof(name));
@@ -922,7 +930,7 @@ public static bool CanSetFunction(
public static EntityTypeBuilder HasCheckConstraint(
[NotNull] this EntityTypeBuilder entityTypeBuilder,
[NotNull] string name,
- [CanBeNull] string sql)
+ [CanBeNull] string? sql)
{
Check.NotNull(entityTypeBuilder, nameof(entityTypeBuilder));
Check.NotEmpty(name, nameof(name));
@@ -961,7 +969,7 @@ public static EntityTypeBuilder HasCheckConstraint(
public static EntityTypeBuilder HasCheckConstraint(
[NotNull] this EntityTypeBuilder entityTypeBuilder,
[NotNull] string name,
- [CanBeNull] string sql)
+ [CanBeNull] string? sql)
where TEntity : class
=> (EntityTypeBuilder)HasCheckConstraint((EntityTypeBuilder)entityTypeBuilder, name, sql);
@@ -976,10 +984,10 @@ public static EntityTypeBuilder HasCheckConstraint(
/// The same builder instance if the check constraint was configured,
/// otherwise.
///
- public static IConventionEntityTypeBuilder HasCheckConstraint(
+ public static IConventionEntityTypeBuilder? HasCheckConstraint(
[NotNull] this IConventionEntityTypeBuilder entityTypeBuilder,
[NotNull] string name,
- [CanBeNull] string sql,
+ [CanBeNull] string? sql,
bool fromDataAnnotation = false)
{
Check.NotNull(entityTypeBuilder, nameof(entityTypeBuilder));
@@ -1026,7 +1034,7 @@ public static IConventionEntityTypeBuilder HasCheckConstraint(
public static bool CanSetCheckConstraint(
[NotNull] this IConventionEntityTypeBuilder entityTypeBuilder,
[NotNull] string name,
- [CanBeNull] string sql,
+ [CanBeNull] string? sql,
bool fromDataAnnotation = false)
{
Check.NotNull(entityTypeBuilder, nameof(entityTypeBuilder));
@@ -1049,7 +1057,7 @@ public static bool CanSetCheckConstraint(
/// A builder to further configure the entity type.
public static EntityTypeBuilder HasComment(
[NotNull] this EntityTypeBuilder entityTypeBuilder,
- [CanBeNull] string comment)
+ [CanBeNull] string? comment)
{
Check.NotNull(entityTypeBuilder, nameof(entityTypeBuilder));
@@ -1066,7 +1074,7 @@ public static EntityTypeBuilder HasComment(
/// A builder to further configure the entity type.
public static EntityTypeBuilder HasComment(
[NotNull] this EntityTypeBuilder entityTypeBuilder,
- [CanBeNull] string comment)
+ [CanBeNull] string? comment)
where TEntity : class
=> (EntityTypeBuilder)HasComment((EntityTypeBuilder)entityTypeBuilder, comment);
@@ -1080,9 +1088,9 @@ public static EntityTypeBuilder HasComment(
/// The same builder instance if the configuration was applied,
/// otherwise.
///
- public static IConventionEntityTypeBuilder HasComment(
+ public static IConventionEntityTypeBuilder? HasComment(
[NotNull] this IConventionEntityTypeBuilder entityTypeBuilder,
- [CanBeNull] string comment,
+ [CanBeNull] string? comment,
bool fromDataAnnotation = false)
{
Check.NotNull(entityTypeBuilder, nameof(entityTypeBuilder));
@@ -1106,7 +1114,7 @@ public static IConventionEntityTypeBuilder HasComment(
/// if the configuration can be applied.
public static bool CanSetComment(
[NotNull] this IConventionEntityTypeBuilder entityTypeBuilder,
- [CanBeNull] string comment,
+ [CanBeNull] string? comment,
bool fromDataAnnotation = false)
=> entityTypeBuilder.CanSetAnnotation(
RelationalAnnotationNames.Comment,
diff --git a/src/EFCore.Relational/Extensions/RelationalEntityTypeExtensions.cs b/src/EFCore.Relational/Extensions/RelationalEntityTypeExtensions.cs
index 167f5cf906a..5fc70755186 100644
--- a/src/EFCore.Relational/Extensions/RelationalEntityTypeExtensions.cs
+++ b/src/EFCore.Relational/Extensions/RelationalEntityTypeExtensions.cs
@@ -10,6 +10,8 @@
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using Microsoft.EntityFrameworkCore.Utilities;
+#nullable enable
+
// ReSharper disable once CheckNamespace
namespace Microsoft.EntityFrameworkCore
{
@@ -24,7 +26,7 @@ public static class RelationalEntityTypeExtensions
///
/// The entity type to get the table name for.
/// The name of the table to which the entity type is mapped.
- public static string GetTableName([NotNull] this IEntityType entityType)
+ public static string? GetTableName([NotNull] this IEntityType entityType)
{
var nameAnnotation = entityType.FindAnnotation(RelationalAnnotationNames.TableName);
if (nameAnnotation != null)
@@ -53,7 +55,7 @@ public static string GetTableName([NotNull] this IEntityType entityType)
/// The entity type to get the table name for.
/// A value indicating whether the name should be truncated to the max identifier length.
/// The default name of the table to which the entity type would be mapped.
- public static string GetDefaultTableName([NotNull] this IEntityType entityType, bool truncate = true)
+ public static string? GetDefaultTableName([NotNull] this IEntityType entityType, bool truncate = true)
{
var ownership = entityType.FindOwnership();
if (ownership != null
@@ -66,7 +68,7 @@ public static string GetDefaultTableName([NotNull] this IEntityType entityType,
if (entityType.HasSharedClrType
&& ownership != null
#pragma warning disable EF1001 // Internal EF Core API usage.
- && entityType.Name == ownership.PrincipalEntityType.GetOwnedName(name, ownership.PrincipalToDependent.Name))
+ && entityType.Name == ownership.PrincipalEntityType.GetOwnedName(name, ownership.PrincipalToDependent!.Name))
#pragma warning restore EF1001 // Internal EF Core API usage.
{
var ownerTypeTable = ownership.PrincipalEntityType.GetTableName();
@@ -85,7 +87,7 @@ public static string GetDefaultTableName([NotNull] this IEntityType entityType,
///
/// The entity type to set the table name for.
/// The name to set.
- public static void SetTableName([NotNull] this IMutableEntityType entityType, [CanBeNull] string name)
+ public static void SetTableName([NotNull] this IMutableEntityType entityType, [CanBeNull] string? name)
=> entityType.SetAnnotation(
RelationalAnnotationNames.TableName,
Check.NullButNotEmpty(name, nameof(name)));
@@ -97,9 +99,9 @@ public static void SetTableName([NotNull] this IMutableEntityType entityType, [C
/// The name to set.
/// Indicates whether the configuration was specified using a data annotation.
/// The configured table name.
- public static string SetTableName(
+ public static string? SetTableName(
[NotNull] this IConventionEntityType entityType,
- [CanBeNull] string name,
+ [CanBeNull] string? name,
bool fromDataAnnotation = false)
{
entityType.SetAnnotation(
@@ -124,12 +126,12 @@ public static string SetTableName(
///
/// The entity type to get the schema for.
/// The database schema that contains the mapped table.
- public static string GetSchema([NotNull] this IEntityType entityType)
+ public static string? GetSchema([NotNull] this IEntityType entityType)
{
var schemaAnnotation = entityType.FindAnnotation(RelationalAnnotationNames.Schema);
if (schemaAnnotation != null)
{
- return (string)schemaAnnotation.Value ?? GetDefaultSchema(entityType);
+ return (string?)schemaAnnotation.Value ?? GetDefaultSchema(entityType);
}
return entityType.BaseType != null
@@ -142,7 +144,7 @@ public static string GetSchema([NotNull] this IEntityType entityType)
///
/// The entity type to get the schema for.
/// The default database schema to which the entity type would be mapped.
- public static string GetDefaultSchema([NotNull] this IEntityType entityType)
+ public static string? GetDefaultSchema([NotNull] this IEntityType entityType)
{
var ownership = entityType.FindOwnership();
if (ownership != null)
@@ -169,7 +171,7 @@ public static string GetDefaultSchema([NotNull] this IEntityType entityType)
///
/// The entity type to set the schema for.
/// The value to set.
- public static void SetSchema([NotNull] this IMutableEntityType entityType, [CanBeNull] string value)
+ public static void SetSchema([NotNull] this IMutableEntityType entityType, [CanBeNull] string? value)
=> entityType.SetAnnotation(
RelationalAnnotationNames.Schema,
Check.NullButNotEmpty(value, nameof(value)));
@@ -181,9 +183,9 @@ public static void SetSchema([NotNull] this IMutableEntityType entityType, [CanB
/// The value to set.
/// Indicates whether the configuration was specified using a data annotation.
/// The configured value.
- public static string SetSchema(
+ public static string? SetSchema(
[NotNull] this IConventionEntityType entityType,
- [CanBeNull] string value,
+ [CanBeNull] string? value,
bool fromDataAnnotation = false)
{
entityType.SetAnnotation(
@@ -209,7 +211,7 @@ public static string SetSchema(
///
/// The entity type to get the table name for.
/// The name of the table to which the entity type is mapped prepended by the schema.
- public static string GetSchemaQualifiedTableName([NotNull] this IEntityType entityType)
+ public static string? GetSchemaQualifiedTableName([NotNull] this IEntityType entityType)
{
var tableName = entityType.GetTableName();
if (tableName == null)
@@ -227,7 +229,7 @@ public static string GetSchemaQualifiedTableName([NotNull] this IEntityType enti
///
/// The entity type to get the table name for.
/// The name of the table to which the entity type is mapped prepended by the schema.
- public static string GetSchemaQualifiedViewName([NotNull] this IEntityType entityType)
+ public static string? GetSchemaQualifiedViewName([NotNull] this IEntityType entityType)
{
var viewName = entityType.GetViewName();
if (viewName == null)
@@ -245,7 +247,7 @@ public static string GetSchemaQualifiedViewName([NotNull] this IEntityType entit
/// The entity type to get the table mappings for.
/// The tables to which the entity type is mapped.
public static IEnumerable GetDefaultMappings([NotNull] this IEntityType entityType)
- => (IEnumerable)entityType[RelationalAnnotationNames.DefaultMappings]
+ => (IEnumerable?)entityType[RelationalAnnotationNames.DefaultMappings]
?? Array.Empty();
///
@@ -254,7 +256,7 @@ public static IEnumerable GetDefaultMappings([NotNull] this I
/// The entity type to get the table mappings for.
/// The tables to which the entity type is mapped.
public static IEnumerable GetTableMappings([NotNull] this IEntityType entityType)
- => (IEnumerable)entityType[RelationalAnnotationNames.TableMappings]
+ => (IEnumerable?)entityType[RelationalAnnotationNames.TableMappings]
?? Array.Empty();
///
@@ -262,9 +264,9 @@ public static IEnumerable GetTableMappings([NotNull] this IEntity
///
/// The entity type to get the view name for.
/// The name of the view to which the entity type is mapped.
- public static string GetViewName([NotNull] this IEntityType entityType)
+ public static string? GetViewName([NotNull] this IEntityType entityType)
{
- var nameAnnotation = (string)entityType[RelationalAnnotationNames.ViewName];
+ var nameAnnotation = (string?)entityType[RelationalAnnotationNames.ViewName];
if (nameAnnotation != null)
{
return nameAnnotation;
@@ -289,7 +291,7 @@ public static string GetViewName([NotNull] this IEntityType entityType)
///
/// The entity type to get the table name for.
/// The default name of the table to which the entity type would be mapped.
- public static string GetDefaultViewName([NotNull] this IEntityType entityType)
+ public static string? GetDefaultViewName([NotNull] this IEntityType entityType)
{
var ownership = entityType.FindOwnership();
return ownership != null
@@ -303,7 +305,7 @@ public static string GetDefaultViewName([NotNull] this IEntityType entityType)
///
/// The entity type to set the view name for.
/// The name to set.
- public static void SetViewName([NotNull] this IMutableEntityType entityType, [CanBeNull] string name)
+ public static void SetViewName([NotNull] this IMutableEntityType entityType, [CanBeNull] string? name)
=> entityType.SetAnnotation(
RelationalAnnotationNames.ViewName,
Check.NullButNotEmpty(name, nameof(name)));
@@ -315,9 +317,9 @@ public static void SetViewName([NotNull] this IMutableEntityType entityType, [Ca
/// The name to set.
/// Indicates whether the configuration was specified using a data annotation.
/// The configured value.
- public static string SetViewName(
+ public static string? SetViewName(
[NotNull] this IConventionEntityType entityType,
- [CanBeNull] string name,
+ [CanBeNull] string? name,
bool fromDataAnnotation = false)
{
entityType.SetAnnotation(
@@ -342,12 +344,12 @@ public static string SetViewName(
///
/// The entity type to get the view schema for.
/// The database schema that contains the mapped view.
- public static string GetViewSchema([NotNull] this IEntityType entityType)
+ public static string? GetViewSchema([NotNull] this IEntityType entityType)
{
var schemaAnnotation = entityType.FindAnnotation(RelationalAnnotationNames.ViewSchema);
if (schemaAnnotation != null)
{
- return (string)schemaAnnotation.Value ?? GetDefaultViewSchema(entityType);
+ return (string?)schemaAnnotation.Value ?? GetDefaultViewSchema(entityType);
}
return entityType.BaseType != null
@@ -360,7 +362,7 @@ public static string GetViewSchema([NotNull] this IEntityType entityType)
///
/// The entity type to get the view schema for.
/// The default database schema to which the entity type would be mapped.
- public static string GetDefaultViewSchema([NotNull] this IEntityType entityType)
+ public static string? GetDefaultViewSchema([NotNull] this IEntityType entityType)
{
var ownership = entityType.FindOwnership();
if (ownership != null
@@ -377,7 +379,7 @@ public static string GetDefaultViewSchema([NotNull] this IEntityType entityType)
///
/// The entity type to set the view schema for.
/// The value to set.
- public static void SetViewSchema([NotNull] this IMutableEntityType entityType, [CanBeNull] string value)
+ public static void SetViewSchema([NotNull] this IMutableEntityType entityType, [CanBeNull] string? value)
=> entityType.SetAnnotation(
RelationalAnnotationNames.ViewSchema,
Check.NullButNotEmpty(value, nameof(value)));
@@ -389,9 +391,9 @@ public static void SetViewSchema([NotNull] this IMutableEntityType entityType, [
/// The value to set.
/// Indicates whether the configuration was specified using a data annotation.
/// The configured schema.
- public static string SetViewSchema(
+ public static string? SetViewSchema(
[NotNull] this IConventionEntityType entityType,
- [CanBeNull] string value,
+ [CanBeNull] string? value,
bool fromDataAnnotation = false)
{
entityType.SetAnnotation(
@@ -417,7 +419,7 @@ public static string SetViewSchema(
/// The entity type to get the view mappings for.
/// The views to which the entity type is mapped.
public static IEnumerable GetViewMappings([NotNull] this IEntityType entityType)
- => (IEnumerable)entityType[RelationalAnnotationNames.ViewMappings]
+ => (IEnumerable?)entityType[RelationalAnnotationNames.ViewMappings]
?? Array.Empty();
///
@@ -434,9 +436,9 @@ public static string GetDefaultSqlQueryName([NotNull] this IEntityType entityTyp
///
/// The entity type.
/// The SQL string used to provide data for the entity type.
- public static string GetSqlQuery([NotNull] this IEntityType entityType)
+ public static string? GetSqlQuery([NotNull] this IEntityType entityType)
{
- var nameAnnotation = (string)entityType[RelationalAnnotationNames.SqlQuery];
+ var nameAnnotation = (string?)entityType[RelationalAnnotationNames.SqlQuery];
if (nameAnnotation != null)
{
return nameAnnotation;
@@ -455,7 +457,7 @@ public static string GetSqlQuery([NotNull] this IEntityType entityType)
///
/// The entity type.
/// The SQL string to set.
- public static void SetSqlQuery([NotNull] this IMutableEntityType entityType, [CanBeNull] string name)
+ public static void SetSqlQuery([NotNull] this IMutableEntityType entityType, [CanBeNull] string? name)
=> entityType.SetAnnotation(
RelationalAnnotationNames.SqlQuery,
Check.NullButNotEmpty(name, nameof(name)));
@@ -467,11 +469,11 @@ public static void SetSqlQuery([NotNull] this IMutableEntityType entityType, [Ca
/// The SQL string to set.
/// Indicates whether the configuration was specified using a data annotation.
/// The configured value.
- public static string SetSqlQuery(
+ public static string? SetSqlQuery(
[NotNull] this IConventionEntityType entityType,
- [CanBeNull] string name,
+ [CanBeNull] string? name,
bool fromDataAnnotation = false)
- => (string)entityType.SetAnnotation(
+ => (string?)entityType.SetAnnotation(
RelationalAnnotationNames.SqlQuery,
Check.NullButNotEmpty(name, nameof(name)),
fromDataAnnotation)?.Value;
@@ -491,7 +493,7 @@ public static string SetSqlQuery(
/// The entity type to get the function mappings for.
/// The functions to which the entity type is mapped.
public static IEnumerable GetSqlQueryMappings([NotNull] this IEntityType entityType)
- => (IEnumerable)entityType[RelationalAnnotationNames.SqlQueryMappings]
+ => (IEnumerable?)entityType[RelationalAnnotationNames.SqlQueryMappings]
?? Array.Empty();
///
@@ -499,9 +501,9 @@ public static IEnumerable GetSqlQueryMappings([NotNull] this I
///
/// The entity type to get the function name for.
/// The name of the function to which the entity type is mapped.
- public static string GetFunctionName([NotNull] this IEntityType entityType)
+ public static string? GetFunctionName([NotNull] this IEntityType entityType)
{
- var nameAnnotation = (string)entityType[RelationalAnnotationNames.FunctionName];
+ var nameAnnotation = (string?)entityType[RelationalAnnotationNames.FunctionName];
if (nameAnnotation != null)
{
return nameAnnotation;
@@ -520,7 +522,7 @@ public static string GetFunctionName([NotNull] this IEntityType entityType)
///
/// The entity type to set the function name for.
/// The name to set.
- public static void SetFunctionName([NotNull] this IMutableEntityType entityType, [CanBeNull] string name)
+ public static void SetFunctionName([NotNull] this IMutableEntityType entityType, [CanBeNull] string? name)
=> entityType.SetAnnotation(
RelationalAnnotationNames.FunctionName,
Check.NullButNotEmpty(name, nameof(name)));
@@ -532,11 +534,11 @@ public static void SetFunctionName([NotNull] this IMutableEntityType entityType,
/// The name to set.
/// Indicates whether the configuration was specified using a data annotation.
/// The configured value.
- public static string SetFunctionName(
+ public static string? SetFunctionName(
[NotNull] this IConventionEntityType entityType,
- [CanBeNull] string name,
+ [CanBeNull] string? name,
bool fromDataAnnotation = false)
- => (string)entityType.SetAnnotation(
+ => (string?)entityType.SetAnnotation(
RelationalAnnotationNames.ViewName,
Check.NullButNotEmpty(name, nameof(name)),
fromDataAnnotation)?.Value;
@@ -556,7 +558,7 @@ public static string SetFunctionName(
/// The entity type to get the function mappings for.
/// The functions to which the entity type is mapped.
public static IEnumerable GetFunctionMappings([NotNull] this IEntityType entityType)
- => (IEnumerable)entityType[RelationalAnnotationNames.FunctionMappings]
+ => (IEnumerable?)entityType[RelationalAnnotationNames.FunctionMappings]
?? Array.Empty();
///
@@ -568,7 +570,7 @@ public static IEnumerable GetFunctionMappings([NotNull] this I
/// The or if no check constraint with the
/// given name in the given entity type was found.
///
- public static ICheckConstraint FindCheckConstraint(
+ public static ICheckConstraint? FindCheckConstraint(
[NotNull] this IEntityType entityType,
[NotNull] string name)
{
@@ -586,10 +588,10 @@ public static ICheckConstraint FindCheckConstraint(
/// The or if no check constraint with the
/// given name in the given entity type was found.
///
- public static IMutableCheckConstraint FindCheckConstraint(
+ public static IMutableCheckConstraint? FindCheckConstraint(
[NotNull] this IMutableEntityType entityType,
[NotNull] string name)
- => (IMutableCheckConstraint)((IEntityType)entityType).FindCheckConstraint(name);
+ => (IMutableCheckConstraint?)((IEntityType)entityType).FindCheckConstraint(name);
///
/// Finds an with the given name.
@@ -600,10 +602,10 @@ public static IMutableCheckConstraint FindCheckConstraint(
/// The or if no check constraint with the
/// given name in the given entity type was found.
///
- public static IConventionCheckConstraint FindCheckConstraint(
+ public static IConventionCheckConstraint? FindCheckConstraint(
[NotNull] this IConventionEntityType entityType,
[NotNull] string name)
- => (IConventionCheckConstraint)((IEntityType)entityType).FindCheckConstraint(name);
+ => (IConventionCheckConstraint?)((IEntityType)entityType).FindCheckConstraint(name);
///
/// Creates a new check constraint with the given name on entity type. Throws an exception
@@ -653,7 +655,7 @@ public static IConventionCheckConstraint AddCheckConstraint(
/// The entity type to remove the check constraint from.
/// The check constraint name to be removed.
/// The removed .
- public static IMutableCheckConstraint RemoveCheckConstraint(
+ public static IMutableCheckConstraint? RemoveCheckConstraint(
[NotNull] this IMutableEntityType entityType,
[NotNull] string name)
=> CheckConstraint.RemoveCheckConstraint(entityType, Check.NotEmpty(name, nameof(name)));
@@ -664,7 +666,7 @@ public static IMutableCheckConstraint RemoveCheckConstraint(
/// The entity type to remove the check constraint from.
/// The check constraint name.
/// The removed .
- public static IConventionCheckConstraint RemoveCheckConstraint(
+ public static IConventionCheckConstraint? RemoveCheckConstraint(
[NotNull] this IConventionEntityType entityType,
[NotNull] string name)
=> CheckConstraint.RemoveCheckConstraint((IMutableEntityType)entityType, Check.NotEmpty(name, nameof(name)));
@@ -695,15 +697,15 @@ public static IEnumerable GetCheckConstraints([NotNu
///
/// The entity type.
/// The comment for the table this entity is mapped to.
- public static string GetComment([NotNull] this IEntityType entityType)
- => (string)entityType[RelationalAnnotationNames.Comment];
+ public static string? GetComment([NotNull] this IEntityType entityType)
+ => (string?)entityType[RelationalAnnotationNames.Comment];
///
/// Configures a comment to be applied to the table this entity is mapped to.
///
/// The entity type.
/// The comment for the table this entity is mapped to.
- public static void SetComment([NotNull] this IMutableEntityType entityType, [CanBeNull] string comment)
+ public static void SetComment([NotNull] this IMutableEntityType entityType, [CanBeNull] string? comment)
=> entityType.SetOrRemoveAnnotation(RelationalAnnotationNames.Comment, comment);
///
@@ -713,9 +715,9 @@ public static void SetComment([NotNull] this IMutableEntityType entityType, [Can
/// The comment for the table.
/// Indicates whether the configuration was specified using a data annotation.
/// The configured comment.
- public static string SetComment(
+ public static string? SetComment(
[NotNull] this IConventionEntityType entityType,
- [CanBeNull] string comment,
+ [CanBeNull] string? comment,
bool fromDataAnnotation = false)
{
entityType.SetOrRemoveAnnotation(RelationalAnnotationNames.Comment, comment, fromDataAnnotation);
diff --git a/src/EFCore.Relational/Extensions/RelationalForeignKeyBuilderExtensions.cs b/src/EFCore.Relational/Extensions/RelationalForeignKeyBuilderExtensions.cs
index e625097acf9..ab2bed2c9ed 100644
--- a/src/EFCore.Relational/Extensions/RelationalForeignKeyBuilderExtensions.cs
+++ b/src/EFCore.Relational/Extensions/RelationalForeignKeyBuilderExtensions.cs
@@ -6,6 +6,8 @@
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Microsoft.EntityFrameworkCore.Utilities;
+#nullable enable
+
// ReSharper disable once CheckNamespace
namespace Microsoft.EntityFrameworkCore
{
@@ -22,7 +24,7 @@ public static class RelationalForeignKeyBuilderExtensions
/// The same builder instance so that multiple calls can be chained.
public static ReferenceCollectionBuilder HasConstraintName(
[NotNull] this ReferenceCollectionBuilder referenceCollectionBuilder,
- [CanBeNull] string name)
+ [CanBeNull] string? name)
{
Check.NotNull(referenceCollectionBuilder, nameof(referenceCollectionBuilder));
Check.NullButNotEmpty(name, nameof(name));
@@ -42,7 +44,7 @@ public static ReferenceCollectionBuilder HasConstraintName(
/// The dependent entity type in this relationship.
public static ReferenceCollectionBuilder HasConstraintName(
[NotNull] this ReferenceCollectionBuilder referenceCollectionBuilder,
- [CanBeNull] string name)
+ [CanBeNull] string? name)
where TEntity : class
where TRelatedEntity : class
=> (ReferenceCollectionBuilder)HasConstraintName(
@@ -56,7 +58,7 @@ public static ReferenceCollectionBuilder HasConstraintN
/// The same builder instance so that multiple calls can be chained.
public static ReferenceReferenceBuilder HasConstraintName(
[NotNull] this ReferenceReferenceBuilder referenceReferenceBuilder,
- [CanBeNull] string name)
+ [CanBeNull] string? name)
{
Check.NotNull(referenceReferenceBuilder, nameof(referenceReferenceBuilder));
Check.NullButNotEmpty(name, nameof(name));
@@ -76,7 +78,7 @@ public static ReferenceReferenceBuilder HasConstraintName(
/// The entity type on the other end of the relationship.
public static ReferenceReferenceBuilder HasConstraintName(
[NotNull] this ReferenceReferenceBuilder referenceReferenceBuilder,
- [CanBeNull] string name)
+ [CanBeNull] string? name)
where TEntity : class
where TRelatedEntity : class
=> (ReferenceReferenceBuilder)HasConstraintName(
@@ -90,7 +92,7 @@ public static ReferenceReferenceBuilder HasConstraintNa
/// The same builder instance so that multiple calls can be chained.
public static OwnershipBuilder HasConstraintName(
[NotNull] this OwnershipBuilder ownershipBuilder,
- [CanBeNull] string name)
+ [CanBeNull] string? name)
{
Check.NullButNotEmpty(name, nameof(name));
@@ -109,7 +111,7 @@ public static OwnershipBuilder HasConstraintName(
/// The entity type on the other end of the relationship.
public static OwnershipBuilder HasConstraintName(
[NotNull] this OwnershipBuilder ownershipBuilder,
- [CanBeNull] string name)
+ [CanBeNull] string? name)
where TEntity : class
where TDependentEntity : class
=> (OwnershipBuilder)HasConstraintName(
@@ -125,9 +127,9 @@ public static OwnershipBuilder HasConstraintName otherwise.
///
- public static IConventionForeignKeyBuilder HasConstraintName(
+ public static IConventionForeignKeyBuilder? HasConstraintName(
[NotNull] this IConventionForeignKeyBuilder relationship,
- [CanBeNull] string name,
+ [CanBeNull] string? name,
bool fromDataAnnotation = false)
{
if (!relationship.CanSetConstraintName(name, fromDataAnnotation))
@@ -149,7 +151,7 @@ public static IConventionForeignKeyBuilder HasConstraintName(
/// if the configuration can be applied.
public static bool CanSetConstraintName(
[NotNull] this IConventionForeignKeyBuilder relationship,
- [CanBeNull] string name,
+ [CanBeNull] string? name,
bool fromDataAnnotation = false)
=> Check.NotNull(relationship, nameof(relationship))
.CanSetAnnotation(RelationalAnnotationNames.Name, name, fromDataAnnotation);
diff --git a/src/EFCore.Relational/Extensions/RelationalForeignKeyExtensions.cs b/src/EFCore.Relational/Extensions/RelationalForeignKeyExtensions.cs
index 726191d1889..c7d1d611c38 100644
--- a/src/EFCore.Relational/Extensions/RelationalForeignKeyExtensions.cs
+++ b/src/EFCore.Relational/Extensions/RelationalForeignKeyExtensions.cs
@@ -9,6 +9,8 @@
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Utilities;
+#nullable enable
+
// ReSharper disable once CheckNamespace
namespace Microsoft.EntityFrameworkCore
{
@@ -37,7 +39,7 @@ public static string GetConstraintName([NotNull] this IForeignKey foreignKey)
/// The identifier of the containing store object.
/// The identifier of the principal store object.
/// The foreign key constraint name.
- public static string GetConstraintName(
+ public static string? GetConstraintName(
[NotNull] this IForeignKey foreignKey,
in StoreObjectIdentifier storeObject,
in StoreObjectIdentifier principalStoreObject)
@@ -78,7 +80,7 @@ public static string GetDefaultName([NotNull] this IForeignKey foreignKey)
/// The identifier of the containing store object.
/// The identifier of the principal store object.
/// The default constraint name that would be used for this foreign key.
- public static string GetDefaultName(
+ public static string? GetDefaultName(
[NotNull] this IForeignKey foreignKey,
in StoreObjectIdentifier storeObject,
in StoreObjectIdentifier principalStoreObject)
@@ -97,7 +99,7 @@ public static string GetDefaultName(
// Using a hashset is detrimental to the perf when there are no cycles
for (var i = 0; i < Metadata.Internal.RelationalEntityTypeExtensions.MaxEntityTypesSharingTable; i++)
{
- IForeignKey linkedForeignKey = null;
+ IForeignKey? linkedForeignKey = null;
foreach (var otherForeignKey in rootForeignKey.DeclaringEntityType
.FindRowInternalForeignKeys(storeObject)
.SelectMany(fk => fk.PrincipalEntityType.GetForeignKeys()))
@@ -148,7 +150,7 @@ public static string GetDefaultName(
///
/// The foreign key.
/// The value to set.
- public static void SetConstraintName([NotNull] this IMutableForeignKey foreignKey, [CanBeNull] string value)
+ public static void SetConstraintName([NotNull] this IMutableForeignKey foreignKey, [CanBeNull] string? value)
=> foreignKey.SetOrRemoveAnnotation(
RelationalAnnotationNames.Name,
Check.NullButNotEmpty(value, nameof(value)));
@@ -160,9 +162,9 @@ public static void SetConstraintName([NotNull] this IMutableForeignKey foreignKe
/// The value to set.
/// Indicates whether the configuration was specified using a data annotation.
/// The configured name.
- public static string SetConstraintName(
+ public static string? SetConstraintName(
[NotNull] this IConventionForeignKey foreignKey,
- [CanBeNull] string value,
+ [CanBeNull] string? value,
bool fromDataAnnotation = false)
{
foreignKey.SetOrRemoveAnnotation(
@@ -188,7 +190,7 @@ public static string SetConstraintName(
/// The foreign key.
/// The foreign key constraints to which the foreign key is mapped.
public static IEnumerable GetMappedConstraints([NotNull] this IForeignKey foreignKey)
- => (IEnumerable)foreignKey[RelationalAnnotationNames.ForeignKeyMappings]
+ => (IEnumerable?)foreignKey[RelationalAnnotationNames.ForeignKeyMappings]
?? Enumerable.Empty();
///
@@ -203,7 +205,7 @@ public static IEnumerable GetMappedConstraints([NotNull]
/// The foreign key.
/// The identifier of the containing store object.
/// The foreign key if found, or if none was found.
- public static IForeignKey FindSharedObjectRootForeignKey(
+ public static IForeignKey? FindSharedObjectRootForeignKey(
[NotNull] this IForeignKey foreignKey,
in StoreObjectIdentifier storeObject)
{
@@ -211,14 +213,14 @@ public static IForeignKey FindSharedObjectRootForeignKey(
var foreignKeyName = foreignKey.GetConstraintName(
storeObject,
- StoreObjectIdentifier.Table(foreignKey.PrincipalEntityType.GetTableName(), foreignKey.PrincipalEntityType.GetSchema()));
+ StoreObjectIdentifier.Table(foreignKey.PrincipalEntityType.GetTableName()!, foreignKey.PrincipalEntityType.GetSchema()));
var rootForeignKey = foreignKey;
// Limit traversal to avoid getting stuck in a cycle (validation will throw for these later)
// Using a hashset is detrimental to the perf when there are no cycles
for (var i = 0; i < Metadata.Internal.RelationalEntityTypeExtensions.MaxEntityTypesSharingTable; i++)
{
- IForeignKey linkedForeignKey = null;
+ IForeignKey? linkedForeignKey = null;
foreach (var otherForeignKey in rootForeignKey.DeclaringEntityType
.FindRowInternalForeignKeys(storeObject)
.SelectMany(fk => fk.PrincipalEntityType.GetForeignKeys()))
@@ -226,7 +228,7 @@ public static IForeignKey FindSharedObjectRootForeignKey(
if (otherForeignKey.GetConstraintName(
storeObject,
StoreObjectIdentifier.Table(
- otherForeignKey.PrincipalEntityType.GetTableName(),
+ otherForeignKey.PrincipalEntityType.GetTableName()!,
otherForeignKey.PrincipalEntityType.GetSchema()))
== foreignKeyName)
{
@@ -258,10 +260,10 @@ public static IForeignKey FindSharedObjectRootForeignKey(
/// The foreign key.
/// The identifier of the containing store object.
/// The foreign key if found, or if none was found.
- public static IMutableForeignKey FindSharedObjectRootForeignKey(
+ public static IMutableForeignKey? FindSharedObjectRootForeignKey(
[NotNull] this IMutableForeignKey foreignKey,
in StoreObjectIdentifier storeObject)
- => (IMutableForeignKey)((IForeignKey)foreignKey).FindSharedObjectRootForeignKey(storeObject);
+ => (IMutableForeignKey?)((IForeignKey)foreignKey).FindSharedObjectRootForeignKey(storeObject);
///
///
@@ -275,9 +277,9 @@ public static IMutableForeignKey FindSharedObjectRootForeignKey(
/// The foreign key.
/// The identifier of the containing store object.
/// The foreign key if found, or if none was found.
- public static IConventionForeignKey FindSharedObjectRootForeignKey(
+ public static IConventionForeignKey? FindSharedObjectRootForeignKey(
[NotNull] this IConventionForeignKey foreignKey,
in StoreObjectIdentifier storeObject)
- => (IConventionForeignKey)((IForeignKey)foreignKey).FindSharedObjectRootForeignKey(storeObject);
+ => (IConventionForeignKey?)((IForeignKey)foreignKey).FindSharedObjectRootForeignKey(storeObject);
}
}
diff --git a/src/EFCore.Relational/Extensions/RelationalIndexBuilderExtensions.cs b/src/EFCore.Relational/Extensions/RelationalIndexBuilderExtensions.cs
index 6a7da9f78f2..b3e06cd5f20 100644
--- a/src/EFCore.Relational/Extensions/RelationalIndexBuilderExtensions.cs
+++ b/src/EFCore.Relational/Extensions/RelationalIndexBuilderExtensions.cs
@@ -7,6 +7,8 @@
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Microsoft.EntityFrameworkCore.Utilities;
+#nullable enable
+
// ReSharper disable once CheckNamespace
namespace Microsoft.EntityFrameworkCore
{
@@ -21,7 +23,7 @@ public static class RelationalIndexBuilderExtensions
/// The builder for the index being configured.
/// The name of the index.
/// A builder to further configure the index.
- public static IndexBuilder HasDatabaseName([NotNull] this IndexBuilder indexBuilder, [CanBeNull] string name)
+ public static IndexBuilder HasDatabaseName([NotNull] this IndexBuilder indexBuilder, [CanBeNull] string? name)
{
indexBuilder.Metadata.SetDatabaseName(name);
@@ -35,7 +37,7 @@ public static IndexBuilder HasDatabaseName([NotNull] this IndexBuilder indexBuil
/// The name of the index.
/// A builder to further configure the index.
[Obsolete("Use HasDatabaseName() instead.")]
- public static IndexBuilder HasName([NotNull] this IndexBuilder indexBuilder, [CanBeNull] string name)
+ public static IndexBuilder HasName([NotNull] this IndexBuilder indexBuilder, [CanBeNull] string? name)
=> HasDatabaseName(indexBuilder, name);
///
@@ -47,7 +49,7 @@ public static IndexBuilder HasName([NotNull] this IndexBuilder indexBuilder, [Ca
/// A builder to further configure the index.
public static IndexBuilder HasDatabaseName(
[NotNull] this IndexBuilder indexBuilder,
- [CanBeNull] string name)
+ [CanBeNull] string? name)
{
indexBuilder.Metadata.SetDatabaseName(name);
@@ -62,7 +64,7 @@ public static IndexBuilder HasDatabaseName(
/// The name of the index.
/// A builder to further configure the index.
[Obsolete("Use HasDatabaseName() instead.")]
- public static IndexBuilder HasName([NotNull] this IndexBuilder indexBuilder, [CanBeNull] string name)
+ public static IndexBuilder HasName([NotNull] this IndexBuilder indexBuilder, [CanBeNull] string? name)
=> indexBuilder.HasDatabaseName(name);
///
@@ -75,9 +77,9 @@ public static IndexBuilder HasName([NotNull] this IndexBuilder
/// The same builder instance if the configuration was applied,
/// otherwise.
///
- public static IConventionIndexBuilder HasDatabaseName(
+ public static IConventionIndexBuilder? HasDatabaseName(
[NotNull] this IConventionIndexBuilder indexBuilder,
- [CanBeNull] string name,
+ [CanBeNull] string? name,
bool fromDataAnnotation = false)
{
if (indexBuilder.CanSetDatabaseName(name, fromDataAnnotation))
@@ -100,9 +102,9 @@ public static IConventionIndexBuilder HasDatabaseName(
/// otherwise.
///
[Obsolete("Use HasDatabaseName() instead.")]
- public static IConventionIndexBuilder HasName(
+ public static IConventionIndexBuilder? HasName(
[NotNull] this IConventionIndexBuilder indexBuilder,
- [CanBeNull] string name,
+ [CanBeNull] string? name,
bool fromDataAnnotation = false)
=> indexBuilder.HasDatabaseName(name, fromDataAnnotation);
@@ -115,7 +117,7 @@ public static IConventionIndexBuilder HasName(
/// if the given name can be set for the index.
public static bool CanSetDatabaseName(
[NotNull] this IConventionIndexBuilder indexBuilder,
- [CanBeNull] string name,
+ [CanBeNull] string? name,
bool fromDataAnnotation = false)
=> indexBuilder.CanSetAnnotation(RelationalAnnotationNames.Name, name, fromDataAnnotation);
@@ -129,7 +131,7 @@ public static bool CanSetDatabaseName(
[Obsolete("Use CanSetDatabaseName() instead.")]
public static bool CanSetName(
[NotNull] this IConventionIndexBuilder indexBuilder,
- [CanBeNull] string name,
+ [CanBeNull] string? name,
bool fromDataAnnotation = false)
=> CanSetDatabaseName(indexBuilder, name, fromDataAnnotation);
@@ -139,7 +141,7 @@ public static bool CanSetName(
/// The builder for the index being configured.
/// The filter expression for the index.
/// A builder to further configure the index.
- public static IndexBuilder HasFilter([NotNull] this IndexBuilder indexBuilder, [CanBeNull] string sql)
+ public static IndexBuilder HasFilter([NotNull] this IndexBuilder indexBuilder, [CanBeNull] string? sql)
{
Check.NotNull(indexBuilder, nameof(indexBuilder));
Check.NullButNotEmpty(sql, nameof(sql));
@@ -156,7 +158,7 @@ public static IndexBuilder HasFilter([NotNull] this IndexBuilder indexBuilder, [
/// The builder for the index being configured.
/// The filter expression for the index.
/// A builder to further configure the index.
- public static IndexBuilder HasFilter([NotNull] this IndexBuilder indexBuilder, [CanBeNull] string sql)
+ public static IndexBuilder HasFilter([NotNull] this IndexBuilder indexBuilder, [CanBeNull] string? sql)
=> (IndexBuilder)HasFilter((IndexBuilder)indexBuilder, sql);
///
@@ -169,9 +171,9 @@ public static IndexBuilder HasFilter([NotNull] this IndexBuild
/// The same builder instance if the configuration was applied,
/// otherwise.
///
- public static IConventionIndexBuilder HasFilter(
+ public static IConventionIndexBuilder? HasFilter(
[NotNull] this IConventionIndexBuilder indexBuilder,
- [CanBeNull] string sql,
+ [CanBeNull] string? sql,
bool fromDataAnnotation = false)
{
if (indexBuilder.CanSetFilter(sql, fromDataAnnotation))
@@ -192,7 +194,7 @@ public static IConventionIndexBuilder HasFilter(
/// if the given name can be set for the index.
public static bool CanSetFilter(
[NotNull] this IConventionIndexBuilder indexBuilder,
- [CanBeNull] string sql,
+ [CanBeNull] string? sql,
bool fromDataAnnotation = false)
=> indexBuilder.CanSetAnnotation(RelationalAnnotationNames.Filter, sql, fromDataAnnotation);
}
diff --git a/src/EFCore.Relational/Extensions/RelationalIndexExtensions.cs b/src/EFCore.Relational/Extensions/RelationalIndexExtensions.cs
index ec4fcab8cf1..1f8ad74164a 100644
--- a/src/EFCore.Relational/Extensions/RelationalIndexExtensions.cs
+++ b/src/EFCore.Relational/Extensions/RelationalIndexExtensions.cs
@@ -10,6 +10,8 @@
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Utilities;
+#nullable enable
+
// ReSharper disable once CheckNamespace
namespace Microsoft.EntityFrameworkCore
{
@@ -24,7 +26,7 @@ public static class RelationalIndexExtensions
/// The index.
/// The name of the index in the database.
public static string GetDatabaseName([NotNull] this IIndex index)
- => (string)index[RelationalAnnotationNames.Name]
+ => (string?)index[RelationalAnnotationNames.Name]
?? index.Name
?? index.GetDefaultDatabaseName();
@@ -43,8 +45,8 @@ public static string GetName([NotNull] this IIndex index)
/// The index.
/// The identifier of the store object.
/// The name of the index in the database.
- public static string GetDatabaseName([NotNull] this IIndex index, in StoreObjectIdentifier storeObject)
- => (string)index[RelationalAnnotationNames.Name]
+ public static string? GetDatabaseName([NotNull] this IIndex index, in StoreObjectIdentifier storeObject)
+ => (string?)index[RelationalAnnotationNames.Name]
?? index.Name
?? index.GetDefaultDatabaseName(storeObject);
@@ -82,7 +84,7 @@ public static string GetDefaultName([NotNull] this IIndex index)
/// The index.
/// The identifier of the store object.
/// The default name that would be used for this index.
- public static string GetDefaultDatabaseName([NotNull] this IIndex index, in StoreObjectIdentifier storeObject)
+ public static string? GetDefaultDatabaseName([NotNull] this IIndex index, in StoreObjectIdentifier storeObject)
{
var columnNames = index.Properties.GetColumnNames(storeObject);
if (columnNames == null)
@@ -96,7 +98,7 @@ public static string GetDefaultDatabaseName([NotNull] this IIndex index, in Stor
// Using a hashset is detrimental to the perf when there are no cycles
for (var i = 0; i < Metadata.Internal.RelationalEntityTypeExtensions.MaxEntityTypesSharingTable; i++)
{
- IIndex linkedIndex = null;
+ IIndex? linkedIndex = null;
foreach (var otherIndex in rootIndex.DeclaringEntityType
.FindRowInternalForeignKeys(storeObject)
.SelectMany(fk => fk.PrincipalEntityType.GetIndexes()))
@@ -138,7 +140,7 @@ public static string GetDefaultDatabaseName([NotNull] this IIndex index, in Stor
///
/// The index.
/// The value to set.
- public static void SetDatabaseName([NotNull] this IMutableIndex index, [CanBeNull] string name)
+ public static void SetDatabaseName([NotNull] this IMutableIndex index, [CanBeNull] string? name)
{
index.SetOrRemoveAnnotation(
RelationalAnnotationNames.Name,
@@ -151,7 +153,7 @@ public static void SetDatabaseName([NotNull] this IMutableIndex index, [CanBeNul
/// The index.
/// The value to set.
[Obsolete("Use SetDatabaseName() instead.")]
- public static void SetName([NotNull] this IMutableIndex index, [CanBeNull] string name)
+ public static void SetName([NotNull] this IMutableIndex index, [CanBeNull] string? name)
=> SetDatabaseName(index, name);
///
@@ -161,9 +163,9 @@ public static void SetName([NotNull] this IMutableIndex index, [CanBeNull] strin
/// The value to set.
/// Indicates whether the configuration was specified using a data annotation.
/// The configured value.
- public static string SetDatabaseName(
+ public static string? SetDatabaseName(
[NotNull] this IConventionIndex index,
- [CanBeNull] string name,
+ [CanBeNull] string? name,
bool fromDataAnnotation = false)
{
index.SetOrRemoveAnnotation(
@@ -181,7 +183,7 @@ public static string SetDatabaseName(
/// The value to set.
/// Indicates whether the configuration was specified using a data annotation.
[Obsolete("Use SetDatabaseName() instead.")]
- public static void SetName([NotNull] this IConventionIndex index, [CanBeNull] string name, bool fromDataAnnotation = false)
+ public static void SetName([NotNull] this IConventionIndex index, [CanBeNull] string? name, bool fromDataAnnotation = false)
=> SetDatabaseName(index, name, fromDataAnnotation);
///
@@ -206,11 +208,8 @@ public static void SetName([NotNull] this IConventionIndex index, [CanBeNull] st
///
/// The index.
/// The index filter expression.
- public static string GetFilter([NotNull] this IIndex index)
- {
- var annotation = index.FindAnnotation(RelationalAnnotationNames.Filter);
- return annotation != null ? (string)annotation.Value : null;
- }
+ public static string? GetFilter([NotNull] this IIndex index)
+ => (string?)index.FindAnnotation(RelationalAnnotationNames.Filter)?.Value;
///
/// Returns the index filter expression.
@@ -218,7 +217,7 @@ public static string GetFilter([NotNull] this IIndex index)
/// The index.
/// The identifier of the containing store object.
/// The index filter expression.
- public static string GetFilter([NotNull] this IIndex index, in StoreObjectIdentifier storeObject)
+ public static string? GetFilter([NotNull] this IIndex index, in StoreObjectIdentifier storeObject)
{
var annotation = index.FindAnnotation(RelationalAnnotationNames.Filter);
if (annotation != null)
@@ -235,7 +234,7 @@ public static string GetFilter([NotNull] this IIndex index, in StoreObjectIdenti
///
/// The index.
/// The value to set.
- public static void SetFilter([NotNull] this IMutableIndex index, [CanBeNull] string value)
+ public static void SetFilter([NotNull] this IMutableIndex index, [CanBeNull] string? value)
=> index.SetAnnotation(
RelationalAnnotationNames.Filter,
Check.NullButNotEmpty(value, nameof(value)));
@@ -247,7 +246,7 @@ public static void SetFilter([NotNull] this IMutableIndex index, [CanBeNull] str
/// The value to set.
/// Indicates whether the configuration was specified using a data annotation.
/// The configured value.
- public static string SetFilter([NotNull] this IConventionIndex index, [CanBeNull] string value, bool fromDataAnnotation = false)
+ public static string? SetFilter([NotNull] this IConventionIndex index, [CanBeNull] string? value, bool fromDataAnnotation = false)
{
index.SetAnnotation(
RelationalAnnotationNames.Filter,
@@ -271,7 +270,7 @@ public static string SetFilter([NotNull] this IConventionIndex index, [CanBeNull
/// The index.
/// The table indexes to which the index is mapped.
public static IEnumerable GetMappedTableIndexes([NotNull] this IIndex index)
- => (IEnumerable)index[RelationalAnnotationNames.TableIndexMappings]
+ => (IEnumerable?)index[RelationalAnnotationNames.TableIndexMappings]
?? Enumerable.Empty();
///
@@ -286,7 +285,7 @@ public static IEnumerable GetMappedTableIndexes([NotNull] this IInd
/// The index.
/// The identifier of the containing store object.
/// The index found, or if none was found.
- public static IIndex FindSharedObjectRootIndex([NotNull] this IIndex index, in StoreObjectIdentifier storeObject)
+ public static IIndex? FindSharedObjectRootIndex([NotNull] this IIndex index, in StoreObjectIdentifier storeObject)
{
Check.NotNull(index, nameof(index));
@@ -297,7 +296,7 @@ public static IIndex FindSharedObjectRootIndex([NotNull] this IIndex index, in S
// Using a hashset is detrimental to the perf when there are no cycles
for (var i = 0; i < Metadata.Internal.RelationalEntityTypeExtensions.MaxEntityTypesSharingTable; i++)
{
- IIndex linkedIndex = null;
+ IIndex? linkedIndex = null;
foreach (var otherIndex in rootIndex.DeclaringEntityType
.FindRowInternalForeignKeys(storeObject)
.SelectMany(fk => fk.PrincipalEntityType.GetIndexes()))
@@ -332,10 +331,10 @@ public static IIndex FindSharedObjectRootIndex([NotNull] this IIndex index, in S
/// The index.
/// The identifier of the containing store object.
/// The index found, or if none was found.
- public static IMutableIndex FindSharedObjectRootIndex(
+ public static IMutableIndex? FindSharedObjectRootIndex(
[NotNull] this IMutableIndex index,
in StoreObjectIdentifier storeObject)
- => (IMutableIndex)((IIndex)index).FindSharedObjectRootIndex(storeObject);
+ => (IMutableIndex?)((IIndex)index).FindSharedObjectRootIndex(storeObject);
///
///
@@ -349,9 +348,9 @@ public static IMutableIndex FindSharedObjectRootIndex(
/// The index.
/// The identifier of the containing store object.
/// The index found, or if none was found.
- public static IConventionIndex FindSharedObjectRootIndex(
+ public static IConventionIndex? FindSharedObjectRootIndex(
[NotNull] this IConventionIndex index,
in StoreObjectIdentifier storeObject)
- => (IConventionIndex)((IIndex)index).FindSharedObjectRootIndex(storeObject);
+ => (IConventionIndex?)((IIndex)index).FindSharedObjectRootIndex(storeObject);
}
}
diff --git a/src/EFCore.Relational/Extensions/RelationalKeyBuilderExtensions.cs b/src/EFCore.Relational/Extensions/RelationalKeyBuilderExtensions.cs
index 3a931fd5644..8968164cc21 100644
--- a/src/EFCore.Relational/Extensions/RelationalKeyBuilderExtensions.cs
+++ b/src/EFCore.Relational/Extensions/RelationalKeyBuilderExtensions.cs
@@ -6,6 +6,8 @@
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Microsoft.EntityFrameworkCore.Utilities;
+#nullable enable
+
// ReSharper disable once CheckNamespace
namespace Microsoft.EntityFrameworkCore
{
@@ -20,7 +22,7 @@ public static class RelationalKeyBuilderExtensions
/// The builder for the key being configured.
/// The name of the key.
/// The same builder instance so that multiple calls can be chained.
- public static KeyBuilder HasName([NotNull] this KeyBuilder keyBuilder, [CanBeNull] string name)
+ public static KeyBuilder HasName([NotNull] this KeyBuilder keyBuilder, [CanBeNull] string? name)
{
Check.NotNull(keyBuilder, nameof(keyBuilder));
Check.NullButNotEmpty(name, nameof(name));
@@ -38,7 +40,7 @@ public static KeyBuilder HasName([NotNull] this KeyBuilder keyBuilder, [CanBeNul
/// The same builder instance so that multiple calls can be chained.
public static KeyBuilder HasName(
[NotNull] this KeyBuilder keyBuilder,
- [CanBeNull] string name)
+ [CanBeNull] string? name)
=> (KeyBuilder)HasName((KeyBuilder)keyBuilder, name);
///
@@ -51,9 +53,9 @@ public static KeyBuilder HasName(
/// The same builder instance if the configuration was applied,
/// otherwise.
///
- public static IConventionKeyBuilder HasName(
+ public static IConventionKeyBuilder? HasName(
[NotNull] this IConventionKeyBuilder keyBuilder,
- [CanBeNull] string name,
+ [CanBeNull] string? name,
bool fromDataAnnotation = false)
{
if (keyBuilder.CanSetName(name, fromDataAnnotation))
@@ -74,7 +76,7 @@ public static IConventionKeyBuilder HasName(
/// if the given name can be set for the key constraint.
public static bool CanSetName(
[NotNull] this IConventionKeyBuilder keyBuilder,
- [CanBeNull] string name,
+ [CanBeNull] string? name,
bool fromDataAnnotation = false)
=> keyBuilder.CanSetAnnotation(RelationalAnnotationNames.Name, name, fromDataAnnotation);
}
diff --git a/src/EFCore.Relational/Extensions/RelationalKeyExtensions.cs b/src/EFCore.Relational/Extensions/RelationalKeyExtensions.cs
index 30a3fc47244..90b87736472 100644
--- a/src/EFCore.Relational/Extensions/RelationalKeyExtensions.cs
+++ b/src/EFCore.Relational/Extensions/RelationalKeyExtensions.cs
@@ -9,6 +9,8 @@
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Utilities;
+#nullable enable
+
// ReSharper disable once CheckNamespace
namespace Microsoft.EntityFrameworkCore
{
@@ -22,8 +24,8 @@ public static class RelationalKeyExtensions
///
/// The key.
/// The key constraint name for this key.
- public static string GetName([NotNull] this IKey key)
- => key.GetName(StoreObjectIdentifier.Table(key.DeclaringEntityType.GetTableName(), key.DeclaringEntityType.GetSchema()));
+ public static string? GetName([NotNull] this IKey key)
+ => key.GetName(StoreObjectIdentifier.Table(key.DeclaringEntityType.GetTableName()!, key.DeclaringEntityType.GetSchema()));
///
/// Returns the key constraint name for this key for a particular table.
@@ -31,8 +33,8 @@ public static string GetName([NotNull] this IKey key)
/// The key.
/// The identifier of the containing store object.
/// The key constraint name for this key.
- public static string GetName([NotNull] this IKey key, in StoreObjectIdentifier storeObject)
- => (string)key[RelationalAnnotationNames.Name]
+ public static string? GetName([NotNull] this IKey key, in StoreObjectIdentifier storeObject)
+ => (string?)key[RelationalAnnotationNames.Name]
?? key.GetDefaultName(storeObject);
///
@@ -42,21 +44,15 @@ public static string GetName([NotNull] this IKey key, in StoreObjectIdentifier s
/// The default key constraint name that would be used for this key.
public static string GetDefaultName([NotNull] this IKey key)
{
- string name = null;
var tableName = key.DeclaringEntityType.GetTableName();
- if (key.IsPrimaryKey())
- {
- name = "PK_" + tableName;
- }
- else
- {
- name = new StringBuilder()
+ var name = key.IsPrimaryKey()
+ ? "PK_" + tableName
+ : new StringBuilder()
.Append("AK_")
.Append(tableName)
.Append("_")
.AppendJoin(key.Properties.Select(p => p.GetColumnBaseName()), "_")
.ToString();
- }
return Uniquifier.Truncate(name, key.DeclaringEntityType.Model.GetMaxIdentifierLength());
}
@@ -67,9 +63,9 @@ public static string GetDefaultName([NotNull] this IKey key)
/// The key.
/// The identifier of the containing store object.
/// The default key constraint name that would be used for this key.
- public static string GetDefaultName([NotNull] this IKey key, in StoreObjectIdentifier storeObject)
+ public static string? GetDefaultName([NotNull] this IKey key, in StoreObjectIdentifier storeObject)
{
- string name = null;
+ string? name;
if (key.IsPrimaryKey())
{
var rootKey = key;
@@ -77,7 +73,7 @@ public static string GetDefaultName([NotNull] this IKey key, in StoreObjectIdent
// Using a hashset is detrimental to the perf when there are no cycles
for (var i = 0; i < Metadata.Internal.RelationalEntityTypeExtensions.MaxEntityTypesSharingTable; i++)
{
- var linkingFk = rootKey.DeclaringEntityType.FindRowInternalForeignKeys(storeObject)
+ var linkingFk = rootKey!.DeclaringEntityType.FindRowInternalForeignKeys(storeObject)
.FirstOrDefault();
if (linkingFk == null)
{
@@ -109,7 +105,7 @@ public static string GetDefaultName([NotNull] this IKey key, in StoreObjectIdent
// Using a hashset is detrimental to the perf when there are no cycles
for (var i = 0; i < Metadata.Internal.RelationalEntityTypeExtensions.MaxEntityTypesSharingTable; i++)
{
- IKey linkedKey = null;
+ IKey? linkedKey = null;
foreach (var otherKey in rootKey.DeclaringEntityType
.FindRowInternalForeignKeys(storeObject)
.SelectMany(fk => fk.PrincipalEntityType.GetKeys()))
@@ -152,7 +148,7 @@ public static string GetDefaultName([NotNull] this IKey key, in StoreObjectIdent
///
/// The key.
/// The value to set.
- public static void SetName([NotNull] this IMutableKey key, [CanBeNull] string name)
+ public static void SetName([NotNull] this IMutableKey key, [CanBeNull] string? name)
=> key.SetOrRemoveAnnotation(
RelationalAnnotationNames.Name,
Check.NullButNotEmpty(name, nameof(name)));
@@ -164,7 +160,7 @@ public static void SetName([NotNull] this IMutableKey key, [CanBeNull] string na
/// The value to set.
/// Indicates whether the configuration was specified using a data annotation.
/// The configured name.
- public static string SetName([NotNull] this IConventionKey key, [CanBeNull] string name, bool fromDataAnnotation = false)
+ public static string? SetName([NotNull] this IConventionKey key, [CanBeNull] string? name, bool fromDataAnnotation = false)
{
key.SetOrRemoveAnnotation(
RelationalAnnotationNames.Name,
@@ -188,7 +184,7 @@ public static string SetName([NotNull] this IConventionKey key, [CanBeNull] stri
/// The key.
/// The unique constraints to which the key is mapped.
public static IEnumerable GetMappedConstraints([NotNull] this IKey key)
- => (IEnumerable)key[RelationalAnnotationNames.UniqueConstraintMappings]
+ => (IEnumerable?)key[RelationalAnnotationNames.UniqueConstraintMappings]
?? Enumerable.Empty();
///
@@ -203,7 +199,7 @@ public static IEnumerable GetMappedConstraints([NotNull] this
/// The key.
/// The identifier of the containing store object.
/// The key found, or if none was found.
- public static IKey FindSharedObjectRootKey([NotNull] this IKey key, in StoreObjectIdentifier storeObject)
+ public static IKey? FindSharedObjectRootKey([NotNull] this IKey key, in StoreObjectIdentifier storeObject)
{
Check.NotNull(key, nameof(key));
@@ -214,7 +210,7 @@ public static IKey FindSharedObjectRootKey([NotNull] this IKey key, in StoreObje
// Using a hashset is detrimental to the perf when there are no cycles
for (var i = 0; i < Metadata.Internal.RelationalEntityTypeExtensions.MaxEntityTypesSharingTable; i++)
{
- IKey linkedKey = null;
+ IKey? linkedKey = null;
foreach (var otherKey in rootKey.DeclaringEntityType
.FindRowInternalForeignKeys(storeObject)
.SelectMany(fk => fk.PrincipalEntityType.GetKeys()))
@@ -249,10 +245,10 @@ public static IKey FindSharedObjectRootKey([NotNull] this IKey key, in StoreObje
/// The key.
/// The identifier of the containing store object.
/// The key found, or if none was found.
- public static IMutableKey FindSharedObjectRootKey(
+ public static IMutableKey? FindSharedObjectRootKey(
[NotNull] this IMutableKey key,
in StoreObjectIdentifier storeObject)
- => (IMutableKey)((IKey)key).FindSharedObjectRootKey(storeObject);
+ => (IMutableKey?)((IKey)key).FindSharedObjectRootKey(storeObject);
///
///
@@ -266,9 +262,9 @@ public static IMutableKey FindSharedObjectRootKey(
/// The key.
/// The identifier of the containing store object.
/// The key found, or if none was found.
- public static IConventionKey FindSharedObjectRootKey(
+ public static IConventionKey? FindSharedObjectRootKey(
[NotNull] this IConventionKey key,
in StoreObjectIdentifier storeObject)
- => (IConventionKey)((IKey)key).FindSharedObjectRootKey(storeObject);
+ => (IConventionKey?)((IKey)key).FindSharedObjectRootKey(storeObject);
}
}
diff --git a/src/EFCore.Relational/Extensions/RelationalModelBuilderExtensions.cs b/src/EFCore.Relational/Extensions/RelationalModelBuilderExtensions.cs
index 72f8fa66938..40915978bd9 100644
--- a/src/EFCore.Relational/Extensions/RelationalModelBuilderExtensions.cs
+++ b/src/EFCore.Relational/Extensions/RelationalModelBuilderExtensions.cs
@@ -11,6 +11,8 @@
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using Microsoft.EntityFrameworkCore.Utilities;
+#nullable enable
+
// ReSharper disable once CheckNamespace
namespace Microsoft.EntityFrameworkCore
{
@@ -29,7 +31,7 @@ public static class RelationalModelBuilderExtensions
public static SequenceBuilder HasSequence(
[NotNull] this ModelBuilder modelBuilder,
[NotNull] string name,
- [CanBeNull] string schema = null)
+ [CanBeNull] string? schema = null)
=> new(
HasSequence(
Check.NotNull(modelBuilder, nameof(modelBuilder)).Model,
@@ -61,7 +63,7 @@ public static ModelBuilder HasSequence(
public static ModelBuilder HasSequence(
[NotNull] this ModelBuilder modelBuilder,
[NotNull] string name,
- [CanBeNull] string schema,
+ [CanBeNull] string? schema,
[NotNull] Action builderAction)
{
Check.NotNull(builderAction, nameof(builderAction));
@@ -83,7 +85,7 @@ public static SequenceBuilder HasSequence(
[NotNull] this ModelBuilder modelBuilder,
[NotNull] Type type,
[NotNull] string name,
- [CanBeNull] string schema = null)
+ [CanBeNull] string? schema = null)
{
Check.NotNull(modelBuilder, nameof(modelBuilder));
Check.NotNull(type, nameof(type));
@@ -122,7 +124,7 @@ public static ModelBuilder HasSequence(
[NotNull] this ModelBuilder modelBuilder,
[NotNull] Type type,
[NotNull] string name,
- [CanBeNull] string schema,
+ [CanBeNull] string? schema,
[NotNull] Action builderAction)
{
Check.NotNull(builderAction, nameof(builderAction));
@@ -143,7 +145,7 @@ public static ModelBuilder HasSequence(
public static SequenceBuilder HasSequence(
[NotNull] this ModelBuilder modelBuilder,
[NotNull] string name,
- [CanBeNull] string schema = null)
+ [CanBeNull] string? schema = null)
{
Check.NotNull(modelBuilder, nameof(modelBuilder));
@@ -179,7 +181,7 @@ public static ModelBuilder HasSequence(
public static ModelBuilder HasSequence(
[NotNull] this ModelBuilder modelBuilder,
[NotNull] string name,
- [CanBeNull] string schema,
+ [CanBeNull] string? schema,
[NotNull] Action builderAction)
{
Check.NotNull(builderAction, nameof(builderAction));
@@ -200,7 +202,7 @@ public static ModelBuilder HasSequence(
public static IConventionSequenceBuilder HasSequence(
[NotNull] this IConventionModelBuilder modelBuilder,
[NotNull] string name,
- [CanBeNull] string schema = null,
+ [CanBeNull] string? schema = null,
bool fromDataAnnotation = false)
=> HasSequence(
(IMutableModel)Check.NotNull(modelBuilder, nameof(modelBuilder)).Metadata,
@@ -211,7 +213,7 @@ public static IConventionSequenceBuilder HasSequence(
private static Sequence HasSequence(
IMutableModel model,
string name,
- string schema,
+ string? schema,
ConfigurationSource configurationSource)
{
Check.NotEmpty(name, nameof(name));
@@ -334,7 +336,7 @@ public static IConventionDbFunctionBuilder HasDbFunction(
/// A builder to further configure the function.
public static IConventionDbFunctionBuilder HasDbFunction(
[NotNull] this IConventionModelBuilder modelBuilder,
- [NotNull] string name,
+ [CanBeNull] string? name,
[NotNull] Type returnType,
bool fromDataAnnotation = false)
{
@@ -364,7 +366,7 @@ public static IConventionDbFunctionBuilder HasDbFunction(
/// The same builder instance so that multiple calls can be chained.
public static ModelBuilder HasDefaultSchema(
[NotNull] this ModelBuilder modelBuilder,
- [CanBeNull] string schema)
+ [CanBeNull] string? schema)
{
Check.NotNull(modelBuilder, nameof(modelBuilder));
Check.NullButNotEmpty(schema, nameof(schema));
@@ -385,9 +387,9 @@ public static ModelBuilder HasDefaultSchema(
/// The same builder instance if the configuration was applied,
/// otherwise.
///
- public static IConventionModelBuilder HasDefaultSchema(
+ public static IConventionModelBuilder? HasDefaultSchema(
[NotNull] this IConventionModelBuilder modelBuilder,
- [CanBeNull] string schema,
+ [CanBeNull] string? schema,
bool fromDataAnnotation = false)
{
if (modelBuilder.CanSetDefaultSchema(schema, fromDataAnnotation))
@@ -409,7 +411,7 @@ public static IConventionModelBuilder HasDefaultSchema(
/// if the given schema can be set as default.
public static bool CanSetDefaultSchema(
[NotNull] this IConventionModelBuilder modelBuilder,
- [CanBeNull] string schema,
+ [CanBeNull] string? schema,
bool fromDataAnnotation = false)
{
Check.NotNull(modelBuilder, nameof(modelBuilder));
@@ -428,7 +430,7 @@ public static bool CanSetDefaultSchema(
/// The same builder instance if the configuration was applied,
/// otherwise.
///
- public static IConventionModelBuilder HasMaxIdentifierLength(
+ public static IConventionModelBuilder? HasMaxIdentifierLength(
[NotNull] this IConventionModelBuilder modelBuilder,
int? length,
bool fromDataAnnotation = false)
@@ -468,7 +470,7 @@ public static bool CanSetMaxIdentifierLength(
/// The same builder instance so that multiple calls can be chained.
public static ModelBuilder UseCollation(
[NotNull] this ModelBuilder modelBuilder,
- [CanBeNull] string collation)
+ [CanBeNull] string? collation)
{
Check.NotNull(modelBuilder, nameof(modelBuilder));
Check.NullButNotEmpty(collation, nameof(collation));
@@ -488,9 +490,9 @@ public static ModelBuilder UseCollation(
/// The same builder instance if the configuration was applied,
/// otherwise.
///
- public static IConventionModelBuilder UseCollation(
+ public static IConventionModelBuilder? UseCollation(
[NotNull] this IConventionModelBuilder modelBuilder,
- [CanBeNull] string collation,
+ [CanBeNull] string? collation,
bool fromDataAnnotation = false)
{
if (modelBuilder.CanSetCollation(collation, fromDataAnnotation))
@@ -512,7 +514,7 @@ public static IConventionModelBuilder UseCollation(
/// if the given collation can be set as default.
public static bool CanSetCollation(
[NotNull] this IConventionModelBuilder modelBuilder,
- [CanBeNull] string collation,
+ [CanBeNull] string? collation,
bool fromDataAnnotation = false)
{
Check.NotNull(modelBuilder, nameof(modelBuilder));
diff --git a/src/EFCore.Relational/Extensions/RelationalModelExtensions.cs b/src/EFCore.Relational/Extensions/RelationalModelExtensions.cs
index 45f0fa3696b..64f24cd5582 100644
--- a/src/EFCore.Relational/Extensions/RelationalModelExtensions.cs
+++ b/src/EFCore.Relational/Extensions/RelationalModelExtensions.cs
@@ -235,7 +235,7 @@ public static void SetMaxIdentifierLength([NotNull] this IMutableModel model, in
/// The sequence name.
/// The schema name, or to use the default schema.
/// The sequence.
- public static IMutableSequence? AddSequence(
+ public static IMutableSequence AddSequence(
[NotNull] this IMutableModel model,
[NotNull] string name,
[CanBeNull] string? schema = null)
@@ -376,9 +376,9 @@ public static IEnumerable GetSequences([NotNull] this IConv
/// The model to add the function to.
/// The for the method that is mapped to the function.
/// The new .
- public static IMutableDbFunction? AddDbFunction([NotNull] this IMutableModel model, [NotNull] MethodInfo methodInfo)
+ public static IMutableDbFunction AddDbFunction([NotNull] this IMutableModel model, [NotNull] MethodInfo methodInfo)
=> DbFunction.AddDbFunction(
- model, Check.NotNull(methodInfo, nameof(methodInfo)), ConfigurationSource.Explicit);
+ model, Check.NotNull(methodInfo, nameof(methodInfo)), ConfigurationSource.Explicit)!;
///
/// Creates an mapped to the given method.
@@ -387,7 +387,7 @@ public static IEnumerable GetSequences([NotNull] this IConv
/// The for the method that is mapped to the function.
/// Indicates whether the configuration was specified using a data annotation.
/// The new .
- public static IConventionDbFunction? AddDbFunction(
+ public static IConventionDbFunction AddDbFunction(
[NotNull] this IConventionModel model,
[NotNull] MethodInfo methodInfo,
bool fromDataAnnotation = false)
@@ -402,7 +402,7 @@ public static IEnumerable GetSequences([NotNull] this IConv
/// The model name of the function.
/// The function return type.
/// The new .
- public static IMutableDbFunction? AddDbFunction(
+ public static IMutableDbFunction AddDbFunction(
[NotNull] this IMutableModel model,
[NotNull] string name,
[NotNull] Type returnType)
@@ -417,7 +417,7 @@ public static IEnumerable GetSequences([NotNull] this IConv
/// The function return type.
/// Indicates whether the configuration was specified using a data annotation.
/// The new .
- public static IConventionDbFunction? AddDbFunction(
+ public static IConventionDbFunction AddDbFunction(
[NotNull] this IConventionModel model,
[NotNull] string name,
[NotNull] Type returnType,
diff --git a/src/EFCore.Relational/Extensions/RelationalOwnedNavigationBuilderExtensions.cs b/src/EFCore.Relational/Extensions/RelationalOwnedNavigationBuilderExtensions.cs
index bdc637d7269..418005a4ed4 100644
--- a/src/EFCore.Relational/Extensions/RelationalOwnedNavigationBuilderExtensions.cs
+++ b/src/EFCore.Relational/Extensions/RelationalOwnedNavigationBuilderExtensions.cs
@@ -7,6 +7,8 @@
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using Microsoft.EntityFrameworkCore.Utilities;
+#nullable enable
+
// ReSharper disable once CheckNamespace
namespace Microsoft.EntityFrameworkCore
{
@@ -25,7 +27,7 @@ public static class RelationalOwnedNavigationBuilderExtensions
public static OwnedNavigationBuilder HasCheckConstraint(
[NotNull] this OwnedNavigationBuilder ownedNavigationBuilder,
[NotNull] string name,
- [CanBeNull] string sql)
+ [CanBeNull] string? sql)
{
Check.NotNull(ownedNavigationBuilder, nameof(ownedNavigationBuilder));
Check.NotEmpty(name, nameof(name));
@@ -65,7 +67,7 @@ public static OwnedNavigationBuilder HasCheckConstraint(
public static OwnedNavigationBuilder HasCheckConstraint(
[NotNull] this OwnedNavigationBuilder ownedNavigationBuilder,
[NotNull] string name,
- [CanBeNull] string sql)
+ [CanBeNull] string? sql)
where TEntity : class
where TDependentEntity : class
=> (OwnedNavigationBuilder)
diff --git a/src/EFCore.Relational/Extensions/RelationalPropertyBuilderExtensions.cs b/src/EFCore.Relational/Extensions/RelationalPropertyBuilderExtensions.cs
index 8c029f7db6e..a1d9779f4ee 100644
--- a/src/EFCore.Relational/Extensions/RelationalPropertyBuilderExtensions.cs
+++ b/src/EFCore.Relational/Extensions/RelationalPropertyBuilderExtensions.cs
@@ -8,6 +8,8 @@
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using Microsoft.EntityFrameworkCore.Utilities;
+#nullable enable
+
// ReSharper disable once CheckNamespace
namespace Microsoft.EntityFrameworkCore
{
@@ -24,7 +26,7 @@ public static class RelationalPropertyBuilderExtensions
/// The same builder instance so that multiple calls can be chained.
public static PropertyBuilder HasColumnName(
[NotNull] this PropertyBuilder propertyBuilder,
- [CanBeNull] string name)
+ [CanBeNull] string? name)
{
Check.NotNull(propertyBuilder, nameof(propertyBuilder));
Check.NullButNotEmpty(name, nameof(name));
@@ -43,7 +45,7 @@ public static PropertyBuilder HasColumnName(
/// The same builder instance so that multiple calls can be chained.
public static PropertyBuilder HasColumnName(
[NotNull] this PropertyBuilder propertyBuilder,
- [CanBeNull] string name)
+ [CanBeNull] string? name)
=> (PropertyBuilder)HasColumnName((PropertyBuilder)propertyBuilder, name);
///
@@ -56,9 +58,9 @@ public static PropertyBuilder HasColumnName(
/// The same builder instance if the configuration was applied,
/// otherwise.
///
- public static IConventionPropertyBuilder HasColumnName(
+ public static IConventionPropertyBuilder? HasColumnName(
[NotNull] this IConventionPropertyBuilder propertyBuilder,
- [CanBeNull] string name,
+ [CanBeNull] string? name,
bool fromDataAnnotation = false)
{
if (!propertyBuilder.CanSetColumnName(name, fromDataAnnotation))
@@ -81,9 +83,9 @@ public static IConventionPropertyBuilder HasColumnName(
/// The same builder instance if the configuration was applied,
/// otherwise.
///
- public static IConventionPropertyBuilder HasColumnName(
+ public static IConventionPropertyBuilder? HasColumnName(
[NotNull] this IConventionPropertyBuilder propertyBuilder,
- [CanBeNull] string name,
+ [CanBeNull] string? name,
in StoreObjectIdentifier storeObject,
bool fromDataAnnotation = false)
{
@@ -105,7 +107,7 @@ public static IConventionPropertyBuilder HasColumnName(
/// if the property can be mapped to the given column.
public static bool CanSetColumnName(
[NotNull] this IConventionPropertyBuilder propertyBuilder,
- [CanBeNull] string name,
+ [CanBeNull] string? name,
bool fromDataAnnotation = false)
=> propertyBuilder.CanSetAnnotation(RelationalAnnotationNames.ColumnName, name, fromDataAnnotation);
@@ -119,7 +121,7 @@ public static bool CanSetColumnName(
/// if the property can be mapped to the given column.
public static bool CanSetColumnName(
[NotNull] this IConventionPropertyBuilder propertyBuilder,
- [CanBeNull] string name,
+ [CanBeNull] string? name,
in StoreObjectIdentifier storeObject,
bool fromDataAnnotation = false)
{
@@ -139,7 +141,7 @@ public static bool CanSetColumnName(
/// The same builder instance so that multiple calls can be chained.
public static PropertyBuilder HasColumnType(
[NotNull] this PropertyBuilder propertyBuilder,
- [CanBeNull] string typeName)
+ [CanBeNull] string? typeName)
{
Check.NotNull(propertyBuilder, nameof(propertyBuilder));
Check.NullButNotEmpty(typeName, nameof(typeName));
@@ -159,7 +161,7 @@ public static PropertyBuilder HasColumnType(
/// The same builder instance so that multiple calls can be chained.
public static PropertyBuilder HasColumnType(
[NotNull] this PropertyBuilder propertyBuilder,
- [CanBeNull] string typeName)
+ [CanBeNull] string? typeName)
=> (PropertyBuilder)HasColumnType((PropertyBuilder)propertyBuilder, typeName);
///
@@ -173,9 +175,9 @@ public static PropertyBuilder HasColumnType(
/// The same builder instance if the configuration was applied,
/// otherwise.
///
- public static IConventionPropertyBuilder HasColumnType(
+ public static IConventionPropertyBuilder? HasColumnType(
[NotNull] this IConventionPropertyBuilder propertyBuilder,
- [CanBeNull] string typeName,
+ [CanBeNull] string? typeName,
bool fromDataAnnotation = false)
{
if (!propertyBuilder.CanSetColumnType(typeName, fromDataAnnotation))
@@ -196,7 +198,7 @@ public static IConventionPropertyBuilder HasColumnType(
/// if the given data type can be set for the property.
public static bool CanSetColumnType(
[NotNull] this IConventionPropertyBuilder propertyBuilder,
- [CanBeNull] string typeName,
+ [CanBeNull] string? typeName,
bool fromDataAnnotation = false)
=> propertyBuilder.CanSetAnnotation(RelationalAnnotationNames.ColumnType, typeName, fromDataAnnotation);
@@ -239,7 +241,7 @@ public static PropertyBuilder IsFixedLength(
/// The same builder instance if the configuration was applied,
/// otherwise.
///
- public static IConventionPropertyBuilder IsFixedLength(
+ public static IConventionPropertyBuilder? IsFixedLength(
[NotNull] this IConventionPropertyBuilder propertyBuilder,
bool? fixedLength,
bool fromDataAnnotation = false)
@@ -296,7 +298,7 @@ public static PropertyBuilder HasDefaultValueSql([NotNull] this PropertyBuilder
/// The same builder instance so that multiple calls can be chained.
public static PropertyBuilder HasDefaultValueSql(
[NotNull] this PropertyBuilder propertyBuilder,
- [CanBeNull] string sql)
+ [CanBeNull] string? sql)
{
Check.NotNull(propertyBuilder, nameof(propertyBuilder));
Check.NullButNotEmpty(sql, nameof(sql));
@@ -333,7 +335,7 @@ public static PropertyBuilder HasDefaultValueSql(
/// The same builder instance so that multiple calls can be chained.
public static PropertyBuilder HasDefaultValueSql(
[NotNull] this PropertyBuilder propertyBuilder,
- [CanBeNull] string sql)
+ [CanBeNull] string? sql)
=> (PropertyBuilder)HasDefaultValueSql((PropertyBuilder)propertyBuilder, sql);
///
@@ -346,9 +348,9 @@ public static PropertyBuilder HasDefaultValueSql(
/// The same builder instance if the configuration was applied,
/// otherwise.
///
- public static IConventionPropertyBuilder HasDefaultValueSql(
+ public static IConventionPropertyBuilder? HasDefaultValueSql(
[NotNull] this IConventionPropertyBuilder propertyBuilder,
- [CanBeNull] string sql,
+ [CanBeNull] string? sql,
bool fromDataAnnotation = false)
{
if (!propertyBuilder.CanSetDefaultValueSql(sql, fromDataAnnotation))
@@ -369,7 +371,7 @@ public static IConventionPropertyBuilder HasDefaultValueSql(
/// if the given default value expression can be set for the column.
public static bool CanSetDefaultValueSql(
[NotNull] this IConventionPropertyBuilder propertyBuilder,
- [CanBeNull] string sql,
+ [CanBeNull] string? sql,
bool fromDataAnnotation = false)
=> propertyBuilder.CanSetAnnotation(
RelationalAnnotationNames.DefaultValueSql,
@@ -405,7 +407,7 @@ public static PropertyBuilder HasComputedColumnSql([NotNull] this PropertyBuilde
/// The same builder instance so that multiple calls can be chained.
public static PropertyBuilder HasComputedColumnSql(
[NotNull] this PropertyBuilder propertyBuilder,
- [CanBeNull] string sql)
+ [CanBeNull] string? sql)
=> HasComputedColumnSql(propertyBuilder, sql, null);
///
@@ -421,7 +423,7 @@ public static PropertyBuilder HasComputedColumnSql(
/// The same builder instance so that multiple calls can be chained.
public static PropertyBuilder HasComputedColumnSql(
[NotNull] this PropertyBuilder propertyBuilder,
- [CanBeNull] string sql,
+ [CanBeNull] string? sql,
bool? stored)
{
Check.NotNull(propertyBuilder, nameof(propertyBuilder));
@@ -463,7 +465,7 @@ public static PropertyBuilder HasComputedColumnSql(
/// The same builder instance so that multiple calls can be chained.
public static PropertyBuilder HasComputedColumnSql(
[NotNull] this PropertyBuilder propertyBuilder,
- [CanBeNull] string sql)
+ [CanBeNull] string? sql)
=> HasComputedColumnSql(propertyBuilder, sql, null);
///
@@ -480,7 +482,7 @@ public static PropertyBuilder HasComputedColumnSql(
/// The same builder instance so that multiple calls can be chained.
public static PropertyBuilder HasComputedColumnSql(
[NotNull] this PropertyBuilder propertyBuilder,
- [CanBeNull] string sql,
+ [CanBeNull] string? sql,
bool? stored)
=> (PropertyBuilder)HasComputedColumnSql((PropertyBuilder)propertyBuilder, sql, stored);
@@ -494,9 +496,9 @@ public static PropertyBuilder HasComputedColumnSql(
/// The same builder instance if the configuration was applied,
/// otherwise.
///
- public static IConventionPropertyBuilder HasComputedColumnSql(
+ public static IConventionPropertyBuilder? HasComputedColumnSql(
[NotNull] this IConventionPropertyBuilder propertyBuilder,
- [CanBeNull] string sql,
+ [CanBeNull] string? sql,
bool fromDataAnnotation = false)
{
if (!propertyBuilder.CanSetComputedColumnSql(sql, fromDataAnnotation))
@@ -521,7 +523,7 @@ public static IConventionPropertyBuilder HasComputedColumnSql(
///
/// The same builder instance if the configuration was applied, otherwise.
///
- public static IConventionPropertyBuilder IsStoredComputedColumn(
+ public static IConventionPropertyBuilder? IsStoredComputedColumn(
[NotNull] this IConventionPropertyBuilder propertyBuilder,
bool? stored,
bool fromDataAnnotation = false)
@@ -544,7 +546,7 @@ public static IConventionPropertyBuilder IsStoredComputedColumn(
/// if the given computed value SQL expression can be set for the column.
public static bool CanSetComputedColumnSql(
[NotNull] this IConventionPropertyBuilder propertyBuilder,
- [CanBeNull] string sql,
+ [CanBeNull] string? sql,
bool fromDataAnnotation = false)
=> propertyBuilder.CanSetAnnotation(
RelationalAnnotationNames.ComputedColumnSql,
@@ -602,7 +604,7 @@ public static PropertyBuilder HasDefaultValue([NotNull] this PropertyBuilder pro
/// The same builder instance so that multiple calls can be chained.
public static PropertyBuilder HasDefaultValue(
[NotNull] this PropertyBuilder propertyBuilder,
- [CanBeNull] object value)
+ [CanBeNull] object? value)
{
Check.NotNull(propertyBuilder, nameof(propertyBuilder));
@@ -639,7 +641,7 @@ public static PropertyBuilder HasDefaultValue(
/// The same builder instance so that multiple calls can be chained.
public static PropertyBuilder HasDefaultValue(
[NotNull] this PropertyBuilder propertyBuilder,
- [CanBeNull] object value)
+ [CanBeNull] object? value)
=> (PropertyBuilder)HasDefaultValue((PropertyBuilder)propertyBuilder, value);
///
@@ -652,9 +654,9 @@ public static PropertyBuilder HasDefaultValue(
/// The same builder instance if the configuration was applied,
/// otherwise.
///
- public static IConventionPropertyBuilder HasDefaultValue(
+ public static IConventionPropertyBuilder? HasDefaultValue(
[NotNull] this IConventionPropertyBuilder propertyBuilder,
- [CanBeNull] object value,
+ [CanBeNull] object? value,
bool fromDataAnnotation = false)
{
if (!propertyBuilder.CanSetDefaultValue(value, fromDataAnnotation))
@@ -675,7 +677,7 @@ public static IConventionPropertyBuilder HasDefaultValue(
/// if the given value can be set as default for the column.
public static bool CanSetDefaultValue(
[NotNull] this IConventionPropertyBuilder propertyBuilder,
- [CanBeNull] object value,
+ [CanBeNull] object? value,
bool fromDataAnnotation = false)
=> propertyBuilder.CanSetAnnotation(
RelationalAnnotationNames.DefaultValue,
@@ -690,7 +692,7 @@ public static bool CanSetDefaultValue(
/// The same builder instance so that multiple calls can be chained.
public static PropertyBuilder HasComment(
[NotNull] this PropertyBuilder propertyBuilder,
- [CanBeNull] string comment)
+ [CanBeNull] string? comment)
{
Check.NotNull(propertyBuilder, nameof(propertyBuilder));
@@ -708,7 +710,7 @@ public static PropertyBuilder HasComment(
/// The same builder instance so that multiple calls can be chained.
public static PropertyBuilder HasComment(
[NotNull] this PropertyBuilder propertyBuilder,
- [CanBeNull] string comment)
+ [CanBeNull] string? comment)
=> (PropertyBuilder)HasComment((PropertyBuilder)propertyBuilder, comment);
///
@@ -721,9 +723,9 @@ public static PropertyBuilder HasComment(
/// The same builder instance if the configuration was applied,
/// otherwise.
///
- public static IConventionPropertyBuilder HasComment(
+ public static IConventionPropertyBuilder? HasComment(
[NotNull] this IConventionPropertyBuilder propertyBuilder,
- [CanBeNull] string comment,
+ [CanBeNull] string? comment,
bool fromDataAnnotation = false)
{
if (!propertyBuilder.CanSetComment(comment, fromDataAnnotation))
@@ -744,7 +746,7 @@ public static IConventionPropertyBuilder HasComment(
/// if the given value can be set as default for the column.
public static bool CanSetComment(
[NotNull] this IConventionPropertyBuilder propertyBuilder,
- [CanBeNull] string comment,
+ [CanBeNull] string? comment,
bool fromDataAnnotation = false)
=> propertyBuilder.CanSetAnnotation(
RelationalAnnotationNames.Comment,
@@ -758,7 +760,7 @@ public static bool CanSetComment(
/// The builder for the property being configured.
/// The collation for the column.
/// The same builder instance so that multiple calls can be chained.
- public static PropertyBuilder UseCollation([NotNull] this PropertyBuilder propertyBuilder, [CanBeNull] string collation)
+ public static PropertyBuilder UseCollation([NotNull] this PropertyBuilder propertyBuilder, [CanBeNull] string? collation)
{
Check.NotNull(propertyBuilder, nameof(propertyBuilder));
Check.NullButNotEmpty(collation, nameof(collation));
@@ -777,7 +779,7 @@ public static PropertyBuilder UseCollation([NotNull] this PropertyBuilder proper
/// The same builder instance so that multiple calls can be chained.
public static PropertyBuilder UseCollation(
[NotNull] this PropertyBuilder propertyBuilder,
- [CanBeNull] string collation)
+ [CanBeNull] string? collation)
=> (PropertyBuilder)UseCollation((PropertyBuilder)propertyBuilder, collation);
///
@@ -791,9 +793,9 @@ public static PropertyBuilder UseCollation(
/// The same builder instance if the configuration was applied,
/// otherwise.
///
- public static IConventionPropertyBuilder UseCollation(
+ public static IConventionPropertyBuilder? UseCollation(
[NotNull] this IConventionPropertyBuilder propertyBuilder,
- [CanBeNull] string collation,
+ [CanBeNull] string? collation,
bool fromDataAnnotation = false)
{
if (propertyBuilder.CanSetCollation(collation, fromDataAnnotation))
@@ -815,7 +817,7 @@ public static IConventionPropertyBuilder UseCollation(
/// if the given value can be set as default for the column.
public static bool CanSetCollation(
[NotNull] this IConventionPropertyBuilder propertyBuilder,
- [CanBeNull] string collation,
+ [CanBeNull] string? collation,
bool fromDataAnnotation = false)
{
Check.NotNull(propertyBuilder, nameof(propertyBuilder));
diff --git a/src/EFCore.Relational/Extensions/RelationalPropertyExtensions.cs b/src/EFCore.Relational/Extensions/RelationalPropertyExtensions.cs
index eb1392c43a2..123e6421ded 100644
--- a/src/EFCore.Relational/Extensions/RelationalPropertyExtensions.cs
+++ b/src/EFCore.Relational/Extensions/RelationalPropertyExtensions.cs
@@ -15,6 +15,8 @@
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.EntityFrameworkCore.Utilities;
+#nullable enable
+
// ReSharper disable once CheckNamespace
namespace Microsoft.EntityFrameworkCore
{
@@ -30,10 +32,7 @@ public static class RelationalPropertyExtensions
/// The name of the table column to which the property is mapped.
[Obsolete("Use the overload that takes a StoreObjectIdentifier")]
public static string GetColumnName([NotNull] this IProperty property)
- {
- var annotation = property.FindAnnotation(RelationalAnnotationNames.ColumnName);
- return annotation != null ? (string)annotation.Value : property.GetDefaultColumnName();
- }
+ => (string?)property.FindAnnotation(RelationalAnnotationNames.ColumnName)?.Value ?? property.GetDefaultColumnName();
///
/// Returns the base name of the column to which the property would be mapped.
@@ -41,10 +40,7 @@ public static string GetColumnName([NotNull] this IProperty property)
/// The property.
/// The the base name of the column to which the property would be mapped.
public static string GetColumnBaseName([NotNull] this IProperty property)
- {
- var annotation = property.FindAnnotation(RelationalAnnotationNames.ColumnName);
- return annotation != null ? (string)annotation.Value : property.GetDefaultColumnBaseName();
- }
+ => (string?)property.FindAnnotation(RelationalAnnotationNames.ColumnName)?.Value ?? property.GetDefaultColumnBaseName();
///
/// Returns the name of the column to which the property is mapped for a particular table.
@@ -52,7 +48,7 @@ public static string GetColumnBaseName([NotNull] this IProperty property)
/// The property.
/// The identifier of the table-like store object containing the column.
/// The name of the column to which the property is mapped.
- public static string GetColumnName([NotNull] this IProperty property, in StoreObjectIdentifier storeObject)
+ public static string? GetColumnName([NotNull] this IProperty property, in StoreObjectIdentifier storeObject)
{
Check.NotNull(property, nameof(property));
@@ -128,17 +124,17 @@ public static string GetDefaultColumnName([NotNull] this IProperty property, in
var sharedTablePrincipalPrimaryKeyProperty = FindSharedObjectRootPrimaryKeyProperty(property, storeObject);
if (sharedTablePrincipalPrimaryKeyProperty != null)
{
- return sharedTablePrincipalPrimaryKeyProperty.GetColumnName(storeObject);
+ return sharedTablePrincipalPrimaryKeyProperty.GetColumnName(storeObject)!;
}
var sharedTablePrincipalConcurrencyProperty = FindSharedObjectRootConcurrencyTokenProperty(property, storeObject);
if (sharedTablePrincipalConcurrencyProperty != null)
{
- return sharedTablePrincipalConcurrencyProperty.GetColumnName(storeObject);
+ return sharedTablePrincipalConcurrencyProperty.GetColumnName(storeObject)!;
}
var entityType = property.DeclaringEntityType;
- StringBuilder builder = null;
+ StringBuilder? builder = null;
while (true)
{
var ownership = entityType.GetForeignKeys().SingleOrDefault(fk => fk.IsOwnership);
@@ -190,7 +186,7 @@ public static string GetDefaultColumnName([NotNull] this IProperty property, in
}
builder.Insert(0, "_");
- builder.Insert(0, ownership.PrincipalToDependent.Name);
+ builder.Insert(0, ownership.PrincipalToDependent!.Name);
entityType = ownerType;
}
@@ -211,7 +207,7 @@ public static string GetDefaultColumnName([NotNull] this IProperty property, in
///
/// The property.
/// The name to set.
- public static void SetColumnName([NotNull] this IMutableProperty property, [CanBeNull] string name)
+ public static void SetColumnName([NotNull] this IMutableProperty property, [CanBeNull] string? name)
=> property.SetOrRemoveAnnotation(
RelationalAnnotationNames.ColumnName,
Check.NullButNotEmpty(name, nameof(name)));
@@ -223,9 +219,9 @@ public static void SetColumnName([NotNull] this IMutableProperty property, [CanB
/// The name to set.
/// Indicates whether the configuration was specified using a data annotation.
/// The configured value.
- public static string SetColumnName(
+ public static string? SetColumnName(
[NotNull] this IConventionProperty property,
- [CanBeNull] string name,
+ [CanBeNull] string? name,
bool fromDataAnnotation = false)
{
property.SetOrRemoveAnnotation(
@@ -244,7 +240,7 @@ public static string SetColumnName(
/// The identifier of the table-like store object containing the column.
public static void SetColumnName(
[NotNull] this IMutableProperty property,
- [CanBeNull] string name,
+ [CanBeNull] string? name,
in StoreObjectIdentifier storeObject)
=> RelationalPropertyOverrides.GetOrCreate(property, storeObject)
.SetColumnName(name, ConfigurationSource.Explicit);
@@ -257,9 +253,9 @@ public static void SetColumnName(
/// The identifier of the table-like store object containing the column.
/// Indicates whether the configuration was specified using a data annotation.
/// The configured value.
- public static string SetColumnName(
+ public static string? SetColumnName(
[NotNull] this IConventionProperty property,
- [CanBeNull] string name,
+ [CanBeNull] string? name,
in StoreObjectIdentifier storeObject,
bool fromDataAnnotation = false)
=> RelationalPropertyOverrides.GetOrCreate(property, storeObject)
@@ -289,11 +285,11 @@ public static string SetColumnName(
///
/// The property.
/// The database type of the column to which the property is mapped.
- public static string GetColumnType([NotNull] this IProperty property)
+ public static string? GetColumnType([NotNull] this IProperty property)
{
Check.NotNull(property, nameof(property));
- return (string)(property.FindRelationalTypeMapping()?.StoreType
+ return (string?)(property.FindRelationalTypeMapping()?.StoreType
?? property.FindAnnotation(RelationalAnnotationNames.ColumnType)?.Value);
}
@@ -303,7 +299,7 @@ public static string GetColumnType([NotNull] this IProperty property)
/// The property.
/// The identifier of the table-like store object containing the column.
/// The database type of the column to which the property is mapped.
- public static string GetColumnType([NotNull] this IProperty property, in StoreObjectIdentifier storeObject)
+ public static string? GetColumnType([NotNull] this IProperty property, in StoreObjectIdentifier storeObject)
{
var annotation = property.FindAnnotation(RelationalAnnotationNames.ColumnType);
if (annotation != null)
@@ -314,7 +310,7 @@ public static string GetColumnType([NotNull] this IProperty property, in StoreOb
return GetDefaultColumnType(property, storeObject);
}
- private static string GetDefaultColumnType(IProperty property, in StoreObjectIdentifier storeObject)
+ private static string? GetDefaultColumnType(IProperty property, in StoreObjectIdentifier storeObject)
{
var sharedTableRootProperty = property.FindSharedStoreObjectRootProperty(storeObject);
return sharedTableRootProperty != null
@@ -327,7 +323,7 @@ private static string GetDefaultColumnType(IProperty property, in StoreObjectIde
///
/// The property.
/// The value to set.
- public static void SetColumnType([NotNull] this IMutableProperty property, [CanBeNull] string value)
+ public static void SetColumnType([NotNull] this IMutableProperty property, [CanBeNull] string? value)
=> property.SetOrRemoveAnnotation(
RelationalAnnotationNames.ColumnType,
Check.NullButNotEmpty(value, nameof(value)));
@@ -339,9 +335,9 @@ public static void SetColumnType([NotNull] this IMutableProperty property, [CanB
/// The value to set.
/// Indicates whether the configuration was specified using a data annotation.
/// The configured value.
- public static string SetColumnType(
+ public static string? SetColumnType(
[NotNull] this IConventionProperty property,
- [CanBeNull] string value,
+ [CanBeNull] string? value,
bool fromDataAnnotation = false)
{
property.SetOrRemoveAnnotation(
@@ -366,7 +362,7 @@ public static string SetColumnType(
/// The property.
/// The default columns to which the property would be mapped.
public static IEnumerable GetDefaultColumnMappings([NotNull] this IProperty property)
- => (IEnumerable)property[RelationalAnnotationNames.DefaultColumnMappings]
+ => (IEnumerable?)property[RelationalAnnotationNames.DefaultColumnMappings]
?? Enumerable.Empty();
///
@@ -375,7 +371,7 @@ public static IEnumerable GetDefaultColumnMappings([NotNull]
/// The property.
/// The table columns to which the property is mapped.
public static IEnumerable GetTableColumnMappings([NotNull] this IProperty property)
- => (IEnumerable)property[RelationalAnnotationNames.TableColumnMappings]
+ => (IEnumerable?)property[RelationalAnnotationNames.TableColumnMappings]
?? Enumerable.Empty();
///
@@ -384,7 +380,7 @@ public static IEnumerable GetTableColumnMappings([NotNull] this
/// The property.
/// The view columns to which the property is mapped.
public static IEnumerable GetViewColumnMappings([NotNull] this IProperty property)
- => (IEnumerable)property[RelationalAnnotationNames.ViewColumnMappings]
+ => (IEnumerable?)property[RelationalAnnotationNames.ViewColumnMappings]
?? Enumerable.Empty();
///
@@ -393,7 +389,7 @@ public static IEnumerable GetViewColumnMappings([NotNull] th
/// The property.
/// The SQL query columns to which the property is mapped.
public static IEnumerable GetSqlQueryColumnMappings([NotNull] this IProperty property)
- => (IEnumerable)property[RelationalAnnotationNames.SqlQueryColumnMappings]
+ => (IEnumerable?)property[RelationalAnnotationNames.SqlQueryColumnMappings]
?? Enumerable.Empty();
///
@@ -402,7 +398,7 @@ public static IEnumerable GetSqlQueryColumnMappings([Not
/// The property.
/// The function columns to which the property is mapped.
public static IEnumerable GetFunctionColumnMappings([NotNull] this IProperty property)
- => (IEnumerable)property[RelationalAnnotationNames.FunctionColumnMappings]
+ => (IEnumerable?)property[RelationalAnnotationNames.FunctionColumnMappings]
?? Enumerable.Empty();
///
@@ -411,7 +407,7 @@ public static IEnumerable GetFunctionColumnMappings([Not
/// The property.
/// The identifier of the table-like store object containing the column.
/// The column to which the property is mapped.
- public static IColumnBase FindColumn([NotNull] this IProperty property, in StoreObjectIdentifier storeObject)
+ public static IColumnBase? FindColumn([NotNull] this IProperty property, in StoreObjectIdentifier storeObject)
{
switch (storeObject.StoreObjectType)
{
@@ -465,11 +461,8 @@ public static IColumnBase FindColumn([NotNull] this IProperty property, in Store
///
/// The property.
/// The SQL expression that is used as the default value for the column this property is mapped to.
- public static string GetDefaultValueSql([NotNull] this IProperty property)
- {
- var annotation = property.FindAnnotation(RelationalAnnotationNames.DefaultValueSql);
- return annotation != null ? (string)annotation.Value : null;
- }
+ public static string? GetDefaultValueSql([NotNull] this IProperty property)
+ => (string?)property.FindAnnotation(RelationalAnnotationNames.DefaultValueSql)?.Value;
///
/// Returns the SQL expression that is used as the default value for the column this property is mapped to.
@@ -477,7 +470,7 @@ public static string GetDefaultValueSql([NotNull] this IProperty property)
/// The property.
/// The identifier of the table-like store object containing the column.
/// The SQL expression that is used as the default value for the column this property is mapped to.
- public static string GetDefaultValueSql([NotNull] this IProperty property, in StoreObjectIdentifier storeObject)
+ public static string? GetDefaultValueSql([NotNull] this IProperty property, in StoreObjectIdentifier storeObject)
{
var annotation = property.FindAnnotation(RelationalAnnotationNames.DefaultValueSql);
if (annotation != null)
@@ -499,7 +492,7 @@ public static string GetDefaultValueSql([NotNull] this IProperty property, in St
///
/// The property.
/// The value to set.
- public static void SetDefaultValueSql([NotNull] this IMutableProperty property, [CanBeNull] string value)
+ public static void SetDefaultValueSql([NotNull] this IMutableProperty property, [CanBeNull] string? value)
=> property.SetOrRemoveAnnotation(
RelationalAnnotationNames.DefaultValueSql,
value);
@@ -511,9 +504,9 @@ public static void SetDefaultValueSql([NotNull] this IMutableProperty property,
/// The value to set.
/// Indicates whether the configuration was specified using a data annotation.
/// The configured value.
- public static string SetDefaultValueSql(
+ public static string? SetDefaultValueSql(
[NotNull] this IConventionProperty property,
- [CanBeNull] string value,
+ [CanBeNull] string? value,
bool fromDataAnnotation = false)
{
property.SetOrRemoveAnnotation(
@@ -537,16 +530,8 @@ public static string SetDefaultValueSql(
///
/// The property.
/// The SQL expression that is used as the computed value for the column this property is mapped to.
- public static string GetComputedColumnSql([NotNull] this IProperty property)
- {
- var annotation = property.FindAnnotation(RelationalAnnotationNames.ComputedColumnSql);
- if (annotation != null)
- {
- return (string)annotation.Value;
- }
-
- return null;
- }
+ public static string? GetComputedColumnSql([NotNull] this IProperty property)
+ => (string?)property.FindAnnotation(RelationalAnnotationNames.ComputedColumnSql)?.Value;
///
/// Returns the SQL expression that is used as the computed value for the column this property is mapped to.
@@ -554,7 +539,7 @@ public static string GetComputedColumnSql([NotNull] this IProperty property)
/// The property.
/// The identifier of the table-like store object containing the column.
/// The SQL expression that is used as the computed value for the column this property is mapped to.
- public static string GetComputedColumnSql([NotNull] this IProperty property, in StoreObjectIdentifier storeObject)
+ public static string? GetComputedColumnSql([NotNull] this IProperty property, in StoreObjectIdentifier storeObject)
{
var annotation = property.FindAnnotation(RelationalAnnotationNames.ComputedColumnSql);
if (annotation != null)
@@ -576,7 +561,7 @@ public static string GetComputedColumnSql([NotNull] this IProperty property, in
///
/// The property.
/// The value to set.
- public static void SetComputedColumnSql([NotNull] this IMutableProperty property, [CanBeNull] string value)
+ public static void SetComputedColumnSql([NotNull] this IMutableProperty property, [CanBeNull] string? value)
=> property.SetOrRemoveAnnotation(
RelationalAnnotationNames.ComputedColumnSql,
value);
@@ -588,9 +573,9 @@ public static void SetComputedColumnSql([NotNull] this IMutableProperty property
/// The value to set.
/// Indicates whether the configuration was specified using a data annotation.
/// The configured value.
- public static string SetComputedColumnSql(
+ public static string? SetComputedColumnSql(
[NotNull] this IConventionProperty property,
- [CanBeNull] string value,
+ [CanBeNull] string? value,
bool fromDataAnnotation = false)
{
property.SetOrRemoveAnnotation(
@@ -619,10 +604,7 @@ public static string SetComputedColumnSql(
/// or calculated when it is read.
///
public static bool? GetIsStored([NotNull] this IProperty property)
- {
- var annotation = property.FindAnnotation(RelationalAnnotationNames.IsStored);
- return annotation != null ? (bool?)annotation.Value : null;
- }
+ => (bool?)property.FindAnnotation(RelationalAnnotationNames.IsStored)?.Value;
///
/// Gets whether the value of the computed column this property is mapped to is stored in the database, or calculated when
@@ -658,9 +640,7 @@ public static string SetComputedColumnSql(
/// The property.
/// The value to set.
public static void SetIsStored([NotNull] this IMutableProperty property, bool? value)
- => property.SetOrRemoveAnnotation(
- RelationalAnnotationNames.IsStored,
- value);
+ => property.SetOrRemoveAnnotation(RelationalAnnotationNames.IsStored, value);
///
/// Sets whether the value of the computed column this property is mapped to is stored in the database, or calculated when
@@ -693,11 +673,8 @@ public static void SetIsStored([NotNull] this IMutableProperty property, bool? v
///
/// The property.
/// The object that is used as the default value for the column this property is mapped to.
- public static object GetDefaultValue([NotNull] this IProperty property)
- {
- var annotation = property.FindAnnotation(RelationalAnnotationNames.DefaultValue);
- return annotation != null ? annotation.Value : null;
- }
+ public static object? GetDefaultValue([NotNull] this IProperty property)
+ => property.FindAnnotation(RelationalAnnotationNames.DefaultValue)?.Value;
///
/// Returns the object that is used as the default value for the column this property is mapped to.
@@ -705,7 +682,7 @@ public static object GetDefaultValue([NotNull] this IProperty property)
/// The property.
/// The identifier of the table-like store object containing the column.
/// The object that is used as the default value for the column this property is mapped to.
- public static object GetDefaultValue([NotNull] this IProperty property, in StoreObjectIdentifier storeObject)
+ public static object? GetDefaultValue([NotNull] this IProperty property, in StoreObjectIdentifier storeObject)
{
var annotation = property.FindAnnotation(RelationalAnnotationNames.DefaultValue);
if (annotation != null)
@@ -727,7 +704,7 @@ public static object GetDefaultValue([NotNull] this IProperty property, in Store
///
/// The property.
/// The value to set.
- public static void SetDefaultValue([NotNull] this IMutableProperty property, [CanBeNull] object value)
+ public static void SetDefaultValue([NotNull] this IMutableProperty property, [CanBeNull] object? value)
=> property.SetOrRemoveAnnotation(RelationalAnnotationNames.DefaultValue, ConvertDefaultValue(property, value));
///
@@ -737,9 +714,9 @@ public static void SetDefaultValue([NotNull] this IMutableProperty property, [Ca
/// The value to set.
/// Indicates whether the configuration was specified using a data annotation.
/// The configured value.
- public static object SetDefaultValue(
+ public static object? SetDefaultValue(
[NotNull] this IConventionProperty property,
- [CanBeNull] object value,
+ [CanBeNull] object? value,
bool fromDataAnnotation = false)
{
property.SetOrRemoveAnnotation(
@@ -748,7 +725,7 @@ public static object SetDefaultValue(
return value;
}
- private static object ConvertDefaultValue([NotNull] IProperty property, [CanBeNull] object value)
+ private static object? ConvertDefaultValue([NotNull] IProperty property, [CanBeNull] object? value)
{
if (value == null
|| value == DBNull.Value)
@@ -871,10 +848,7 @@ private static object ConvertDefaultValue([NotNull] IProperty property, [CanBeNu
/// The property.
/// A flag indicating if the property as capable of storing only fixed-length data, such as strings.
public static bool? IsFixedLength([NotNull] this IProperty property)
- {
- var annotation = property.FindAnnotation(RelationalAnnotationNames.IsFixedLength);
- return annotation != null ? (bool?)annotation.Value : null;
- }
+ => (bool?)property.FindAnnotation(RelationalAnnotationNames.IsFixedLength)?.Value;
///
/// Returns a flag indicating if the property as capable of storing only fixed-length data, such as strings.
@@ -1004,11 +978,8 @@ private static bool IsOptionalSharingDependent(IEntityType entityType, in StoreO
///
/// The property.
/// The comment for the column this property is mapped to.
- public static string GetComment([NotNull] this IProperty property)
- {
- var annotation = property.FindAnnotation(RelationalAnnotationNames.Comment);
- return annotation != null ? (string)annotation.Value : null;
- }
+ public static string? GetComment([NotNull] this IProperty property)
+ => (string?)property.FindAnnotation(RelationalAnnotationNames.Comment)?.Value;
///
/// Returns the comment for the column this property is mapped to.
@@ -1016,7 +987,7 @@ public static string GetComment([NotNull] this IProperty property)
/// The property.
/// The identifier of the table-like store object containing the column.
/// The comment for the column this property is mapped to.
- public static string GetComment([NotNull] this IProperty property, in StoreObjectIdentifier storeObject)
+ public static string? GetComment([NotNull] this IProperty property, in StoreObjectIdentifier storeObject)
{
var annotation = property.FindAnnotation(RelationalAnnotationNames.Comment);
if (annotation != null)
@@ -1038,7 +1009,7 @@ public static string GetComment([NotNull] this IProperty property, in StoreObjec
///
/// The property.
/// The comment for the column.
- public static void SetComment([NotNull] this IMutableProperty property, [CanBeNull] string comment)
+ public static void SetComment([NotNull] this IMutableProperty property, [CanBeNull] string? comment)
=> property.SetOrRemoveAnnotation(RelationalAnnotationNames.Comment, comment);
///
@@ -1048,9 +1019,9 @@ public static void SetComment([NotNull] this IMutableProperty property, [CanBeNu
/// The comment for the column.
/// Indicates whether the configuration was specified using a data annotation.
/// The configured value.
- public static string SetComment(
+ public static string? SetComment(
[NotNull] this IConventionProperty property,
- [CanBeNull] string comment,
+ [CanBeNull] string? comment,
bool fromDataAnnotation = false)
{
property.SetOrRemoveAnnotation(RelationalAnnotationNames.Comment, comment, fromDataAnnotation);
@@ -1072,11 +1043,8 @@ public static string SetComment(
///
/// The property.
/// The collation for the column this property is mapped to.
- public static string GetCollation([NotNull] this IProperty property)
- {
- var annotation = property.FindAnnotation(RelationalAnnotationNames.Collation);
- return annotation != null ? (string)annotation.Value : null;
- }
+ public static string? GetCollation([NotNull] this IProperty property)
+ => (string?)property.FindAnnotation(RelationalAnnotationNames.Collation)?.Value;
///
/// Returns the collation to be used for the column.
@@ -1084,7 +1052,7 @@ public static string GetCollation([NotNull] this IProperty property)
/// The property.
/// The identifier of the table-like store object containing the column.
/// The collation for the column this property is mapped to.
- public static string GetCollation([NotNull] this IProperty property, in StoreObjectIdentifier storeObject)
+ public static string? GetCollation([NotNull] this IProperty property, in StoreObjectIdentifier storeObject)
{
var annotation = property.FindAnnotation(RelationalAnnotationNames.Collation);
if (annotation != null)
@@ -1106,7 +1074,7 @@ public static string GetCollation([NotNull] this IProperty property, in StoreObj
///
/// The property.
/// The collation for the column.
- public static void SetCollation([NotNull] this IMutableProperty property, [CanBeNull] string collation)
+ public static void SetCollation([NotNull] this IMutableProperty property, [CanBeNull] string? collation)
=> property.SetOrRemoveAnnotation(RelationalAnnotationNames.Collation, collation);
///
@@ -1116,9 +1084,9 @@ public static void SetCollation([NotNull] this IMutableProperty property, [CanBe
/// The collation for the column.
/// Indicates whether the configuration was specified using a data annotation.
/// The configured value.
- public static string SetCollation(
+ public static string? SetCollation(
[NotNull] this IConventionProperty property,
- [CanBeNull] string collation,
+ [CanBeNull] string? collation,
bool fromDataAnnotation = false)
{
property.SetOrRemoveAnnotation(RelationalAnnotationNames.Collation, collation, fromDataAnnotation);
@@ -1149,7 +1117,7 @@ public static RelationalTypeMapping GetRelationalTypeMapping([NotNull] this IPro
/// The type mapping, or if none was found.
[DebuggerStepThrough]
[Obsolete("Use FindRelationalTypeMapping")]
- public static RelationalTypeMapping FindRelationalMapping([NotNull] this IProperty property)
+ public static RelationalTypeMapping? FindRelationalMapping([NotNull] this IProperty property)
=> property.FindRelationalTypeMapping();
///
@@ -1158,8 +1126,8 @@ public static RelationalTypeMapping FindRelationalMapping([NotNull] this IProper
/// The property.
/// The type mapping, or if none was found.
[DebuggerStepThrough]
- public static RelationalTypeMapping FindRelationalTypeMapping([NotNull] this IProperty property)
- => (RelationalTypeMapping)property.FindTypeMapping();
+ public static RelationalTypeMapping? FindRelationalTypeMapping([NotNull] this IProperty property)
+ => (RelationalTypeMapping?)property.FindTypeMapping();
///
/// Returns the for the given property on a finalized model.
@@ -1167,7 +1135,7 @@ public static RelationalTypeMapping FindRelationalTypeMapping([NotNull] this IPr
/// The property.
/// The identifier of the table-like store object containing the column.
/// The type mapping, or if none was found.
- public static RelationalTypeMapping FindRelationalTypeMapping(
+ public static RelationalTypeMapping? FindRelationalTypeMapping(
[NotNull] this IProperty property,
in StoreObjectIdentifier storeObject)
=> property.FindRelationalTypeMapping();
@@ -1184,7 +1152,7 @@ public static RelationalTypeMapping FindRelationalTypeMapping(
/// The property.
/// The identifier of the table-like store object containing the column.
/// The property found, or if none was found.
- public static IProperty FindSharedStoreObjectRootProperty(
+ public static IProperty? FindSharedStoreObjectRootProperty(
[NotNull] this IProperty property,
in StoreObjectIdentifier storeObject)
=> FindSharedObjectRootProperty(property, storeObject);
@@ -1201,10 +1169,10 @@ public static IProperty FindSharedStoreObjectRootProperty(
/// The property.
/// The identifier of the table-like store object containing the column.
/// The property found, or if none was found.
- public static IMutableProperty FindSharedStoreObjectRootProperty(
+ public static IMutableProperty? FindSharedStoreObjectRootProperty(
[NotNull] this IMutableProperty property,
in StoreObjectIdentifier storeObject)
- => (IMutableProperty)FindSharedObjectRootProperty(property, storeObject);
+ => (IMutableProperty?)FindSharedObjectRootProperty(property, storeObject);
///
///
@@ -1218,12 +1186,12 @@ public static IMutableProperty FindSharedStoreObjectRootProperty(
/// The property.
/// The identifier of the table-like store object containing the column.
/// The property found, or if none was found.
- public static IConventionProperty FindSharedStoreObjectRootProperty(
+ public static IConventionProperty? FindSharedStoreObjectRootProperty(
[NotNull] this IConventionProperty property,
in StoreObjectIdentifier storeObject)
- => (IConventionProperty)FindSharedObjectRootProperty(property, storeObject);
+ => (IConventionProperty?)FindSharedObjectRootProperty(property, storeObject);
- private static IProperty FindSharedObjectRootProperty([NotNull] IProperty property, in StoreObjectIdentifier storeObject)
+ private static IProperty? FindSharedObjectRootProperty([NotNull] IProperty property, in StoreObjectIdentifier storeObject)
{
Check.NotNull(property, nameof(property));
@@ -1242,7 +1210,7 @@ private static IProperty FindSharedObjectRootProperty([NotNull] IProperty proper
// Using a hashset is detrimental to the perf when there are no cycles
for (var i = 0; i < Metadata.Internal.RelationalEntityTypeExtensions.MaxEntityTypesSharingTable; i++)
{
- IProperty linkedProperty = null;
+ IProperty? linkedProperty = null;
foreach (var p in rootProperty.DeclaringEntityType
.FindRowInternalForeignKeys(storeObject)
.SelectMany(fk => fk.PrincipalEntityType.GetProperties()))
@@ -1265,7 +1233,7 @@ private static IProperty FindSharedObjectRootProperty([NotNull] IProperty proper
return rootProperty == property ? null : rootProperty;
}
- private static IProperty FindSharedObjectRootPrimaryKeyProperty([NotNull] IProperty property, in StoreObjectIdentifier storeObject)
+ private static IProperty? FindSharedObjectRootPrimaryKeyProperty([NotNull] IProperty property, in StoreObjectIdentifier storeObject)
{
if (!property.IsPrimaryKey())
{
@@ -1291,7 +1259,7 @@ private static IProperty FindSharedObjectRootPrimaryKeyProperty([NotNull] IPrope
return principalProperty == property ? null : principalProperty;
}
- private static IProperty FindSharedObjectRootConcurrencyTokenProperty(
+ private static IProperty? FindSharedObjectRootConcurrencyTokenProperty(
[NotNull] IProperty property,
in StoreObjectIdentifier storeObject)
{
@@ -1335,7 +1303,7 @@ private static IProperty FindSharedObjectRootConcurrencyTokenProperty(
/// The property.
/// The identifier of the table-like store object containing the column.
/// An object that stores property facet overrides.
- public static IAnnotatable FindOverrides([NotNull] this IProperty property, in StoreObjectIdentifier storeObject)
+ public static IAnnotatable? FindOverrides([NotNull] this IProperty property, in StoreObjectIdentifier storeObject)
=> RelationalPropertyOverrides.Find(property, storeObject);
///
diff --git a/src/EFCore.Relational/Metadata/Builders/DbFunctionBuilder.cs b/src/EFCore.Relational/Metadata/Builders/DbFunctionBuilder.cs
index bb69a0497bf..cb26118aa0e 100644
--- a/src/EFCore.Relational/Metadata/Builders/DbFunctionBuilder.cs
+++ b/src/EFCore.Relational/Metadata/Builders/DbFunctionBuilder.cs
@@ -7,6 +7,8 @@
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Query.SqlExpressions;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Metadata.Builders
{
///
@@ -39,7 +41,7 @@ public DbFunctionBuilder([NotNull] IMutableDbFunction function)
///
/// The schema of the function in the database.
/// The same builder instance so that multiple configuration calls can be chained.
- public new virtual DbFunctionBuilder HasSchema([CanBeNull] string schema)
+ public new virtual DbFunctionBuilder HasSchema([CanBeNull] string? schema)
=> (DbFunctionBuilder)base.HasSchema(schema);
///
@@ -67,7 +69,7 @@ public virtual DbFunctionBuilderBase IsNullable(bool nullable = true)
///
/// The return store type of the function in the database.
/// The same builder instance so that multiple configuration calls can be chained.
- public virtual DbFunctionBuilder HasStoreType([CanBeNull] string storeType)
+ public virtual DbFunctionBuilder HasStoreType([CanBeNull] string? storeType)
{
Builder.HasStoreType(storeType, ConfigurationSource.Explicit);
diff --git a/src/EFCore.Relational/Metadata/Builders/DbFunctionBuilderBase.cs b/src/EFCore.Relational/Metadata/Builders/DbFunctionBuilderBase.cs
index e9527f38c42..4c48c001bea 100644
--- a/src/EFCore.Relational/Metadata/Builders/DbFunctionBuilderBase.cs
+++ b/src/EFCore.Relational/Metadata/Builders/DbFunctionBuilderBase.cs
@@ -9,6 +9,8 @@
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using Microsoft.EntityFrameworkCore.Utilities;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Metadata.Builders
{
///
@@ -68,7 +70,7 @@ public virtual DbFunctionBuilderBase HasName([NotNull] string name)
///
/// The schema of the function in the database.
/// The same builder instance so that multiple configuration calls can be chained.
- public virtual DbFunctionBuilderBase HasSchema([CanBeNull] string schema)
+ public virtual DbFunctionBuilderBase HasSchema([CanBeNull] string? schema)
{
Builder.HasSchema(schema, ConfigurationSource.Explicit);
@@ -103,7 +105,7 @@ public virtual DbFunctionParameterBuilder HasParameter([NotNull] string name)
///
/// A string that represents the current object.
[EditorBrowsable(EditorBrowsableState.Never)]
- public override string ToString()
+ public override string? ToString()
=> base.ToString();
///
@@ -113,7 +115,7 @@ public override string ToString()
/// if the specified object is equal to the current object; otherwise, .
[EditorBrowsable(EditorBrowsableState.Never)]
// ReSharper disable once BaseObjectEqualsIsObjectEquals
- public override bool Equals(object obj)
+ public override bool Equals(object? obj)
=> base.Equals(obj);
///
diff --git a/src/EFCore.Relational/Metadata/Builders/DbFunctionParameterBuilder.cs b/src/EFCore.Relational/Metadata/Builders/DbFunctionParameterBuilder.cs
index 2a45412830a..463d9f845fa 100644
--- a/src/EFCore.Relational/Metadata/Builders/DbFunctionParameterBuilder.cs
+++ b/src/EFCore.Relational/Metadata/Builders/DbFunctionParameterBuilder.cs
@@ -9,6 +9,8 @@
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using Microsoft.EntityFrameworkCore.Utilities;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Metadata.Builders
{
///
@@ -33,7 +35,7 @@ public DbFunctionParameterBuilder([NotNull] IMutableDbFunctionParameter paramete
{
Check.NotNull(parameter, nameof(parameter));
- Builder = ((DbFunctionParameter)parameter).Builder;
+ Builder = ((DbFunctionParameter)parameter).Builder!;
}
private InternalDbFunctionParameterBuilder Builder { [DebuggerStepThrough] get; }
@@ -56,7 +58,7 @@ public virtual IMutableDbFunctionParameter Metadata
///
/// The store type of the function parameter in the database.
/// The same builder instance so that further configuration calls can be chained.
- public virtual DbFunctionParameterBuilder HasStoreType([CanBeNull] string storeType)
+ public virtual DbFunctionParameterBuilder HasStoreType([CanBeNull] string? storeType)
{
Builder.HasStoreType(storeType, ConfigurationSource.Explicit);
@@ -82,7 +84,7 @@ public virtual DbFunctionParameterBuilder PropagatesNullability(bool propagatesN
///
/// A string that represents the current object.
[EditorBrowsable(EditorBrowsableState.Never)]
- public override string ToString()
+ public override string? ToString()
=> base.ToString();
///
@@ -92,7 +94,7 @@ public override string ToString()
/// if the specified object is equal to the current object; otherwise, .
[EditorBrowsable(EditorBrowsableState.Never)]
// ReSharper disable once BaseObjectEqualsIsObjectEquals
- public override bool Equals(object obj)
+ public override bool Equals(object? obj)
=> base.Equals(obj);
///
diff --git a/src/EFCore.Relational/Metadata/Builders/IConventionDbFunctionBuilder.cs b/src/EFCore.Relational/Metadata/Builders/IConventionDbFunctionBuilder.cs
index 46d173d189a..12f13948909 100644
--- a/src/EFCore.Relational/Metadata/Builders/IConventionDbFunctionBuilder.cs
+++ b/src/EFCore.Relational/Metadata/Builders/IConventionDbFunctionBuilder.cs
@@ -7,6 +7,8 @@
using Microsoft.EntityFrameworkCore.Query.SqlExpressions;
using Microsoft.EntityFrameworkCore.Storage;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Metadata.Builders
{
///
@@ -28,7 +30,7 @@ public interface IConventionDbFunctionBuilder : IConventionAnnotatableBuilder
/// The same builder instance if the configuration was applied,
/// otherwise.
///
- IConventionDbFunctionBuilder HasName([CanBeNull] string name, bool fromDataAnnotation = false);
+ IConventionDbFunctionBuilder? HasName([CanBeNull] string? name, bool fromDataAnnotation = false);
///
/// Returns a value indicating whether the given name can be set for the database function.
@@ -36,7 +38,7 @@ public interface IConventionDbFunctionBuilder : IConventionAnnotatableBuilder
/// The name of the function in the database.
/// Indicates whether the configuration was specified using a data annotation.
/// if the given name can be set for the database function.
- bool CanSetName([CanBeNull] string name, bool fromDataAnnotation = false);
+ bool CanSetName([CanBeNull] string? name, bool fromDataAnnotation = false);
///
/// Sets the schema of the database function.
@@ -47,7 +49,7 @@ public interface IConventionDbFunctionBuilder : IConventionAnnotatableBuilder
/// The same builder instance if the configuration was applied,
/// otherwise.
///
- IConventionDbFunctionBuilder HasSchema([CanBeNull] string schema, bool fromDataAnnotation = false);
+ IConventionDbFunctionBuilder? HasSchema([CanBeNull] string? schema, bool fromDataAnnotation = false);
///
/// Returns a value indicating whether the given schema can be set for the database function.
@@ -55,7 +57,7 @@ public interface IConventionDbFunctionBuilder : IConventionAnnotatableBuilder
/// The schema of the function in the database.
/// Indicates whether the configuration was specified using a data annotation.
/// if the given schema can be set for the database function.
- bool CanSetSchema([CanBeNull] string schema, bool fromDataAnnotation = false);
+ bool CanSetSchema([CanBeNull] string? schema, bool fromDataAnnotation = false);
///
/// Sets the value indicating whether the database function is built-in or not.
@@ -66,7 +68,7 @@ public interface IConventionDbFunctionBuilder : IConventionAnnotatableBuilder
/// The same builder instance if the configuration was applied,
/// otherwise.
///
- IConventionDbFunctionBuilder IsBuiltIn(bool builtIn, bool fromDataAnnotation = false);
+ IConventionDbFunctionBuilder? IsBuiltIn(bool builtIn, bool fromDataAnnotation = false);
///
/// Returns a value indicating whether the given built-in can be set for the database function.
@@ -85,7 +87,7 @@ public interface IConventionDbFunctionBuilder : IConventionAnnotatableBuilder
/// The same builder instance if the configuration was applied,
/// otherwise.
///
- IConventionDbFunctionBuilder IsNullable(bool nullable, bool fromDataAnnotation = false);
+ IConventionDbFunctionBuilder? IsNullable(bool nullable, bool fromDataAnnotation = false);
///
/// Returns a value indicating whether the given nullable can be set for the database function.
@@ -104,7 +106,7 @@ public interface IConventionDbFunctionBuilder : IConventionAnnotatableBuilder
/// The same builder instance if the configuration was applied,
/// otherwise.
///
- IConventionDbFunctionBuilder HasStoreType([CanBeNull] string storeType, bool fromDataAnnotation = false);
+ IConventionDbFunctionBuilder? HasStoreType([CanBeNull] string? storeType, bool fromDataAnnotation = false);
///
/// Returns a value indicating whether the given store type can be set for the database function.
@@ -112,7 +114,7 @@ public interface IConventionDbFunctionBuilder : IConventionAnnotatableBuilder
/// The store type of the function in the database.
/// Indicates whether the configuration was specified using a data annotation.
/// if the given store type can be set for the database function.
- bool CanSetStoreType([CanBeNull] string storeType, bool fromDataAnnotation = false);
+ bool CanSetStoreType([CanBeNull] string? storeType, bool fromDataAnnotation = false);
///
/// Sets the return type mapping of the database function.
@@ -123,7 +125,7 @@ public interface IConventionDbFunctionBuilder : IConventionAnnotatableBuilder
/// The same builder instance if the configuration was applied,
/// otherwise.
///
- IConventionDbFunctionBuilder HasTypeMapping([CanBeNull] RelationalTypeMapping typeMapping, bool fromDataAnnotation = false);
+ IConventionDbFunctionBuilder? HasTypeMapping([CanBeNull] RelationalTypeMapping? typeMapping, bool fromDataAnnotation = false);
///
/// Returns a value indicating whether the given return type mapping can be set for the database function.
@@ -131,7 +133,7 @@ public interface IConventionDbFunctionBuilder : IConventionAnnotatableBuilder
/// The return type mapping of the function in the database.
/// Indicates whether the configuration was specified using a data annotation.
/// if the given return type mapping can be set for the database function.
- bool CanSetTypeMapping([CanBeNull] RelationalTypeMapping typeMapping, bool fromDataAnnotation = false);
+ bool CanSetTypeMapping([CanBeNull] RelationalTypeMapping? typeMapping, bool fromDataAnnotation = false);
///
///
@@ -150,8 +152,8 @@ public interface IConventionDbFunctionBuilder : IConventionAnnotatableBuilder
/// The same builder instance if the configuration was applied,
/// otherwise.
///
- IConventionDbFunctionBuilder HasTranslation(
- [CanBeNull] Func, SqlExpression> translation,
+ IConventionDbFunctionBuilder? HasTranslation(
+ [CanBeNull] Func, SqlExpression>? translation,
bool fromDataAnnotation = false);
///
@@ -161,7 +163,7 @@ IConventionDbFunctionBuilder HasTranslation(
/// Indicates whether the configuration was specified using a data annotation.
/// if the given translation can be set for the database function.
bool CanSetTranslation(
- [CanBeNull] Func, SqlExpression> translation,
+ [CanBeNull] Func, SqlExpression>? translation,
bool fromDataAnnotation = false);
///
diff --git a/src/EFCore.Relational/Metadata/Builders/IConventionDbFunctionParameterBuilder.cs b/src/EFCore.Relational/Metadata/Builders/IConventionDbFunctionParameterBuilder.cs
index a4e8252b673..b37d69b9da7 100644
--- a/src/EFCore.Relational/Metadata/Builders/IConventionDbFunctionParameterBuilder.cs
+++ b/src/EFCore.Relational/Metadata/Builders/IConventionDbFunctionParameterBuilder.cs
@@ -4,6 +4,8 @@
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Storage;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Metadata.Builders
{
///
@@ -21,8 +23,8 @@ public interface IConventionDbFunctionParameterBuilder : IConventionAnnotatableB
///
/// The store type of the function parameter in the database.
/// Indicates whether the configuration was specified using a data annotation.
- /// The same builder instance if the configuration was applied; null otherwise.
- IConventionDbFunctionParameterBuilder HasStoreType([CanBeNull] string storeType, bool fromDataAnnotation = false);
+ /// The same builder instance if the configuration was applied; otherwise.
+ IConventionDbFunctionParameterBuilder? HasStoreType([CanBeNull] string? storeType, bool fromDataAnnotation = false);
///
/// Returns a value indicating whether the store type can be set for this property
@@ -31,16 +33,16 @@ public interface IConventionDbFunctionParameterBuilder : IConventionAnnotatableB
/// The store type of the function parameter in the database.
/// Indicates whether the configuration was specified using a data annotation.
/// if the store type can be set for this property.
- bool CanSetStoreType([CanBeNull] string storeType, bool fromDataAnnotation = false);
+ bool CanSetStoreType([CanBeNull] string? storeType, bool fromDataAnnotation = false);
///
/// Sets the of the function parameter.
///
/// The type mapping to use for the function parameter.
/// Indicates whether the configuration was specified using a data annotation.
- /// The same builder instance if the configuration was applied; null otherwise.
- IConventionDbFunctionParameterBuilder HasTypeMapping(
- [CanBeNull] RelationalTypeMapping typeMapping,
+ /// The same builder instance if the configuration was applied; otherwise.
+ IConventionDbFunctionParameterBuilder? HasTypeMapping(
+ [CanBeNull] RelationalTypeMapping? typeMapping,
bool fromDataAnnotation = false);
///
@@ -50,6 +52,6 @@ IConventionDbFunctionParameterBuilder HasTypeMapping(
/// The type mapping to use for the function parameter.
/// Indicates whether the configuration was specified using a data annotation.
/// if the type mapping can be set for this property.
- bool CanSetTypeMapping([CanBeNull] RelationalTypeMapping typeMapping, bool fromDataAnnotation = false);
+ bool CanSetTypeMapping([CanBeNull] RelationalTypeMapping? typeMapping, bool fromDataAnnotation = false);
}
}
diff --git a/src/EFCore.Relational/Metadata/Builders/IConventionSequenceBuilder.cs b/src/EFCore.Relational/Metadata/Builders/IConventionSequenceBuilder.cs
index e5f787e15a1..876e74680ab 100644
--- a/src/EFCore.Relational/Metadata/Builders/IConventionSequenceBuilder.cs
+++ b/src/EFCore.Relational/Metadata/Builders/IConventionSequenceBuilder.cs
@@ -4,6 +4,8 @@
using System;
using JetBrains.Annotations;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Metadata.Builders
{
///
@@ -25,7 +27,7 @@ public interface IConventionSequenceBuilder : IConventionAnnotatableBuilder
/// The same builder instance if the configuration was applied,
/// otherwise.
///
- IConventionSequenceBuilder HasType([CanBeNull] Type type, bool fromDataAnnotation = false);
+ IConventionSequenceBuilder? HasType([CanBeNull] Type? type, bool fromDataAnnotation = false);
///
/// Returns a value indicating whether the given type can be set for the sequence.
@@ -33,7 +35,7 @@ public interface IConventionSequenceBuilder : IConventionAnnotatableBuilder
/// The type of values returned by the sequence.
/// Indicates whether the configuration was specified using a data annotation.
/// if the given type can be set for the sequence.
- bool CanSetType([CanBeNull] Type type, bool fromDataAnnotation = false);
+ bool CanSetType([CanBeNull] Type? type, bool fromDataAnnotation = false);
///
/// Sets the sequence to increment by the given amount when generating each next value.
@@ -44,7 +46,7 @@ public interface IConventionSequenceBuilder : IConventionAnnotatableBuilder
/// The same builder instance if the configuration was applied,
/// otherwise.
///
- IConventionSequenceBuilder IncrementsBy(int? increment, bool fromDataAnnotation = false);
+ IConventionSequenceBuilder? IncrementsBy(int? increment, bool fromDataAnnotation = false);
///
/// Returns a value indicating whether the given increment can be set for the sequence.
@@ -63,7 +65,7 @@ public interface IConventionSequenceBuilder : IConventionAnnotatableBuilder
/// The same builder instance if the configuration was applied,
/// otherwise.
///
- IConventionSequenceBuilder StartsAt(long? startValue, bool fromDataAnnotation = false);
+ IConventionSequenceBuilder? StartsAt(long? startValue, bool fromDataAnnotation = false);
///
/// Returns a value indicating whether the given starting value can be set for the sequence.
@@ -82,7 +84,7 @@ public interface IConventionSequenceBuilder : IConventionAnnotatableBuilder
/// The same builder instance if the configuration was applied,
/// otherwise.
///
- IConventionSequenceBuilder HasMax(long? maximum, bool fromDataAnnotation = false);
+ IConventionSequenceBuilder? HasMax(long? maximum, bool fromDataAnnotation = false);
///
/// Returns a value indicating whether the given maximum value can be set for the sequence.
@@ -101,7 +103,7 @@ public interface IConventionSequenceBuilder : IConventionAnnotatableBuilder
/// The same builder instance if the configuration was applied,
/// otherwise.
///
- IConventionSequenceBuilder HasMin(long? minimum, bool fromDataAnnotation = false);
+ IConventionSequenceBuilder? HasMin(long? minimum, bool fromDataAnnotation = false);
///
/// Returns a value indicating whether the given minimum value can be set for the sequence.
@@ -121,7 +123,7 @@ public interface IConventionSequenceBuilder : IConventionAnnotatableBuilder
/// The same builder instance if the configuration was applied,
/// otherwise.
///
- IConventionSequenceBuilder IsCyclic(bool? cyclic, bool fromDataAnnotation = false);
+ IConventionSequenceBuilder? IsCyclic(bool? cyclic, bool fromDataAnnotation = false);
///
/// Returns a value indicating whether the given cyclicity can be set for the sequence.
diff --git a/src/EFCore.Relational/Metadata/Builders/SequenceBuilder.cs b/src/EFCore.Relational/Metadata/Builders/SequenceBuilder.cs
index 052dfbc3f8b..1498ec69b29 100644
--- a/src/EFCore.Relational/Metadata/Builders/SequenceBuilder.cs
+++ b/src/EFCore.Relational/Metadata/Builders/SequenceBuilder.cs
@@ -9,6 +9,8 @@
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using Microsoft.EntityFrameworkCore.Utilities;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Metadata.Builders
{
///
@@ -110,7 +112,7 @@ public virtual SequenceBuilder IsCyclic(bool cyclic = true)
///
/// A string that represents the current object.
[EditorBrowsable(EditorBrowsableState.Never)]
- public override string ToString()
+ public override string? ToString()
=> base.ToString();
///
@@ -120,7 +122,7 @@ public override string ToString()
/// if the specified object is equal to the current object; otherwise, .
[EditorBrowsable(EditorBrowsableState.Never)]
// ReSharper disable once BaseObjectEqualsIsObjectEquals
- public override bool Equals(object obj)
+ public override bool Equals(object? obj)
=> base.Equals(obj);
///
diff --git a/src/EFCore.Relational/Metadata/Builders/TableBuilder.cs b/src/EFCore.Relational/Metadata/Builders/TableBuilder.cs
index 1a8101095d3..667ff6340d4 100644
--- a/src/EFCore.Relational/Metadata/Builders/TableBuilder.cs
+++ b/src/EFCore.Relational/Metadata/Builders/TableBuilder.cs
@@ -6,6 +6,8 @@
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Infrastructure;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Metadata.Builders
{
///
@@ -23,7 +25,7 @@ public class TableBuilder
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
[EntityFrameworkInternal]
- public TableBuilder([NotNull] string name, [CanBeNull] string schema, [NotNull] IMutableEntityType entityType)
+ public TableBuilder([NotNull] string name, [CanBeNull] string? schema, [NotNull] IMutableEntityType entityType)
{
EntityType = entityType;
}
@@ -48,7 +50,7 @@ public virtual TableBuilder ExcludeFromMigrations(bool excluded = true)
///
/// A string that represents the current object.
[EditorBrowsable(EditorBrowsableState.Never)]
- public override string ToString()
+ public override string? ToString()
=> base.ToString();
///
@@ -57,7 +59,7 @@ public override string ToString()
/// The object to compare with the current object.
/// if the specified object is equal to the current object; otherwise, .
[EditorBrowsable(EditorBrowsableState.Never)]
- public override bool Equals(object obj)
+ public override bool Equals(object? obj)
=> base.Equals(obj);
///
diff --git a/src/EFCore.Relational/Metadata/Builders/TableBuilder`.cs b/src/EFCore.Relational/Metadata/Builders/TableBuilder`.cs
index 3abfff21e74..301f3ec2eaf 100644
--- a/src/EFCore.Relational/Metadata/Builders/TableBuilder`.cs
+++ b/src/EFCore.Relational/Metadata/Builders/TableBuilder`.cs
@@ -4,6 +4,8 @@
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Infrastructure;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Metadata.Builders
{
///
@@ -23,7 +25,7 @@ public class TableBuilder : TableBuilder
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
[EntityFrameworkInternal]
- public TableBuilder([NotNull] string name, [CanBeNull] string schema, [NotNull] IMutableEntityType entityType)
+ public TableBuilder([NotNull] string name, [CanBeNull] string? schema, [NotNull] IMutableEntityType entityType)
: base(name, schema, entityType)
{
}
diff --git a/src/EFCore.Relational/Metadata/Builders/TableValuedFunctionBuilder.cs b/src/EFCore.Relational/Metadata/Builders/TableValuedFunctionBuilder.cs
index 6ed5c1fd3c9..7615b673451 100644
--- a/src/EFCore.Relational/Metadata/Builders/TableValuedFunctionBuilder.cs
+++ b/src/EFCore.Relational/Metadata/Builders/TableValuedFunctionBuilder.cs
@@ -4,6 +4,8 @@
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Infrastructure;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Metadata.Builders
{
///
@@ -36,7 +38,7 @@ public TableValuedFunctionBuilder([NotNull] IMutableDbFunction function)
///
/// The schema of the function in the database.
/// The same builder instance so that multiple configuration calls can be chained.
- public new virtual TableValuedFunctionBuilder HasSchema([CanBeNull] string schema)
+ public new virtual TableValuedFunctionBuilder HasSchema([CanBeNull] string? schema)
=> (TableValuedFunctionBuilder)base.HasSchema(schema);
}
}
diff --git a/src/EFCore.Relational/Metadata/Conventions/DbFunctionTypeMappingConvention.cs b/src/EFCore.Relational/Metadata/Conventions/DbFunctionTypeMappingConvention.cs
index 71572aadc61..46b471a136f 100644
--- a/src/EFCore.Relational/Metadata/Conventions/DbFunctionTypeMappingConvention.cs
+++ b/src/EFCore.Relational/Metadata/Conventions/DbFunctionTypeMappingConvention.cs
@@ -7,6 +7,8 @@
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.EntityFrameworkCore.Utilities;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Metadata.Conventions
{
///
@@ -44,7 +46,7 @@ public virtual void ProcessModelFinalizing(
// TODO: This check needs to be updated to skip over enumerable parameter of aggregate.
foreach (var parameter in dbFunction.Parameters)
{
- parameter.Builder.HasTypeMapping(
+ parameter.Builder!.HasTypeMapping(
!string.IsNullOrEmpty(parameter.StoreType)
? _relationalTypeMappingSource.FindMapping(parameter.StoreType)
: _relationalTypeMappingSource.FindMapping(parameter.ClrType));
diff --git a/src/EFCore.Relational/Metadata/Conventions/EntityTypeHierarchyMappingConvention.cs b/src/EFCore.Relational/Metadata/Conventions/EntityTypeHierarchyMappingConvention.cs
index 21f6b1342ec..61f35e770cc 100644
--- a/src/EFCore.Relational/Metadata/Conventions/EntityTypeHierarchyMappingConvention.cs
+++ b/src/EFCore.Relational/Metadata/Conventions/EntityTypeHierarchyMappingConvention.cs
@@ -7,6 +7,8 @@
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Metadata.Conventions
{
///
@@ -50,7 +52,7 @@ public virtual void ProcessModelFinalizing(
&& !entityType.FindDeclaredForeignKeys(pk.Properties)
.Any(fk => fk.PrincipalKey.IsPrimaryKey() && fk.PrincipalEntityType.IsAssignableFrom(entityType)))
{
- entityType.Builder.HasRelationship(entityType.BaseType, pk.Properties, entityType.BaseType.FindPrimaryKey())
+ entityType.Builder.HasRelationship(entityType.BaseType, pk.Properties, pk)?
.IsUnique(true);
}
diff --git a/src/EFCore.Relational/Metadata/Conventions/Infrastructure/RelationalConventionSetBuilder.cs b/src/EFCore.Relational/Metadata/Conventions/Infrastructure/RelationalConventionSetBuilder.cs
index 7fa15a200fd..676c00f7e91 100644
--- a/src/EFCore.Relational/Metadata/Conventions/Infrastructure/RelationalConventionSetBuilder.cs
+++ b/src/EFCore.Relational/Metadata/Conventions/Infrastructure/RelationalConventionSetBuilder.cs
@@ -5,6 +5,8 @@
using Microsoft.EntityFrameworkCore.Utilities;
using Microsoft.Extensions.DependencyInjection;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure
{
///
diff --git a/src/EFCore.Relational/Metadata/Conventions/Infrastructure/RelationalConventionSetBuilderDependencies.cs b/src/EFCore.Relational/Metadata/Conventions/Infrastructure/RelationalConventionSetBuilderDependencies.cs
index 46b2e28feba..e3c71fc1452 100644
--- a/src/EFCore.Relational/Metadata/Conventions/Infrastructure/RelationalConventionSetBuilderDependencies.cs
+++ b/src/EFCore.Relational/Metadata/Conventions/Infrastructure/RelationalConventionSetBuilderDependencies.cs
@@ -6,6 +6,8 @@
using Microsoft.EntityFrameworkCore.Utilities;
using Microsoft.Extensions.DependencyInjection;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure
{
///
diff --git a/src/EFCore.Relational/Metadata/Conventions/RelationalColumnAttributeConvention.cs b/src/EFCore.Relational/Metadata/Conventions/RelationalColumnAttributeConvention.cs
index a7275a67ae0..f2777eaea29 100644
--- a/src/EFCore.Relational/Metadata/Conventions/RelationalColumnAttributeConvention.cs
+++ b/src/EFCore.Relational/Metadata/Conventions/RelationalColumnAttributeConvention.cs
@@ -7,6 +7,8 @@
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Metadata.Conventions
{
///
diff --git a/src/EFCore.Relational/Metadata/Conventions/RelationalColumnCommentAttributeConvention.cs b/src/EFCore.Relational/Metadata/Conventions/RelationalColumnCommentAttributeConvention.cs
index f6f50f0741b..e2f64e89d34 100644
--- a/src/EFCore.Relational/Metadata/Conventions/RelationalColumnCommentAttributeConvention.cs
+++ b/src/EFCore.Relational/Metadata/Conventions/RelationalColumnCommentAttributeConvention.cs
@@ -6,6 +6,8 @@
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Metadata.Conventions
{
///
diff --git a/src/EFCore.Relational/Metadata/Conventions/RelationalDbFunctionAttributeConvention.cs b/src/EFCore.Relational/Metadata/Conventions/RelationalDbFunctionAttributeConvention.cs
index 499d090ad28..f9148066750 100644
--- a/src/EFCore.Relational/Metadata/Conventions/RelationalDbFunctionAttributeConvention.cs
+++ b/src/EFCore.Relational/Metadata/Conventions/RelationalDbFunctionAttributeConvention.cs
@@ -7,6 +7,8 @@
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Metadata.Conventions
{
///
diff --git a/src/EFCore.Relational/Metadata/Conventions/RelationalMaxIdentifierLengthConvention.cs b/src/EFCore.Relational/Metadata/Conventions/RelationalMaxIdentifierLengthConvention.cs
index b8b61188626..c6f696afc41 100644
--- a/src/EFCore.Relational/Metadata/Conventions/RelationalMaxIdentifierLengthConvention.cs
+++ b/src/EFCore.Relational/Metadata/Conventions/RelationalMaxIdentifierLengthConvention.cs
@@ -5,6 +5,8 @@
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Metadata.Conventions
{
///
diff --git a/src/EFCore.Relational/Metadata/Conventions/RelationalModelConvention.cs b/src/EFCore.Relational/Metadata/Conventions/RelationalModelConvention.cs
index 365a20fddfb..3d8e7dcfc4c 100644
--- a/src/EFCore.Relational/Metadata/Conventions/RelationalModelConvention.cs
+++ b/src/EFCore.Relational/Metadata/Conventions/RelationalModelConvention.cs
@@ -5,6 +5,8 @@
using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Metadata.Conventions
{
///
diff --git a/src/EFCore.Relational/Metadata/Conventions/RelationalQueryFilterRewritingConvention.cs b/src/EFCore.Relational/Metadata/Conventions/RelationalQueryFilterRewritingConvention.cs
index 9aad20eed92..47ff3d83192 100644
--- a/src/EFCore.Relational/Metadata/Conventions/RelationalQueryFilterRewritingConvention.cs
+++ b/src/EFCore.Relational/Metadata/Conventions/RelationalQueryFilterRewritingConvention.cs
@@ -10,6 +10,8 @@
using Microsoft.EntityFrameworkCore.Query.Internal;
using Microsoft.EntityFrameworkCore.Utilities;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Metadata.Conventions
{
///
@@ -80,7 +82,7 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp
if (methodName == nameof(RelationalQueryableExtensions.FromSqlRaw))
{
- sql = (string)((ConstantExpression)methodCallExpression.Arguments[1]).Value;
+ sql = (string)((ConstantExpression)methodCallExpression.Arguments[1]).Value!;
argument = methodCallExpression.Arguments[2];
}
else
diff --git a/src/EFCore.Relational/Metadata/Conventions/RelationalTableAttributeConvention.cs b/src/EFCore.Relational/Metadata/Conventions/RelationalTableAttributeConvention.cs
index c32c7214ebc..ee2b64f90d9 100644
--- a/src/EFCore.Relational/Metadata/Conventions/RelationalTableAttributeConvention.cs
+++ b/src/EFCore.Relational/Metadata/Conventions/RelationalTableAttributeConvention.cs
@@ -6,6 +6,8 @@
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Metadata.Conventions
{
///
diff --git a/src/EFCore.Relational/Metadata/Conventions/RelationalTableCommentAttributeConvention.cs b/src/EFCore.Relational/Metadata/Conventions/RelationalTableCommentAttributeConvention.cs
index 98055cbb0ea..8011e9de48e 100644
--- a/src/EFCore.Relational/Metadata/Conventions/RelationalTableCommentAttributeConvention.cs
+++ b/src/EFCore.Relational/Metadata/Conventions/RelationalTableCommentAttributeConvention.cs
@@ -5,6 +5,8 @@
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Metadata.Conventions
{
///
diff --git a/src/EFCore.Relational/Metadata/Conventions/RelationalValueGenerationConvention.cs b/src/EFCore.Relational/Metadata/Conventions/RelationalValueGenerationConvention.cs
index c4bfa170505..a2be599a241 100644
--- a/src/EFCore.Relational/Metadata/Conventions/RelationalValueGenerationConvention.cs
+++ b/src/EFCore.Relational/Metadata/Conventions/RelationalValueGenerationConvention.cs
@@ -6,6 +6,8 @@
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Metadata.Conventions
{
///
@@ -41,8 +43,8 @@ public RelationalValueGenerationConvention(
public virtual void ProcessPropertyAnnotationChanged(
IConventionPropertyBuilder propertyBuilder,
string name,
- IConventionAnnotation annotation,
- IConventionAnnotation oldAnnotation,
+ IConventionAnnotation? annotation,
+ IConventionAnnotation? oldAnnotation,
IConventionContext context)
{
var property = propertyBuilder.Metadata;
@@ -67,8 +69,8 @@ public virtual void ProcessPropertyAnnotationChanged(
public virtual void ProcessEntityTypeAnnotationChanged(
IConventionEntityTypeBuilder entityTypeBuilder,
string name,
- IConventionAnnotation annotation,
- IConventionAnnotation oldAnnotation,
+ IConventionAnnotation? annotation,
+ IConventionAnnotation? oldAnnotation,
IConventionContext context)
{
if (name == RelationalAnnotationNames.TableName)
@@ -76,7 +78,7 @@ public virtual void ProcessEntityTypeAnnotationChanged(
var schema = entityTypeBuilder.Metadata.GetSchema();
ProcessTableChanged(
entityTypeBuilder,
- (string)oldAnnotation?.Value ?? entityTypeBuilder.Metadata.GetDefaultTableName(),
+ (string?)oldAnnotation?.Value ?? entityTypeBuilder.Metadata.GetDefaultTableName(),
schema,
entityTypeBuilder.Metadata.GetTableName(),
schema);
@@ -87,7 +89,7 @@ public virtual void ProcessEntityTypeAnnotationChanged(
ProcessTableChanged(
entityTypeBuilder,
tableName,
- (string)oldAnnotation?.Value ?? entityTypeBuilder.Metadata.GetDefaultSchema(),
+ (string?)oldAnnotation?.Value ?? entityTypeBuilder.Metadata.GetDefaultSchema(),
tableName,
entityTypeBuilder.Metadata.GetSchema());
}
@@ -95,10 +97,10 @@ public virtual void ProcessEntityTypeAnnotationChanged(
private void ProcessTableChanged(
IConventionEntityTypeBuilder entityTypeBuilder,
- string oldTable,
- string oldSchema,
- string newTable,
- string newSchema)
+ string? oldTable,
+ string? oldSchema,
+ string? newTable,
+ string? newSchema)
{
var primaryKey = entityTypeBuilder.Metadata.FindPrimaryKey();
if (primaryKey == null)
@@ -122,7 +124,7 @@ private void ProcessTableChanged(
foreach (var property in primaryKey.Properties)
{
- property.Builder.ValueGenerated(GetValueGenerated(property, StoreObjectIdentifier.Table(newTable, newSchema)));
+ property.Builder.ValueGenerated(GetValueGenerated(property, StoreObjectIdentifier.Table(newTable!, newSchema)));
}
}
diff --git a/src/EFCore.Relational/Metadata/Conventions/SequenceUniquificationConvention.cs b/src/EFCore.Relational/Metadata/Conventions/SequenceUniquificationConvention.cs
index c0bc8e2d55c..2591fecb7cc 100644
--- a/src/EFCore.Relational/Metadata/Conventions/SequenceUniquificationConvention.cs
+++ b/src/EFCore.Relational/Metadata/Conventions/SequenceUniquificationConvention.cs
@@ -9,6 +9,8 @@
using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Metadata.Conventions
{
///
@@ -41,7 +43,7 @@ public virtual void ProcessModelFinalizing(
{
var model = modelBuilder.Metadata;
var modelSequences =
- (SortedDictionary<(string Name, string Schema), Sequence>)model[RelationalAnnotationNames.Sequences];
+ (SortedDictionary<(string Name, string Schema), Sequence>?)model[RelationalAnnotationNames.Sequences];
if (modelSequences != null)
{
diff --git a/src/EFCore.Relational/Metadata/Conventions/SharedTableConvention.cs b/src/EFCore.Relational/Metadata/Conventions/SharedTableConvention.cs
index 52af47d29b6..b4531f39857 100644
--- a/src/EFCore.Relational/Metadata/Conventions/SharedTableConvention.cs
+++ b/src/EFCore.Relational/Metadata/Conventions/SharedTableConvention.cs
@@ -11,6 +11,8 @@
using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
+#nullable enable
+
namespace Microsoft.EntityFrameworkCore.Metadata.Conventions
{
///
@@ -41,7 +43,7 @@ public virtual void ProcessModelFinalizing(
IConventionContext context)
{
var maxLength = modelBuilder.Metadata.GetMaxIdentifierLength();
- var tables = new Dictionary<(string TableName, string Schema), List>();
+ var tables = new Dictionary<(string TableName, string? Schema), List>();
TryUniquifyTableNames(modelBuilder.Metadata, tables, maxLength);
@@ -68,20 +70,22 @@ public virtual void ProcessModelFinalizing(
private static void TryUniquifyTableNames(
IConventionModel model,
- Dictionary<(string Name, string Schema), List> tables,
+ Dictionary<(string Name, string? Schema), List> tables,
int maxLength)
{
- Dictionary<(string Name, string Schema), Dictionary<(string Name, string Schema), List>> clashingTables
+ Dictionary<(string Name, string? Schema), Dictionary<(string Name, string? Schema), List>>? clashingTables
= null;
foreach (var entityType in model.GetEntityTypes())
{
- var table = (Name: entityType.GetTableName(), Schema: entityType.GetSchema());
- if (table.Name == null
+ var tableName = entityType.GetTableName();
+ if (tableName == null
|| entityType.FindPrimaryKey() == null)
{
continue;
}
+ var table = (Name: tableName, Schema: entityType.GetSchema());
+
if (!tables.TryGetValue(table, out var entityTypes))
{
entityTypes = new List();
@@ -101,22 +105,17 @@ private static void TryUniquifyTableNames(
if (table.Name.Length == maxLength)
{
- var originalName = entityType.GetDefaultTableName(truncate: false);
+ var originalName = entityType.GetDefaultTableName(truncate: false)!;
if (originalName.Length == maxLength)
{
continue;
}
- if (clashingTables == null)
- {
- clashingTables =
- new Dictionary<(string Name, string Schema),
- Dictionary<(string Name, string Schema), List>>();
- }
+ clashingTables ??= new();
if (!clashingTables.TryGetValue(table, out var clashingSubTables))
{
- clashingSubTables = new Dictionary<(string Name, string Schema), List>();
+ clashingSubTables = new Dictionary<(string Name, string? Schema), List>();
clashingTables[table] = clashingSubTables;
}
@@ -174,9 +173,9 @@ private static void TryUniquifyColumnNames(
continue;
}
- var identifyingMemberInfo = property.PropertyInfo ?? (MemberInfo)property.FieldInfo;
+ var identifyingMemberInfo = property.PropertyInfo ?? (MemberInfo?)property.FieldInfo;
if ((identifyingMemberInfo != null
- && identifyingMemberInfo.IsSameAs(otherProperty.PropertyInfo ?? (MemberInfo)otherProperty.FieldInfo))
+ && identifyingMemberInfo.IsSameAs(otherProperty.PropertyInfo ?? (MemberInfo?)otherProperty.FieldInfo))
|| (property.IsPrimaryKey() && otherProperty.IsPrimaryKey())
|| (property.IsConcurrencyToken && otherProperty.IsConcurrencyToken)
|| (!property.Builder.CanSetColumnName(null) && !otherProperty.Builder.CanSetColumnName(null)))
@@ -223,7 +222,7 @@ private static void TryUniquifyColumnNames(
}
}
- private static string TryUniquify(
+ private static string? TryUniquify(
IConventionProperty property,
string columnName,
Dictionary