From 6069fe8cb1d5e29a6379bc45efba73f807b43d47 Mon Sep 17 00:00:00 2001 From: Arthur Vickers Date: Wed, 24 Jul 2019 18:04:32 -0700 Subject: [PATCH] API review: Obsolete ForXxx methods in favor of shorter names Fixes #16686 --- .../CosmosEntityTypeBuilderExtensions.cs | 34 +- .../CosmosModelBuilderExtensions.cs | 8 +- .../CosmosPropertyBuilderExtensions.cs | 12 +- .../Conventions/ContextContainerConvention.cs | 2 +- .../Conventions/StoreKeyConvention.cs | 2 +- .../SqlServerAnnotationCodeGenerator.cs | 10 +- .../SqlServerEntityTypeBuilderExtensions.cs | 86 +- .../SqlServerIndexBuilderExtensions.cs | 159 +++- .../SqlServerKeyBuilderExtensions.cs | 36 +- .../SqlServerModelBuilderExtensions.cs | 131 ++- .../Extensions/SqlServerModelExtensions.cs | 2 +- .../SqlServerPropertyBuilderExtensions.cs | 197 +++-- ...qlServerMemoryOptimizedTablesConvention.cs | 8 +- .../SqlServerStoreGenerationConvention.cs | 8 +- ...ServerValueGenerationStrategyConvention.cs | 4 +- .../SqlitePropertyBuilderExtensions.cs | 75 +- ...tTopologySuitePropertyBuilderExtensions.cs | 29 +- .../EndToEndCosmosTest.cs | 8 +- .../NestedDocumentsTest.cs | 2 +- .../CosmosModelValidatorTest.cs | 36 +- .../Metadata/CosmosBuilderExtensionsTest.cs | 20 +- .../Metadata/CosmosMetadataExtensionsTest.cs | 2 +- .../CrossStoreFixture.cs | 2 +- .../CommandConfigurationTest.cs | 2 +- .../GraphUpdatesSqlServerTestIdentity.cs | 2 +- .../GraphUpdatesSqlServerTestSequence.cs | 2 +- .../MemoryOptimizedTablesTest.cs | 4 +- ...onsterFixupChangedChangingSqlServerTest.cs | 6 +- .../ProxyGraphUpdatesSqlServerTest.cs | 2 +- .../SequenceEndToEndTest.cs | 6 +- .../SqlAzure/Model/AdventureWorksContext.cs | 2 +- .../SqlServerEndToEndTest.cs | 4 +- .../SqlServerMigrationSqlGeneratorTest.cs | 124 ++- .../SqlServerValueGenerationScenariosTest.cs | 2 +- .../StoreGeneratedSqlServerTest.cs | 2 +- .../SqlServerAnnotationCodeGeneratorTest.cs | 97 ++- .../SqlServerModelValidatorTest.cs | 262 ++++-- ...rverMemoryOptimizedTablesConventionTest.cs | 29 +- ...erValueGenerationStrategyConventionTest.cs | 2 +- .../SqlServerBuilderExtensionsTest.cs | 787 ++++++++++++++---- .../SqlServerMetadataBuilderExtensionsTest.cs | 72 +- .../Migrations/SqlServerModelDifferTest.cs | 42 +- .../SqlServerModelBuilderGenericTest.cs | 8 +- .../SqlServerTestModelBuilderExtensions.cs | 10 +- .../SqlServerValueGeneratorCacheTest.cs | 40 +- .../SqlServerValueGeneratorSelectorTest.cs | 6 +- .../Builders/SqliteBuilderExtensionsTest.cs | 96 ++- 47 files changed, 1918 insertions(+), 564 deletions(-) diff --git a/src/EFCore.Cosmos/Extensions/CosmosEntityTypeBuilderExtensions.cs b/src/EFCore.Cosmos/Extensions/CosmosEntityTypeBuilderExtensions.cs index 0c61b6c35d2..c14bc691b8b 100644 --- a/src/EFCore.Cosmos/Extensions/CosmosEntityTypeBuilderExtensions.cs +++ b/src/EFCore.Cosmos/Extensions/CosmosEntityTypeBuilderExtensions.cs @@ -24,7 +24,7 @@ public static class CosmosEntityTypeBuilderExtensions /// The builder for the entity type being configured. /// The name of the container. /// The same builder instance so that multiple calls can be chained. - public static EntityTypeBuilder ForCosmosToContainer( + public static EntityTypeBuilder ToContainer( [NotNull] this EntityTypeBuilder entityTypeBuilder, [CanBeNull] string name) { @@ -43,11 +43,11 @@ public static EntityTypeBuilder ForCosmosToContainer( /// The builder for the entity type being configured. /// The name of the container. /// The same builder instance so that multiple calls can be chained. - public static EntityTypeBuilder ForCosmosToContainer( + public static EntityTypeBuilder ToContainer( [NotNull] this EntityTypeBuilder entityTypeBuilder, [CanBeNull] string name) where TEntity : class - => (EntityTypeBuilder)ForCosmosToContainer((EntityTypeBuilder)entityTypeBuilder, name); + => (EntityTypeBuilder)ToContainer((EntityTypeBuilder)entityTypeBuilder, name); /// /// Configures the container that the entity type maps to when targeting Azure Cosmos. @@ -59,12 +59,12 @@ public static EntityTypeBuilder ForCosmosToContainer( /// The same builder instance if the configuration was applied, /// null otherwise. /// - public static IConventionEntityTypeBuilder ForCosmosToContainer( + public static IConventionEntityTypeBuilder ToContainer( [NotNull] this IConventionEntityTypeBuilder entityTypeBuilder, [CanBeNull] string name, bool fromDataAnnotation = false) { - if (!entityTypeBuilder.ForCosmosCanSetContainer(name, fromDataAnnotation)) + if (!entityTypeBuilder.CanSetContainer(name, fromDataAnnotation)) { return null; } @@ -82,7 +82,7 @@ public static IConventionEntityTypeBuilder ForCosmosToContainer( /// The name of the container. /// Indicates whether the configuration was specified using a data annotation. /// true if the configuration can be applied. - public static bool ForCosmosCanSetContainer( + public static bool CanSetContainer( [NotNull] this IConventionEntityTypeBuilder entityTypeBuilder, [CanBeNull] string name, bool fromDataAnnotation = false) { Check.NotNull(entityTypeBuilder, nameof(entityTypeBuilder)); @@ -97,7 +97,7 @@ public static bool ForCosmosCanSetContainer( /// The builder for the entity type being configured. /// The name of the parent property. /// The same builder instance so that multiple calls can be chained. - public static OwnedNavigationBuilder ForCosmosToProperty( + public static OwnedNavigationBuilder ToJsonProperty( [NotNull] this OwnedNavigationBuilder entityTypeBuilder, [CanBeNull] string name) { @@ -112,7 +112,7 @@ public static OwnedNavigationBuilder ForCosmosToProperty( /// The builder for the entity type being configured. /// The name of the parent property. /// The same builder instance so that multiple calls can be chained. - public static OwnedNavigationBuilder ForCosmosToProperty( + public static OwnedNavigationBuilder ToJsonProperty( [NotNull] this OwnedNavigationBuilder entityTypeBuilder, [CanBeNull] string name) where TEntity : class @@ -133,12 +133,12 @@ public static OwnedNavigationBuilder ForCosmosToPrope /// The same builder instance if the configuration was applied, /// null otherwise. /// - public static IConventionEntityTypeBuilder ForCosmosToProperty( + public static IConventionEntityTypeBuilder ToJsonProperty( [NotNull] this IConventionEntityTypeBuilder entityTypeBuilder, [CanBeNull] string name, bool fromDataAnnotation = false) { - if (!entityTypeBuilder.ForCosmosCanSetProperty(name, fromDataAnnotation)) + if (!entityTypeBuilder.CanSetJsonProperty(name, fromDataAnnotation)) { return null; } @@ -156,7 +156,7 @@ public static IConventionEntityTypeBuilder ForCosmosToProperty( /// The name of the parent property. /// Indicates whether the configuration was specified using a data annotation. /// true if the configuration can be applied. - public static bool ForCosmosCanSetProperty( + public static bool CanSetJsonProperty( [NotNull] this IConventionEntityTypeBuilder entityTypeBuilder, [CanBeNull] string name, bool fromDataAnnotation = false) { Check.NotNull(entityTypeBuilder, nameof(entityTypeBuilder)); @@ -171,7 +171,7 @@ public static bool ForCosmosCanSetProperty( /// The builder for the entity type being configured. /// The name of the partition key property. /// The same builder instance so that multiple calls can be chained. - public static EntityTypeBuilder ForCosmosHasPartitionKey( + public static EntityTypeBuilder HasPartitionKey( [NotNull] this EntityTypeBuilder entityTypeBuilder, [CanBeNull] string name) { @@ -186,7 +186,7 @@ public static EntityTypeBuilder ForCosmosHasPartitionKey( /// The builder for the entity type being configured. /// The name of the partition key property. /// The same builder instance so that multiple calls can be chained. - public static EntityTypeBuilder ForCosmosHasPartitionKey( + public static EntityTypeBuilder HasPartitionKey( [NotNull] this EntityTypeBuilder entityTypeBuilder, [CanBeNull] string name) where TEntity : class @@ -202,7 +202,7 @@ public static EntityTypeBuilder ForCosmosHasPartitionKey( /// The builder for the entity type being configured. /// The partition key property. /// The same builder instance so that multiple calls can be chained. - public static EntityTypeBuilder ForCosmosHasPartitionKey( + public static EntityTypeBuilder HasPartitionKey( [NotNull] this EntityTypeBuilder entityTypeBuilder, [NotNull] Expression> propertyExpression) where TEntity : class @@ -224,12 +224,12 @@ public static EntityTypeBuilder ForCosmosHasPartitionKeynull otherwise. /// - public static IConventionEntityTypeBuilder ForCosmosHasPartitionKey( + public static IConventionEntityTypeBuilder HasPartitionKey( [NotNull] this IConventionEntityTypeBuilder entityTypeBuilder, [CanBeNull] string name, bool fromDataAnnotation = false) { - if (!entityTypeBuilder.ForCosmosCanSetPartitionKey(name, fromDataAnnotation)) + if (!entityTypeBuilder.CanSetPartitionKey(name, fromDataAnnotation)) { return null; } @@ -247,7 +247,7 @@ public static IConventionEntityTypeBuilder ForCosmosHasPartitionKey( /// The name of the partition key property. /// Indicates whether the configuration was specified using a data annotation. /// true if the configuration can be applied. - public static bool ForCosmosCanSetPartitionKey( + public static bool CanSetPartitionKey( [NotNull] this IConventionEntityTypeBuilder entityTypeBuilder, [CanBeNull] string name, bool fromDataAnnotation = false) { Check.NotNull(entityTypeBuilder, nameof(entityTypeBuilder)); diff --git a/src/EFCore.Cosmos/Extensions/CosmosModelBuilderExtensions.cs b/src/EFCore.Cosmos/Extensions/CosmosModelBuilderExtensions.cs index c4bd829a828..ddf3495ff42 100644 --- a/src/EFCore.Cosmos/Extensions/CosmosModelBuilderExtensions.cs +++ b/src/EFCore.Cosmos/Extensions/CosmosModelBuilderExtensions.cs @@ -21,7 +21,7 @@ public static class CosmosModelBuilderExtensions /// The model builder. /// The default container name. /// The same builder instance so that multiple calls can be chained. - public static ModelBuilder ForCosmosHasDefaultContainer( + public static ModelBuilder HasDefaultContainer( [NotNull] this ModelBuilder modelBuilder, [CanBeNull] string name) { @@ -44,12 +44,12 @@ public static ModelBuilder ForCosmosHasDefaultContainer( /// The same builder instance if the configuration was applied, /// null otherwise. /// - public static IConventionModelBuilder ForCosmosHasDefaultContainer( + public static IConventionModelBuilder HasDefaultContainer( [NotNull] this IConventionModelBuilder modelBuilder, [CanBeNull] string name, bool fromDataAnnotation = false) { - if (!modelBuilder.ForCosmosCanSetDefaultContainer(name, fromDataAnnotation)) + if (!modelBuilder.CanSetDefaultContainer(name, fromDataAnnotation)) { return null; } @@ -66,7 +66,7 @@ public static IConventionModelBuilder ForCosmosHasDefaultContainer( /// The default container name. /// Indicates whether the configuration was specified using a data annotation. /// true if the given container name can be set as default. - public static bool ForCosmosCanSetDefaultContainer( + public static bool CanSetDefaultContainer( [NotNull] this IConventionModelBuilder modelBuilder, [CanBeNull] string name, bool fromDataAnnotation = false) diff --git a/src/EFCore.Cosmos/Extensions/CosmosPropertyBuilderExtensions.cs b/src/EFCore.Cosmos/Extensions/CosmosPropertyBuilderExtensions.cs index cdd052581ea..25cc6bd7f86 100644 --- a/src/EFCore.Cosmos/Extensions/CosmosPropertyBuilderExtensions.cs +++ b/src/EFCore.Cosmos/Extensions/CosmosPropertyBuilderExtensions.cs @@ -21,7 +21,7 @@ public static class CosmosPropertyBuilderExtensions /// The builder for the property being configured. /// The name of the container. /// The same builder instance so that multiple calls can be chained. - public static PropertyBuilder ForCosmosToProperty( + public static PropertyBuilder ToJsonProperty( [NotNull] this PropertyBuilder propertyBuilder, [NotNull] string name) { @@ -40,10 +40,10 @@ public static PropertyBuilder ForCosmosToProperty( /// The builder for the property being configured. /// The name of the container. /// The same builder instance so that multiple calls can be chained. - public static PropertyBuilder ForCosmosToProperty( + public static PropertyBuilder ToJsonProperty( [NotNull] this PropertyBuilder propertyBuilder, [NotNull] string name) - => (PropertyBuilder)ForCosmosToProperty((PropertyBuilder)propertyBuilder, name); + => (PropertyBuilder)ToJsonProperty((PropertyBuilder)propertyBuilder, name); /// /// @@ -60,12 +60,12 @@ public static PropertyBuilder ForCosmosToProperty( /// The same builder instance if the configuration was applied, /// null otherwise. /// - public static IConventionPropertyBuilder ForCosmosToProperty( + public static IConventionPropertyBuilder ToJsonProperty( [NotNull] this IConventionPropertyBuilder propertyBuilder, [CanBeNull] string name, bool fromDataAnnotation = false) { - if (!propertyBuilder.ForCosmosCanSetProperty(name, fromDataAnnotation)) + if (!propertyBuilder.CanSetJsonProperty(name, fromDataAnnotation)) { return null; } @@ -82,7 +82,7 @@ public static IConventionPropertyBuilder ForCosmosToProperty( /// The name of the container. /// Indicates whether the configuration was specified using a data annotation. /// true if the property name can be set. - public static bool ForCosmosCanSetProperty( + public static bool CanSetJsonProperty( [NotNull] this IConventionPropertyBuilder propertyBuilder, [CanBeNull] string name, bool fromDataAnnotation = false) diff --git a/src/EFCore.Cosmos/Metadata/Conventions/ContextContainerConvention.cs b/src/EFCore.Cosmos/Metadata/Conventions/ContextContainerConvention.cs index 881be598010..5b60b827613 100644 --- a/src/EFCore.Cosmos/Metadata/Conventions/ContextContainerConvention.cs +++ b/src/EFCore.Cosmos/Metadata/Conventions/ContextContainerConvention.cs @@ -39,7 +39,7 @@ public virtual void ProcessModelInitialized( Check.NotNull(modelBuilder, nameof(modelBuilder)); Check.NotNull(context, nameof(context)); - modelBuilder.ForCosmosHasDefaultContainer(Dependencies.ContextType.Name); + modelBuilder.HasDefaultContainer(Dependencies.ContextType.Name); } } } diff --git a/src/EFCore.Cosmos/Metadata/Conventions/StoreKeyConvention.cs b/src/EFCore.Cosmos/Metadata/Conventions/StoreKeyConvention.cs index 671c6d8e637..51f8af767cb 100644 --- a/src/EFCore.Cosmos/Metadata/Conventions/StoreKeyConvention.cs +++ b/src/EFCore.Cosmos/Metadata/Conventions/StoreKeyConvention.cs @@ -54,7 +54,7 @@ private static void Process(IConventionEntityTypeBuilder entityTypeBuilder) entityTypeBuilder.HasKey(new[] { idProperty.Metadata }); var jObjectProperty = entityTypeBuilder.Property(typeof(JObject), JObjectPropertyName); - jObjectProperty.ForCosmosToProperty(""); + jObjectProperty.ToJsonProperty(""); jObjectProperty.ValueGenerated(ValueGenerated.OnAddOrUpdate); } else diff --git a/src/EFCore.SqlServer/Design/Internal/SqlServerAnnotationCodeGenerator.cs b/src/EFCore.SqlServer/Design/Internal/SqlServerAnnotationCodeGenerator.cs index 6d955d9354c..893a2bda01f 100644 --- a/src/EFCore.SqlServer/Design/Internal/SqlServerAnnotationCodeGenerator.cs +++ b/src/EFCore.SqlServer/Design/Internal/SqlServerAnnotationCodeGenerator.cs @@ -58,8 +58,8 @@ public override bool IsHandledByConvention(IModel model, IAnnotation annotation) public override MethodCallCodeFragment GenerateFluentApi(IKey key, IAnnotation annotation) => annotation.Name == SqlServerAnnotationNames.Clustered ? (bool)annotation.Value == false - ? new MethodCallCodeFragment(nameof(SqlServerIndexBuilderExtensions.ForSqlServerIsClustered), false) - : new MethodCallCodeFragment(nameof(SqlServerIndexBuilderExtensions.ForSqlServerIsClustered)) + ? new MethodCallCodeFragment(nameof(SqlServerIndexBuilderExtensions.IsClustered), false) + : new MethodCallCodeFragment(nameof(SqlServerIndexBuilderExtensions.IsClustered)) : null; /// @@ -73,13 +73,13 @@ public override MethodCallCodeFragment GenerateFluentApi(IIndex index, IAnnotati if (annotation.Name == SqlServerAnnotationNames.Clustered) { return (bool)annotation.Value == false - ? new MethodCallCodeFragment(nameof(SqlServerIndexBuilderExtensions.ForSqlServerIsClustered), false) - : new MethodCallCodeFragment(nameof(SqlServerIndexBuilderExtensions.ForSqlServerIsClustered)); + ? new MethodCallCodeFragment(nameof(SqlServerIndexBuilderExtensions.IsClustered), false) + : new MethodCallCodeFragment(nameof(SqlServerIndexBuilderExtensions.IsClustered)); } if (annotation.Name == SqlServerAnnotationNames.Include) { - return new MethodCallCodeFragment(nameof(SqlServerIndexBuilderExtensions.ForSqlServerInclude), annotation.Value); + return new MethodCallCodeFragment(nameof(SqlServerIndexBuilderExtensions.IncludeProperties), annotation.Value); } return null; diff --git a/src/EFCore.SqlServer/Extensions/SqlServerEntityTypeBuilderExtensions.cs b/src/EFCore.SqlServer/Extensions/SqlServerEntityTypeBuilderExtensions.cs index 2ea760c8dd1..fcd9a903b7c 100644 --- a/src/EFCore.SqlServer/Extensions/SqlServerEntityTypeBuilderExtensions.cs +++ b/src/EFCore.SqlServer/Extensions/SqlServerEntityTypeBuilderExtensions.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.SqlServer.Metadata.Internal; @@ -20,7 +21,7 @@ public static class SqlServerEntityTypeBuilderExtensions /// The builder for the entity type being configured. /// A value indicating whether the table is memory-optimized. /// The same builder instance so that multiple calls can be chained. - public static EntityTypeBuilder ForSqlServerIsMemoryOptimized( + public static EntityTypeBuilder IsMemoryOptimized( [NotNull] this EntityTypeBuilder entityTypeBuilder, bool memoryOptimized = true) { Check.NotNull(entityTypeBuilder, nameof(entityTypeBuilder)); @@ -37,10 +38,10 @@ public static EntityTypeBuilder ForSqlServerIsMemoryOptimized( /// The builder for the entity type being configured. /// A value indicating whether the table is memory-optimized. /// The same builder instance so that multiple calls can be chained. - public static EntityTypeBuilder ForSqlServerIsMemoryOptimized( + public static EntityTypeBuilder IsMemoryOptimized( [NotNull] this EntityTypeBuilder entityTypeBuilder, bool memoryOptimized = true) where TEntity : class - => (EntityTypeBuilder)ForSqlServerIsMemoryOptimized((EntityTypeBuilder)entityTypeBuilder, memoryOptimized); + => (EntityTypeBuilder)IsMemoryOptimized((EntityTypeBuilder)entityTypeBuilder, memoryOptimized); /// /// Configures the table that the entity maps to when targeting SQL Server as memory-optimized. @@ -48,7 +49,7 @@ public static EntityTypeBuilder ForSqlServerIsMemoryOptimized( /// The builder for the entity type being configured. /// A value indicating whether the table is memory-optimized. /// The same builder instance so that multiple calls can be chained. - public static OwnedNavigationBuilder ForSqlServerIsMemoryOptimized( + public static OwnedNavigationBuilder IsMemoryOptimized( [NotNull] this OwnedNavigationBuilder collectionOwnershipBuilder, bool memoryOptimized = true) { Check.NotNull(collectionOwnershipBuilder, nameof(collectionOwnershipBuilder)); @@ -66,11 +67,11 @@ public static OwnedNavigationBuilder ForSqlServerIsMemoryOptimized( /// The builder for the entity type being configured. /// A value indicating whether the table is memory-optimized. /// The same builder instance so that multiple calls can be chained. - public static OwnedNavigationBuilder ForSqlServerIsMemoryOptimized( + public static OwnedNavigationBuilder IsMemoryOptimized( [NotNull] this OwnedNavigationBuilder collectionOwnershipBuilder, bool memoryOptimized = true) where TEntity : class where TRelatedEntity : class - => (OwnedNavigationBuilder)ForSqlServerIsMemoryOptimized( + => (OwnedNavigationBuilder)IsMemoryOptimized( (OwnedNavigationBuilder)collectionOwnershipBuilder, memoryOptimized); /// @@ -83,12 +84,12 @@ public static OwnedNavigationBuilder ForSqlServerIsMemo /// The same builder instance if the configuration was applied, /// null otherwise. /// - public static IConventionEntityTypeBuilder ForSqlServerIsMemoryOptimized( + public static IConventionEntityTypeBuilder IsMemoryOptimized( [NotNull] this IConventionEntityTypeBuilder entityTypeBuilder, bool? memoryOptimized, bool fromDataAnnotation = false) { - if (entityTypeBuilder.ForSqlServerCanSetIsMemoryOptimized(memoryOptimized, fromDataAnnotation)) + if (entityTypeBuilder.CanSetIsMemoryOptimized(memoryOptimized, fromDataAnnotation)) { entityTypeBuilder.Metadata.SetSqlServerIsMemoryOptimized(memoryOptimized, fromDataAnnotation); return entityTypeBuilder; @@ -104,7 +105,7 @@ public static IConventionEntityTypeBuilder ForSqlServerIsMemoryOptimized( /// A value indicating whether the table is memory-optimized. /// Indicates whether the configuration was specified using a data annotation. /// true if the mapped table can be configured as memory-optimized. - public static bool ForSqlServerCanSetIsMemoryOptimized( + public static bool CanSetIsMemoryOptimized( [NotNull] this IConventionEntityTypeBuilder entityTypeBuilder, bool? memoryOptimized, bool fromDataAnnotation = false) @@ -113,5 +114,72 @@ public static bool ForSqlServerCanSetIsMemoryOptimized( return entityTypeBuilder.CanSetAnnotation(SqlServerAnnotationNames.MemoryOptimized, memoryOptimized, fromDataAnnotation); } + + /// + /// Configures the table that the entity maps to when targeting SQL Server as memory-optimized. + /// + /// The builder for the entity type being configured. + /// A value indicating whether the table is memory-optimized. + /// The same builder instance so that multiple calls can be chained. + [Obsolete("Use IsMemoryOptimized")] + public static EntityTypeBuilder ForSqlServerIsMemoryOptimized( + [NotNull] this EntityTypeBuilder entityTypeBuilder, bool memoryOptimized = true) + => entityTypeBuilder.IsMemoryOptimized(memoryOptimized); + + /// + /// Configures the table that the entity maps to when targeting SQL Server as memory-optimized. + /// + /// The entity type being configured. + /// The builder for the entity type being configured. + /// A value indicating whether the table is memory-optimized. + /// The same builder instance so that multiple calls can be chained. + [Obsolete("Use IsMemoryOptimized")] + public static EntityTypeBuilder ForSqlServerIsMemoryOptimized( + [NotNull] this EntityTypeBuilder entityTypeBuilder, bool memoryOptimized = true) + where TEntity : class + => entityTypeBuilder.IsMemoryOptimized(memoryOptimized); + + /// + /// Configures the table that the entity maps to when targeting SQL Server as memory-optimized. + /// + /// The builder for the entity type being configured. + /// A value indicating whether the table is memory-optimized. + /// The same builder instance so that multiple calls can be chained. + [Obsolete("Use IsMemoryOptimized")] + public static OwnedNavigationBuilder ForSqlServerIsMemoryOptimized( + [NotNull] this OwnedNavigationBuilder collectionOwnershipBuilder, bool memoryOptimized = true) + => collectionOwnershipBuilder.IsMemoryOptimized(memoryOptimized); + + /// + /// Configures the table that the entity maps to when targeting SQL Server as memory-optimized. + /// + /// The entity type being configured. + /// The entity type that this relationship targets. + /// The builder for the entity type being configured. + /// A value indicating whether the table is memory-optimized. + /// The same builder instance so that multiple calls can be chained. + [Obsolete("Use IsMemoryOptimized")] + public static OwnedNavigationBuilder ForSqlServerIsMemoryOptimized( + [NotNull] this OwnedNavigationBuilder collectionOwnershipBuilder, bool memoryOptimized = true) + where TEntity : class + where TRelatedEntity : class + => collectionOwnershipBuilder.IsMemoryOptimized(memoryOptimized); + + /// + /// Configures the table that the entity maps to when targeting SQL Server as memory-optimized. + /// + /// The builder for the entity type being configured. + /// A value indicating whether the table is memory-optimized. + /// Indicates whether the configuration was specified using a data annotation. + /// + /// The same builder instance if the configuration was applied, + /// null otherwise. + /// + [Obsolete("Use IsMemoryOptimized")] + public static IConventionEntityTypeBuilder ForSqlServerIsMemoryOptimized( + [NotNull] this IConventionEntityTypeBuilder entityTypeBuilder, + bool? memoryOptimized, + bool fromDataAnnotation = false) + => entityTypeBuilder.IsMemoryOptimized(memoryOptimized, fromDataAnnotation); } } diff --git a/src/EFCore.SqlServer/Extensions/SqlServerIndexBuilderExtensions.cs b/src/EFCore.SqlServer/Extensions/SqlServerIndexBuilderExtensions.cs index 57e77e9822c..b449e2eb382 100644 --- a/src/EFCore.SqlServer/Extensions/SqlServerIndexBuilderExtensions.cs +++ b/src/EFCore.SqlServer/Extensions/SqlServerIndexBuilderExtensions.cs @@ -28,7 +28,7 @@ public static class SqlServerIndexBuilderExtensions /// The builder for the index being configured. /// A value indicating whether the index is clustered. /// A builder to further configure the index. - public static IndexBuilder ForSqlServerIsClustered([NotNull] this IndexBuilder indexBuilder, bool clustered = true) + public static IndexBuilder IsClustered([NotNull] this IndexBuilder indexBuilder, bool clustered = true) { Check.NotNull(indexBuilder, nameof(indexBuilder)); @@ -43,9 +43,9 @@ public static IndexBuilder ForSqlServerIsClustered([NotNull] this IndexBuilder i /// The builder for the index being configured. /// A value indicating whether the index is clustered. /// A builder to further configure the index. - public static IndexBuilder ForSqlServerIsClustered( + public static IndexBuilder IsClustered( [NotNull] this IndexBuilder indexBuilder, bool clustered = true) - => (IndexBuilder)ForSqlServerIsClustered((IndexBuilder)indexBuilder, clustered); + => (IndexBuilder)IsClustered((IndexBuilder)indexBuilder, clustered); /// /// Configures whether the index is clustered when targeting SQL Server. @@ -57,12 +57,12 @@ public static IndexBuilder ForSqlServerIsClustered( /// The same builder instance if the configuration was applied, /// null otherwise. /// - public static IConventionIndexBuilder ForSqlServerIsClustered( + public static IConventionIndexBuilder IsClustered( [NotNull] this IConventionIndexBuilder indexBuilder, bool? clustered, bool fromDataAnnotation = false) { - if (indexBuilder.ForSqlServerCanSetIsClustered(clustered, fromDataAnnotation)) + if (indexBuilder.CanSetIsClustered(clustered, fromDataAnnotation)) { indexBuilder.Metadata.SetSqlServerIsClustered(clustered, fromDataAnnotation); return indexBuilder; @@ -78,7 +78,7 @@ public static IConventionIndexBuilder ForSqlServerIsClustered( /// A value indicating whether the index is clustered. /// Indicates whether the configuration was specified using a data annotation. /// true if the index can be configured as clustered. - public static bool ForSqlServerCanSetIsClustered( + public static bool CanSetIsClustered( [NotNull] this IConventionIndexBuilder indexBuilder, bool? clustered, bool fromDataAnnotation = false) @@ -94,7 +94,7 @@ public static bool ForSqlServerCanSetIsClustered( /// The builder for the index being configured. /// An array of property names to be used in 'include' clause. /// A builder to further configure the index. - public static IndexBuilder ForSqlServerInclude([NotNull] this IndexBuilder indexBuilder, [NotNull] params string[] propertyNames) + public static IndexBuilder IncludeProperties([NotNull] this IndexBuilder indexBuilder, [NotNull] params string[] propertyNames) { Check.NotNull(indexBuilder, nameof(indexBuilder)); Check.NotNull(propertyNames, nameof(propertyNames)); @@ -119,13 +119,13 @@ public static IndexBuilder ForSqlServerInclude([NotNull] this IndexBuilder index /// /// /// A builder to further configure the index. - public static IndexBuilder ForSqlServerInclude( + public static IndexBuilder IncludeProperties( [NotNull] this IndexBuilder indexBuilder, [NotNull] Expression> includeExpression) { Check.NotNull(indexBuilder, nameof(indexBuilder)); Check.NotNull(includeExpression, nameof(includeExpression)); - ForSqlServerInclude( + IncludeProperties( indexBuilder, includeExpression.GetPropertyAccessList().Select(MemberInfoExtensions.GetSimpleMemberName).ToArray()); @@ -142,12 +142,12 @@ public static IndexBuilder ForSqlServerInclude( /// The same builder instance if the configuration was applied, /// null otherwise. /// - public static IConventionIndexBuilder ForSqlServerInclude( + public static IConventionIndexBuilder IncludeProperties( [NotNull] this IConventionIndexBuilder indexBuilder, [NotNull] IReadOnlyList propertyNames, bool fromDataAnnotation = false) { - if (indexBuilder.ForSqlServerCanSetInclude(propertyNames, fromDataAnnotation)) + if (indexBuilder.CanSetIncludeProperties(propertyNames, fromDataAnnotation)) { indexBuilder.Metadata.SetSqlServerIncludeProperties(propertyNames, fromDataAnnotation); @@ -164,7 +164,7 @@ public static IConventionIndexBuilder ForSqlServerInclude( /// An array of property names to be used in 'include' clause. /// Indicates whether the configuration was specified using a data annotation. /// true if the given include properties can be set. - public static bool ForSqlServerCanSetInclude( + public static bool CanSetIncludeProperties( [NotNull] this IConventionIndexBuilder indexBuilder, [CanBeNull] IReadOnlyList propertyNames, bool fromDataAnnotation = false) @@ -183,7 +183,7 @@ public static bool ForSqlServerCanSetInclude( /// The builder for the index being configured. /// A value indicating whether the index is created with online option. /// A builder to further configure the index. - public static IndexBuilder ForSqlServerIsCreatedOnline([NotNull] this IndexBuilder indexBuilder, bool createdOnline = true) + public static IndexBuilder IsCreatedOnline([NotNull] this IndexBuilder indexBuilder, bool createdOnline = true) { Check.NotNull(indexBuilder, nameof(indexBuilder)); @@ -198,9 +198,9 @@ public static IndexBuilder ForSqlServerIsCreatedOnline([NotNull] this IndexBuild /// The builder for the index being configured. /// A value indicating whether the index is created with online option. /// A builder to further configure the index. - public static IndexBuilder ForSqlServerIsCreatedOnline( + public static IndexBuilder IsCreatedOnline( [NotNull] this IndexBuilder indexBuilder, bool createdOnline = true) - => (IndexBuilder)ForSqlServerIsCreatedOnline((IndexBuilder)indexBuilder, createdOnline); + => (IndexBuilder)IsCreatedOnline((IndexBuilder)indexBuilder, createdOnline); /// /// Configures whether the index is created with online option when targeting SQL Server. @@ -212,12 +212,12 @@ public static IndexBuilder ForSqlServerIsCreatedOnline( /// The same builder instance if the configuration was applied, /// null otherwise. /// - public static IConventionIndexBuilder ForSqlServerIsCreatedOnline( + public static IConventionIndexBuilder IsCreatedOnline( [NotNull] this IConventionIndexBuilder indexBuilder, bool? createdOnline, bool fromDataAnnotation = false) { - if (indexBuilder.ForSqlServerCanSetIsCreatedOnline(createdOnline, fromDataAnnotation)) + if (indexBuilder.CanSetIsCreatedOnline(createdOnline, fromDataAnnotation)) { indexBuilder.Metadata.SetSqlServerIsCreatedOnline(createdOnline, fromDataAnnotation); @@ -238,7 +238,7 @@ public static IConventionIndexBuilder ForSqlServerIsCreatedOnline( /// null otherwise. /// /// true if the index can be configured with online option when targeting SQL Server. - public static bool ForSqlServerCanSetIsCreatedOnline( + public static bool CanSetIsCreatedOnline( [NotNull] this IConventionIndexBuilder indexBuilder, bool? createdOnline, bool fromDataAnnotation = false) @@ -247,5 +247,128 @@ public static bool ForSqlServerCanSetIsCreatedOnline( return indexBuilder.CanSetAnnotation(SqlServerAnnotationNames.CreatedOnline, createdOnline, fromDataAnnotation); } + + /// + /// Configures whether the index is clustered when targeting SQL Server. + /// + /// The builder for the index being configured. + /// A value indicating whether the index is clustered. + /// A builder to further configure the index. + [Obsolete("Use IsClustered")] + public static IndexBuilder ForSqlServerIsClustered([NotNull] this IndexBuilder indexBuilder, bool clustered = true) + => indexBuilder.IsClustered(clustered); + + /// + /// Configures whether the index is clustered when targeting SQL Server. + /// + /// The builder for the index being configured. + /// A value indicating whether the index is clustered. + /// A builder to further configure the index. + [Obsolete("Use IsClustered")] + public static IndexBuilder ForSqlServerIsClustered( + [NotNull] this IndexBuilder indexBuilder, bool clustered = true) + => indexBuilder.IsClustered(clustered); + + /// + /// Configures whether the index is clustered when targeting SQL Server. + /// + /// The builder for the index being configured. + /// A value indicating whether the index is clustered. + /// Indicates whether the configuration was specified using a data annotation. + /// + /// The same builder instance if the configuration was applied, + /// null otherwise. + /// + [Obsolete("Use IsClustered")] + public static IConventionIndexBuilder ForSqlServerIsClustered( + [NotNull] this IConventionIndexBuilder indexBuilder, + bool? clustered, + bool fromDataAnnotation = false) + => indexBuilder.IsClustered(clustered, fromDataAnnotation); + + /// + /// Configures index include properties when targeting SQL Server. + /// + /// The builder for the index being configured. + /// An array of property names to be used in 'include' clause. + /// A builder to further configure the index. + [Obsolete("Use IncludeProperties")] + public static IndexBuilder ForSqlServerInclude([NotNull] this IndexBuilder indexBuilder, [NotNull] params string[] propertyNames) + => indexBuilder.IncludeProperties(propertyNames); + + /// + /// Configures index include properties when targeting SQL Server. + /// + /// The builder for the index being configured. + /// + /// + /// A lambda expression representing the property(s) to be included in the 'include' clause + /// (blog => blog.Url). + /// + /// + /// If multiple properties are to be included then specify an anonymous type including the + /// properties (post => new { post.Title, post.BlogId }). + /// + /// + /// A builder to further configure the index. + [Obsolete("Use IncludeProperties")] + public static IndexBuilder ForSqlServerInclude( + [NotNull] this IndexBuilder indexBuilder, [NotNull] Expression> includeExpression) + => indexBuilder.IncludeProperties(includeExpression); + + /// + /// Configures index include properties when targeting SQL Server. + /// + /// The builder for the index being configured. + /// An array of property names to be used in 'include' clause. + /// Indicates whether the configuration was specified using a data annotation. + /// + /// The same builder instance if the configuration was applied, + /// null otherwise. + /// + [Obsolete("Use IncludeProperties")] + public static IConventionIndexBuilder ForSqlServerInclude( + [NotNull] this IConventionIndexBuilder indexBuilder, + [NotNull] IReadOnlyList propertyNames, + bool fromDataAnnotation = false) + => indexBuilder.IncludeProperties(propertyNames, fromDataAnnotation); + + /// + /// Configures whether the index is created with online option when targeting SQL Server. + /// + /// The builder for the index being configured. + /// A value indicating whether the index is created with online option. + /// A builder to further configure the index. + [Obsolete("Use IsCreatedOnline")] + public static IndexBuilder ForSqlServerIsCreatedOnline([NotNull] this IndexBuilder indexBuilder, bool createdOnline = true) + => indexBuilder.IsCreatedOnline(createdOnline); + + /// + /// Configures whether the index is created with online option when targeting SQL Server. + /// + /// The builder for the index being configured. + /// A value indicating whether the index is created with online option. + /// A builder to further configure the index. + [Obsolete("Use IsCreatedOnline")] + public static IndexBuilder ForSqlServerIsCreatedOnline( + [NotNull] this IndexBuilder indexBuilder, bool createdOnline = true) + => indexBuilder.IsCreatedOnline(createdOnline); + + /// + /// Configures whether the index is created with online option when targeting SQL Server. + /// + /// The builder for the index being configured. + /// A value indicating whether the index is created with online option. + /// Indicates whether the configuration was specified using a data annotation. + /// + /// The same builder instance if the configuration was applied, + /// null otherwise. + /// + [Obsolete("Use IsCreatedOnline")] + public static IConventionIndexBuilder ForSqlServerIsCreatedOnline( + [NotNull] this IConventionIndexBuilder indexBuilder, + bool? createdOnline, + bool fromDataAnnotation = false) + => indexBuilder.IsCreatedOnline(createdOnline, fromDataAnnotation); } } diff --git a/src/EFCore.SqlServer/Extensions/SqlServerKeyBuilderExtensions.cs b/src/EFCore.SqlServer/Extensions/SqlServerKeyBuilderExtensions.cs index d8daf18da9d..d2f9f870975 100644 --- a/src/EFCore.SqlServer/Extensions/SqlServerKeyBuilderExtensions.cs +++ b/src/EFCore.SqlServer/Extensions/SqlServerKeyBuilderExtensions.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.SqlServer.Metadata.Internal; @@ -20,7 +21,7 @@ public static class SqlServerKeyBuilderExtensions /// The builder for the key being configured. /// A value indicating whether the key is clustered. /// The same builder instance so that multiple calls can be chained. - public static KeyBuilder ForSqlServerIsClustered([NotNull] this KeyBuilder keyBuilder, bool clustered = true) + public static KeyBuilder IsClustered([NotNull] this KeyBuilder keyBuilder, bool clustered = true) { Check.NotNull(keyBuilder, nameof(keyBuilder)); @@ -39,12 +40,12 @@ public static KeyBuilder ForSqlServerIsClustered([NotNull] this KeyBuilder keyBu /// The same builder instance if the configuration was applied, /// null otherwise. /// - public static IConventionKeyBuilder ForSqlServerIsClustered( + public static IConventionKeyBuilder IsClustered( [NotNull] this IConventionKeyBuilder keyBuilder, bool? clustered, bool fromDataAnnotation = false) { - if (keyBuilder.ForSqlServerCanSetIsClustered(clustered, fromDataAnnotation)) + if (keyBuilder.CanSetIsClustered(clustered, fromDataAnnotation)) { keyBuilder.Metadata.SetSqlServerIsClustered(clustered, fromDataAnnotation); return keyBuilder; @@ -60,7 +61,7 @@ public static IConventionKeyBuilder ForSqlServerIsClustered( /// A value indicating whether the key is clustered. /// Indicates whether the configuration was specified using a data annotation. /// true if the key can be configured as clustered. - public static bool ForSqlServerCanSetIsClustered( + public static bool CanSetIsClustered( [NotNull] this IConventionKeyBuilder keyBuilder, bool? clustered, bool fromDataAnnotation = false) @@ -69,5 +70,32 @@ public static bool ForSqlServerCanSetIsClustered( return keyBuilder.CanSetAnnotation(SqlServerAnnotationNames.Clustered, clustered, fromDataAnnotation); } + + /// + /// Configures whether the key is clustered when targeting SQL Server. + /// + /// The builder for the key being configured. + /// A value indicating whether the key is clustered. + /// The same builder instance so that multiple calls can be chained. + [Obsolete("Use IsClustered")] + public static KeyBuilder ForSqlServerIsClustered([NotNull] this KeyBuilder keyBuilder, bool clustered = true) + => keyBuilder.IsClustered(clustered); + + /// + /// Configures whether the key is clustered when targeting SQL Server. + /// + /// The builder for the key being configured. + /// A value indicating whether the key is clustered. + /// Indicates whether the configuration was specified using a data annotation. + /// + /// The same builder instance if the configuration was applied, + /// null otherwise. + /// + [Obsolete("Use IsClustered")] + public static IConventionKeyBuilder ForSqlServerIsClustered( + [NotNull] this IConventionKeyBuilder keyBuilder, + bool? clustered, + bool fromDataAnnotation = false) + => keyBuilder.IsClustered(clustered, fromDataAnnotation); } } diff --git a/src/EFCore.SqlServer/Extensions/SqlServerModelBuilderExtensions.cs b/src/EFCore.SqlServer/Extensions/SqlServerModelBuilderExtensions.cs index 2d80a245ca5..1df33744aeb 100644 --- a/src/EFCore.SqlServer/Extensions/SqlServerModelBuilderExtensions.cs +++ b/src/EFCore.SqlServer/Extensions/SqlServerModelBuilderExtensions.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Metadata.Builders; @@ -23,7 +24,7 @@ public static class SqlServerModelBuilderExtensions /// The name of the sequence. /// The schema of the sequence. /// The same builder instance so that multiple calls can be chained. - public static ModelBuilder ForSqlServerUseSequenceHiLo( + public static ModelBuilder UseHiLo( [NotNull] this ModelBuilder modelBuilder, [CanBeNull] string name = null, [CanBeNull] string schema = null) @@ -59,13 +60,13 @@ public static ModelBuilder ForSqlServerUseSequenceHiLo( /// The schema of the sequence. /// Indicates whether the configuration was specified using a data annotation. /// A builder to further configure the sequence. - public static IConventionSequenceBuilder ForSqlServerHasHiLoSequence( + public static IConventionSequenceBuilder HasHiLoSequence( [NotNull] this IConventionModelBuilder modelBuilder, [CanBeNull] string name, [CanBeNull] string schema, bool fromDataAnnotation = false) { - if (!modelBuilder.ForSqlServerCanSetHiLoSequence(name, schema)) + if (!modelBuilder.CanSetHiLoSequence(name, schema)) { return null; } @@ -84,7 +85,7 @@ public static IConventionSequenceBuilder ForSqlServerHasHiLoSequence( /// The schema of the sequence. /// Indicates whether the configuration was specified using a data annotation. /// true if the given name and schema can be set for the hi-lo sequence. - public static bool ForSqlServerCanSetHiLoSequence( + public static bool CanSetHiLoSequence( [NotNull] this IConventionModelBuilder modelBuilder, [CanBeNull] string name, [CanBeNull] string schema, @@ -107,7 +108,7 @@ public static bool ForSqlServerCanSetHiLoSequence( /// The value that is used for the very first row loaded into the table. /// The incremental value that is added to the identity value of the previous row that was loaded. /// The same builder instance so that multiple calls can be chained. - public static ModelBuilder ForSqlServerUseIdentityColumns( + public static ModelBuilder UseIdentityColumns( [NotNull] this ModelBuilder modelBuilder, int seed = 1, int increment = 1) @@ -135,10 +136,10 @@ public static ModelBuilder ForSqlServerUseIdentityColumns( /// The same builder instance if the configuration was applied, /// null otherwise. /// - public static IConventionModelBuilder ForSqlServerHasIdentitySeed( + public static IConventionModelBuilder HasIdentityColumnSeed( [NotNull] this IConventionModelBuilder modelBuilder, int? seed, bool fromDataAnnotation = false) { - if (modelBuilder.ForSqlServerCanSetIdentitySeed(seed, fromDataAnnotation)) + if (modelBuilder.CanSetIdentityColumnSeed(seed, fromDataAnnotation)) { modelBuilder.Metadata.SetSqlServerIdentitySeed(seed, fromDataAnnotation); return modelBuilder; @@ -154,7 +155,7 @@ public static IConventionModelBuilder ForSqlServerHasIdentitySeed( /// The value that is used for the very first row loaded into the table. /// Indicates whether the configuration was specified using a data annotation. /// true if the given value can be set as the seed for SQL Server IDENTITY. - public static bool ForSqlServerCanSetIdentitySeed( + public static bool CanSetIdentityColumnSeed( [NotNull] this IConventionModelBuilder modelBuilder, int? seed, bool fromDataAnnotation = false) { Check.NotNull(modelBuilder, nameof(modelBuilder)); @@ -172,10 +173,10 @@ public static bool ForSqlServerCanSetIdentitySeed( /// The same builder instance if the configuration was applied, /// null otherwise. /// - public static IConventionModelBuilder ForSqlServerHasIdentityIncrement( + public static IConventionModelBuilder HasIdentityColumnIncrement( [NotNull] this IConventionModelBuilder modelBuilder, int? increment, bool fromDataAnnotation = false) { - if (modelBuilder.ForSqlServerCanSetIdentityIncrement(increment, fromDataAnnotation)) + if (modelBuilder.CanSetIdentityColumnIncrement(increment, fromDataAnnotation)) { modelBuilder.Metadata.SetSqlServerIdentityIncrement(increment, fromDataAnnotation); return modelBuilder; @@ -191,7 +192,7 @@ public static IConventionModelBuilder ForSqlServerHasIdentityIncrement( /// The incremental value that is added to the identity value of the previous row that was loaded. /// Indicates whether the configuration was specified using a data annotation. /// true if the given value can be set as the default increment for SQL Server IDENTITY. - public static bool ForSqlServerCanSetIdentityIncrement( + public static bool CanSetIdentityColumnIncrement( [NotNull] this IConventionModelBuilder modelBuilder, int? increment, bool fromDataAnnotation = false) { Check.NotNull(modelBuilder, nameof(modelBuilder)); @@ -210,23 +211,23 @@ public static bool ForSqlServerCanSetIdentityIncrement( /// The same builder instance if the configuration was applied, /// null otherwise. /// - public static IConventionModelBuilder ForSqlServerHasValueGenerationStrategy( + public static IConventionModelBuilder HasValueGenerationStrategy( [NotNull] this IConventionModelBuilder modelBuilder, SqlServerValueGenerationStrategy? valueGenerationStrategy, bool fromDataAnnotation = false) { - if (modelBuilder.ForSqlServerCanSetValueGenerationStrategy(valueGenerationStrategy, fromDataAnnotation)) + if (modelBuilder.CanSetValueGenerationStrategy(valueGenerationStrategy, fromDataAnnotation)) { modelBuilder.Metadata.SetSqlServerValueGenerationStrategy(valueGenerationStrategy, fromDataAnnotation); if (valueGenerationStrategy != SqlServerValueGenerationStrategy.IdentityColumn) { - modelBuilder.ForSqlServerHasIdentitySeed(null, fromDataAnnotation); - modelBuilder.ForSqlServerHasIdentityIncrement(null, fromDataAnnotation); + modelBuilder.HasIdentityColumnSeed(null, fromDataAnnotation); + modelBuilder.HasIdentityColumnIncrement(null, fromDataAnnotation); } if (valueGenerationStrategy != SqlServerValueGenerationStrategy.SequenceHiLo) { - modelBuilder.ForSqlServerHasHiLoSequence(null, null, fromDataAnnotation); + modelBuilder.HasHiLoSequence(null, null, fromDataAnnotation); } return modelBuilder; @@ -242,7 +243,7 @@ public static IConventionModelBuilder ForSqlServerHasValueGenerationStrategy( /// The value generation strategy. /// Indicates whether the configuration was specified using a data annotation. /// true if the given value can be set as the default value generation strategy. - public static bool ForSqlServerCanSetValueGenerationStrategy( + public static bool CanSetValueGenerationStrategy( [NotNull] this IConventionModelBuilder modelBuilder, SqlServerValueGenerationStrategy? valueGenerationStrategy, bool fromDataAnnotation = false) @@ -252,5 +253,101 @@ public static bool ForSqlServerCanSetValueGenerationStrategy( return modelBuilder.CanSetAnnotation( SqlServerAnnotationNames.ValueGenerationStrategy, valueGenerationStrategy, fromDataAnnotation); } + + /// + /// Configures the model to use a sequence-based hi-lo pattern to generate values for key properties + /// marked as , when targeting SQL Server. + /// + /// The model builder. + /// The name of the sequence. + /// The schema of the sequence. + /// The same builder instance so that multiple calls can be chained. + [Obsolete("Use UseHiLo")] + public static ModelBuilder ForSqlServerUseSequenceHiLo( + [NotNull] this ModelBuilder modelBuilder, + [CanBeNull] string name = null, + [CanBeNull] string schema = null) + => modelBuilder.UseHiLo(name, schema); + + /// + /// Configures the database sequence used for the hi-lo pattern to generate values for key properties + /// marked as , when targeting SQL Server. + /// + /// The model builder. + /// The name of the sequence. + /// The schema of the sequence. + /// Indicates whether the configuration was specified using a data annotation. + /// A builder to further configure the sequence. + [Obsolete("Use HasHiLoSequence")] + public static IConventionSequenceBuilder ForSqlServerHasHiLoSequence( + [NotNull] this IConventionModelBuilder modelBuilder, + [CanBeNull] string name, + [CanBeNull] string schema, + bool fromDataAnnotation = false) + => modelBuilder.HasHiLoSequence(name, schema, fromDataAnnotation); + + /// + /// Configures the model to use the SQL Server IDENTITY feature to generate values for key properties + /// marked as , when targeting SQL Server. This is the default + /// behavior when targeting SQL Server. + /// + /// The model builder. + /// The value that is used for the very first row loaded into the table. + /// The incremental value that is added to the identity value of the previous row that was loaded. + /// The same builder instance so that multiple calls can be chained. + [Obsolete("Use UseIdentityColumns")] + public static ModelBuilder ForSqlServerUseIdentityColumns( + [NotNull] this ModelBuilder modelBuilder, + int seed = 1, + int increment = 1) + => modelBuilder.UseIdentityColumns(seed, increment); + + /// + /// Configures the default seed for SQL Server IDENTITY. + /// + /// The model builder. + /// The value that is used for the very first row loaded into the table. + /// Indicates whether the configuration was specified using a data annotation. + /// + /// The same builder instance if the configuration was applied, + /// null otherwise. + /// + [Obsolete("Use HasIdentityColumnSeed")] + public static IConventionModelBuilder ForSqlServerHasIdentitySeed( + [NotNull] this IConventionModelBuilder modelBuilder, int? seed, bool fromDataAnnotation = false) + => modelBuilder.HasIdentityColumnSeed(seed, fromDataAnnotation); + + /// + /// Configures the default increment for SQL Server IDENTITY. + /// + /// The model builder. + /// The incremental value that is added to the identity value of the previous row that was loaded. + /// Indicates whether the configuration was specified using a data annotation. + /// + /// The same builder instance if the configuration was applied, + /// null otherwise. + /// + [Obsolete("Use HasIdentityColumnIncrement")] + public static IConventionModelBuilder ForSqlServerHasIdentityIncrement( + [NotNull] this IConventionModelBuilder modelBuilder, int? increment, bool fromDataAnnotation = false) + => modelBuilder.HasIdentityColumnIncrement(increment, fromDataAnnotation); + + /// + /// Configures the default value generation strategy for key properties marked as , + /// when targeting SQL Server. + /// + /// The model builder. + /// The value generation strategy. + /// Indicates whether the configuration was specified using a data annotation. + /// + /// The same builder instance if the configuration was applied, + /// null otherwise. + /// + [Obsolete("Use HasValueGenerationStrategy")] + public static IConventionModelBuilder ForSqlServerHasValueGenerationStrategy( + [NotNull] this IConventionModelBuilder modelBuilder, + SqlServerValueGenerationStrategy? valueGenerationStrategy, + bool fromDataAnnotation = false) + => modelBuilder.HasValueGenerationStrategy(valueGenerationStrategy, fromDataAnnotation); } } diff --git a/src/EFCore.SqlServer/Extensions/SqlServerModelExtensions.cs b/src/EFCore.SqlServer/Extensions/SqlServerModelExtensions.cs index bedc3022448..d402819ca66 100644 --- a/src/EFCore.SqlServer/Extensions/SqlServerModelExtensions.cs +++ b/src/EFCore.SqlServer/Extensions/SqlServerModelExtensions.cs @@ -64,7 +64,7 @@ public static void SetSqlServerHiLoSequenceName( /// /// Returns the schema to use for the default hi-lo sequence. - /// + /// /// /// The model. /// The schema to use for the default hi-lo sequence. diff --git a/src/EFCore.SqlServer/Extensions/SqlServerPropertyBuilderExtensions.cs b/src/EFCore.SqlServer/Extensions/SqlServerPropertyBuilderExtensions.cs index ad97d21ac7c..f1c65a2585e 100644 --- a/src/EFCore.SqlServer/Extensions/SqlServerPropertyBuilderExtensions.cs +++ b/src/EFCore.SqlServer/Extensions/SqlServerPropertyBuilderExtensions.cs @@ -24,7 +24,7 @@ public static class SqlServerPropertyBuilderExtensions /// The name of the sequence. /// The schema of the sequence. /// The same builder instance so that multiple calls can be chained. - public static PropertyBuilder ForSqlServerUseSequenceHiLo( + public static PropertyBuilder UseHiLo( [NotNull] this PropertyBuilder propertyBuilder, [CanBeNull] string name = null, [CanBeNull] string schema = null) @@ -62,11 +62,11 @@ public static PropertyBuilder ForSqlServerUseSequenceHiLo( /// The name of the sequence. /// The schema of the sequence. /// The same builder instance so that multiple calls can be chained. - public static PropertyBuilder ForSqlServerUseSequenceHiLo( + public static PropertyBuilder UseHiLo( [NotNull] this PropertyBuilder propertyBuilder, [CanBeNull] string name = null, [CanBeNull] string schema = null) - => (PropertyBuilder)ForSqlServerUseSequenceHiLo((PropertyBuilder)propertyBuilder, name, schema); + => (PropertyBuilder)UseHiLo((PropertyBuilder)propertyBuilder, name, schema); /// /// Configures the database sequence used for the hi-lo pattern to generate values for the key property, @@ -77,13 +77,13 @@ public static PropertyBuilder ForSqlServerUseSequenceHiLo( /// The schema of the sequence. /// Indicates whether the configuration was specified using a data annotation. /// A builder to further configure the sequence. - public static IConventionSequenceBuilder ForSqlServerHasHiLoSequence( + public static IConventionSequenceBuilder HasHiLoSequence( [NotNull] this IConventionPropertyBuilder propertyBuilder, [CanBeNull] string name, [CanBeNull] string schema, bool fromDataAnnotation = false) { - if (!propertyBuilder.ForSqlServerCanSetHiLoSequence(name, schema)) + if (!propertyBuilder.CanSetHiLoSequence(name, schema)) { return null; } @@ -104,7 +104,7 @@ public static IConventionSequenceBuilder ForSqlServerHasHiLoSequence( /// The schema of the sequence. /// Indicates whether the configuration was specified using a data annotation. /// true if the given name and schema can be set for the hi-lo sequence. - public static bool ForSqlServerCanSetHiLoSequence( + public static bool CanSetHiLoSequence( [NotNull] this IConventionPropertyBuilder propertyBuilder, [CanBeNull] string name, [CanBeNull] string schema, @@ -126,7 +126,7 @@ public static bool ForSqlServerCanSetHiLoSequence( /// The value that is used for the very first row loaded into the table. /// The incremental value that is added to the identity value of the previous row that was loaded. /// The same builder instance so that multiple calls can be chained. - public static PropertyBuilder ForSqlServerUseIdentityColumn( + public static PropertyBuilder UseIdentityColumn( [NotNull] this PropertyBuilder propertyBuilder, int seed = 1, int increment = 1) @@ -152,42 +152,11 @@ public static PropertyBuilder ForSqlServerUseIdentityColumn( /// The value that is used for the very first row loaded into the table. /// The incremental value that is added to the identity value of the previous row that was loaded. /// The same builder instance so that multiple calls can be chained. - public static PropertyBuilder ForSqlServerUseIdentityColumn( - [NotNull] this PropertyBuilder propertyBuilder, - int seed = 1, - int increment = 1) - => (PropertyBuilder)ForSqlServerUseIdentityColumn((PropertyBuilder)propertyBuilder, seed, increment); - - /// - /// Configures the key property to use the SQL Server IDENTITY feature to generate values for new entities, - /// when targeting SQL Server. This method sets the property to be . - /// - /// The builder for the property being configured. - /// The value that is used for the very first row loaded into the table. - /// The incremental value that is added to the identity value of the previous row that was loaded. - /// The same builder instance so that multiple calls can be chained. - [Obsolete("Use ForSqlServerUseIdentityColumn instead")] - public static PropertyBuilder UseSqlServerIdentityColumn( - [NotNull] this PropertyBuilder propertyBuilder, - int seed = 1, - int increment = 1) - => propertyBuilder.ForSqlServerUseIdentityColumn(seed, increment); - - /// - /// Configures the key property to use the SQL Server IDENTITY feature to generate values for new entities, - /// when targeting SQL Server. This method sets the property to be . - /// - /// The type of the property being configured. - /// The builder for the property being configured. - /// The value that is used for the very first row loaded into the table. - /// The incremental value that is added to the identity value of the previous row that was loaded. - /// The same builder instance so that multiple calls can be chained. - [Obsolete("Use ForSqlServerUseIdentityColumn instead")] - public static PropertyBuilder UseSqlServerIdentityColumn( + public static PropertyBuilder UseIdentityColumn( [NotNull] this PropertyBuilder propertyBuilder, int seed = 1, int increment = 1) - => propertyBuilder.ForSqlServerUseIdentityColumn(seed, increment); + => (PropertyBuilder)UseIdentityColumn((PropertyBuilder)propertyBuilder, seed, increment); /// /// Configures the seed for SQL Server IDENTITY. @@ -199,10 +168,10 @@ public static PropertyBuilder UseSqlServerIdentityColumn( /// The same builder instance if the configuration was applied, /// null otherwise. /// - public static IConventionPropertyBuilder ForSqlServerHasIdentitySeed( + public static IConventionPropertyBuilder HasIdentityColumnSeed( [NotNull] this IConventionPropertyBuilder propertyBuilder, int? seed, bool fromDataAnnotation = false) { - if (propertyBuilder.ForSqlServerCanSetIdentitySeed(seed, fromDataAnnotation)) + if (propertyBuilder.CanSetIdentityColumnSeed(seed, fromDataAnnotation)) { propertyBuilder.Metadata.SetSqlServerIdentitySeed(seed, fromDataAnnotation); return propertyBuilder; @@ -218,7 +187,7 @@ public static IConventionPropertyBuilder ForSqlServerHasIdentitySeed( /// The value that is used for the very first row loaded into the table. /// Indicates whether the configuration was specified using a data annotation. /// true if the given value can be set as the seed for SQL Server IDENTITY. - public static bool ForSqlServerCanSetIdentitySeed( + public static bool CanSetIdentityColumnSeed( [NotNull] this IConventionPropertyBuilder propertyBuilder, int? seed, bool fromDataAnnotation = false) { Check.NotNull(propertyBuilder, nameof(propertyBuilder)); @@ -236,10 +205,10 @@ public static bool ForSqlServerCanSetIdentitySeed( /// The same builder instance if the configuration was applied, /// null otherwise. /// - public static IConventionPropertyBuilder ForSqlServerHasIdentityIncrement( + public static IConventionPropertyBuilder HasIdentityColumnIncrement( [NotNull] this IConventionPropertyBuilder propertyBuilder, int? increment, bool fromDataAnnotation = false) { - if (propertyBuilder.ForSqlServerCanSetIdentityIncrement(increment, fromDataAnnotation)) + if (propertyBuilder.CanSetIdentityColumnIncrement(increment, fromDataAnnotation)) { propertyBuilder.Metadata.SetSqlServerIdentityIncrement(increment, fromDataAnnotation); return propertyBuilder; @@ -255,7 +224,7 @@ public static IConventionPropertyBuilder ForSqlServerHasIdentityIncrement( /// The incremental value that is added to the identity value of the previous row that was loaded. /// Indicates whether the configuration was specified using a data annotation. /// true if the given value can be set as the default increment for SQL Server IDENTITY. - public static bool ForSqlServerCanSetIdentityIncrement( + public static bool CanSetIdentityColumnIncrement( [NotNull] this IConventionPropertyBuilder propertyBuilder, int? increment, bool fromDataAnnotation = false) { Check.NotNull(propertyBuilder, nameof(propertyBuilder)); @@ -273,7 +242,7 @@ public static bool ForSqlServerCanSetIdentityIncrement( /// The same builder instance if the configuration was applied, /// null otherwise. /// - public static IConventionPropertyBuilder ForSqlServerHasValueGenerationStrategy( + public static IConventionPropertyBuilder HasValueGenerationStrategy( [NotNull] this IConventionPropertyBuilder propertyBuilder, SqlServerValueGenerationStrategy? valueGenerationStrategy, bool fromDataAnnotation = false) @@ -284,13 +253,13 @@ public static IConventionPropertyBuilder ForSqlServerHasValueGenerationStrategy( propertyBuilder.Metadata.SetSqlServerValueGenerationStrategy(valueGenerationStrategy, fromDataAnnotation); if (valueGenerationStrategy != SqlServerValueGenerationStrategy.IdentityColumn) { - propertyBuilder.ForSqlServerHasIdentitySeed(null, fromDataAnnotation); - propertyBuilder.ForSqlServerHasIdentityIncrement(null, fromDataAnnotation); + propertyBuilder.HasIdentityColumnSeed(null, fromDataAnnotation); + propertyBuilder.HasIdentityColumnIncrement(null, fromDataAnnotation); } if (valueGenerationStrategy != SqlServerValueGenerationStrategy.SequenceHiLo) { - propertyBuilder.ForSqlServerHasHiLoSequence(null, null, fromDataAnnotation); + propertyBuilder.HasHiLoSequence(null, null, fromDataAnnotation); } return propertyBuilder; @@ -306,7 +275,7 @@ public static IConventionPropertyBuilder ForSqlServerHasValueGenerationStrategy( /// The value generation strategy. /// Indicates whether the configuration was specified using a data annotation. /// true if the given value can be set as the default value generation strategy. - public static bool ForSqlServerCanSetValueGenerationStrategy( + public static bool CanSetValueGenerationStrategy( [NotNull] this IConventionPropertyBuilder propertyBuilder, SqlServerValueGenerationStrategy? valueGenerationStrategy, bool fromDataAnnotation = false) @@ -318,5 +287,131 @@ public static bool ForSqlServerCanSetValueGenerationStrategy( && propertyBuilder.CanSetAnnotation( SqlServerAnnotationNames.ValueGenerationStrategy, valueGenerationStrategy, fromDataAnnotation); } + + /// + /// Configures the key property to use a sequence-based hi-lo pattern to generate values for new entities, + /// when targeting SQL Server. This method sets the property to be . + /// + /// The builder for the property being configured. + /// The name of the sequence. + /// The schema of the sequence. + /// The same builder instance so that multiple calls can be chained. + [Obsolete("Use UseHiLo")] + public static PropertyBuilder ForSqlServerUseSequenceHiLo( + [NotNull] this PropertyBuilder propertyBuilder, + [CanBeNull] string name = null, + [CanBeNull] string schema = null) + => propertyBuilder.UseHiLo(name, schema); + + /// + /// Configures the key property to use a sequence-based hi-lo pattern to generate values for new entities, + /// when targeting SQL Server. This method sets the property to be . + /// + /// The type of the property being configured. + /// The builder for the property being configured. + /// The name of the sequence. + /// The schema of the sequence. + /// The same builder instance so that multiple calls can be chained. + [Obsolete("Use UseHiLo")] + public static PropertyBuilder ForSqlServerUseSequenceHiLo( + [NotNull] this PropertyBuilder propertyBuilder, + [CanBeNull] string name = null, + [CanBeNull] string schema = null) + => propertyBuilder.UseHiLo(name, schema); + + /// + /// Configures the database sequence used for the hi-lo pattern to generate values for the key property, + /// when targeting SQL Server. + /// + /// The builder for the property being configured. + /// The name of the sequence. + /// The schema of the sequence. + /// Indicates whether the configuration was specified using a data annotation. + /// A builder to further configure the sequence. + [Obsolete("Use HasHiLoSequence")] + public static IConventionSequenceBuilder ForSqlServerHasHiLoSequence( + [NotNull] this IConventionPropertyBuilder propertyBuilder, + [CanBeNull] string name, + [CanBeNull] string schema, + bool fromDataAnnotation = false) + => propertyBuilder.HasHiLoSequence(name, schema); + + /// + /// Configures the key property to use the SQL Server IDENTITY feature to generate values for new entities, + /// when targeting SQL Server. This method sets the property to be . + /// + /// The builder for the property being configured. + /// The value that is used for the very first row loaded into the table. + /// The incremental value that is added to the identity value of the previous row that was loaded. + /// The same builder instance so that multiple calls can be chained. + [Obsolete("Use UseIdentityColumn")] + public static PropertyBuilder UseSqlServerIdentityColumn( + [NotNull] this PropertyBuilder propertyBuilder, + int seed = 1, + int increment = 1) + => propertyBuilder.UseIdentityColumn(seed, increment); + + /// + /// Configures the key property to use the SQL Server IDENTITY feature to generate values for new entities, + /// when targeting SQL Server. This method sets the property to be . + /// + /// The type of the property being configured. + /// The builder for the property being configured. + /// The value that is used for the very first row loaded into the table. + /// The incremental value that is added to the identity value of the previous row that was loaded. + /// The same builder instance so that multiple calls can be chained. + [Obsolete("Use UseIdentityColumn")] + public static PropertyBuilder UseSqlServerIdentityColumn( + [NotNull] this PropertyBuilder propertyBuilder, + int seed = 1, + int increment = 1) + => propertyBuilder.UseIdentityColumn(seed, increment); + + /// + /// Configures the seed for SQL Server IDENTITY. + /// + /// The builder for the property being configured. + /// The value that is used for the very first row loaded into the table. + /// Indicates whether the configuration was specified using a data annotation. + /// + /// The same builder instance if the configuration was applied, + /// null otherwise. + /// + [Obsolete("Use HasIdentityColumnSeed")] + public static IConventionPropertyBuilder ForSqlServerHasIdentitySeed( + [NotNull] this IConventionPropertyBuilder propertyBuilder, int? seed, bool fromDataAnnotation = false) + => propertyBuilder.HasIdentityColumnSeed(seed, fromDataAnnotation); + + /// + /// Configures the increment for SQL Server IDENTITY. + /// + /// The builder for the property being configured. + /// The incremental value that is added to the identity value of the previous row that was loaded. + /// Indicates whether the configuration was specified using a data annotation. + /// + /// The same builder instance if the configuration was applied, + /// null otherwise. + /// + [Obsolete("Use HasIdentityColumnIncrement")] + public static IConventionPropertyBuilder ForSqlServerHasIdentityIncrement( + [NotNull] this IConventionPropertyBuilder propertyBuilder, int? increment, bool fromDataAnnotation = false) + => propertyBuilder.HasIdentityColumnIncrement(increment, fromDataAnnotation); + + /// + /// Configures the value generation strategy for the key property, when targeting SQL Server. + /// + /// The builder for the property being configured. + /// The value generation strategy. + /// Indicates whether the configuration was specified using a data annotation. + /// + /// The same builder instance if the configuration was applied, + /// null otherwise. + /// + [Obsolete("Use HasValueGenerationStrategy")] + public static IConventionPropertyBuilder ForSqlServerHasValueGenerationStrategy( + [NotNull] this IConventionPropertyBuilder propertyBuilder, + SqlServerValueGenerationStrategy? valueGenerationStrategy, + bool fromDataAnnotation = false) + => propertyBuilder.HasValueGenerationStrategy(valueGenerationStrategy, fromDataAnnotation); } } diff --git a/src/EFCore.SqlServer/Metadata/Conventions/SqlServerMemoryOptimizedTablesConvention.cs b/src/EFCore.SqlServer/Metadata/Conventions/SqlServerMemoryOptimizedTablesConvention.cs index b329e2e75e9..ab1d5058f6d 100644 --- a/src/EFCore.SqlServer/Metadata/Conventions/SqlServerMemoryOptimizedTablesConvention.cs +++ b/src/EFCore.SqlServer/Metadata/Conventions/SqlServerMemoryOptimizedTablesConvention.cs @@ -55,13 +55,13 @@ public virtual void ProcessEntityTypeAnnotationChanged( var memoryOptimized = annotation?.Value as bool? == true; foreach (var key in entityTypeBuilder.Metadata.GetDeclaredKeys()) { - key.Builder.ForSqlServerIsClustered(memoryOptimized ? false : (bool?)null); + key.Builder.IsClustered(memoryOptimized ? false : (bool?)null); } foreach (var index in entityTypeBuilder.Metadata.GetDerivedTypesInclusive().SelectMany(et => et.GetDeclaredIndexes())) { - index.Builder.ForSqlServerIsClustered(memoryOptimized ? false : (bool?)null); + index.Builder.IsClustered(memoryOptimized ? false : (bool?)null); } } } @@ -75,7 +75,7 @@ public virtual void ProcessKeyAdded(IConventionKeyBuilder keyBuilder, IConventio { if (keyBuilder.Metadata.DeclaringEntityType.GetSqlServerIsMemoryOptimized()) { - keyBuilder.ForSqlServerIsClustered(false); + keyBuilder.IsClustered(false); } } @@ -88,7 +88,7 @@ public virtual void ProcessIndexAdded(IConventionIndexBuilder indexBuilder, ICon { if (indexBuilder.Metadata.DeclaringEntityType.GetAllBaseTypesInclusive().Any(et => et.GetSqlServerIsMemoryOptimized())) { - indexBuilder.ForSqlServerIsClustered(false); + indexBuilder.IsClustered(false); } } } diff --git a/src/EFCore.SqlServer/Metadata/Conventions/SqlServerStoreGenerationConvention.cs b/src/EFCore.SqlServer/Metadata/Conventions/SqlServerStoreGenerationConvention.cs index ced8007cafa..593f8ae15a8 100644 --- a/src/EFCore.SqlServer/Metadata/Conventions/SqlServerStoreGenerationConvention.cs +++ b/src/EFCore.SqlServer/Metadata/Conventions/SqlServerStoreGenerationConvention.cs @@ -55,7 +55,7 @@ public override void ProcessPropertyAnnotationChanged( switch (name) { case RelationalAnnotationNames.DefaultValue: - if (propertyBuilder.ForSqlServerHasValueGenerationStrategy(null, fromDataAnnotation) == null + if (propertyBuilder.HasValueGenerationStrategy(null, fromDataAnnotation) == null && propertyBuilder.HasDefaultValue(null, fromDataAnnotation) != null) { context.StopProcessing(); @@ -64,7 +64,7 @@ public override void ProcessPropertyAnnotationChanged( break; case RelationalAnnotationNames.DefaultValueSql: - if (propertyBuilder.ForSqlServerHasValueGenerationStrategy(null, fromDataAnnotation) == null + if (propertyBuilder.HasValueGenerationStrategy(null, fromDataAnnotation) == null && propertyBuilder.HasDefaultValueSql(null, fromDataAnnotation) != null) { context.StopProcessing(); @@ -73,7 +73,7 @@ public override void ProcessPropertyAnnotationChanged( break; case RelationalAnnotationNames.ComputedColumnSql: - if (propertyBuilder.ForSqlServerHasValueGenerationStrategy(null, fromDataAnnotation) == null + if (propertyBuilder.HasValueGenerationStrategy(null, fromDataAnnotation) == null && propertyBuilder.HasComputedColumnSql(null, fromDataAnnotation) != null) { context.StopProcessing(); @@ -85,7 +85,7 @@ public override void ProcessPropertyAnnotationChanged( if ((propertyBuilder.HasDefaultValue(null, fromDataAnnotation) == null | propertyBuilder.HasDefaultValueSql(null, fromDataAnnotation) == null | propertyBuilder.HasComputedColumnSql(null, fromDataAnnotation) == null) - && propertyBuilder.ForSqlServerHasValueGenerationStrategy(null, fromDataAnnotation) != null) + && propertyBuilder.HasValueGenerationStrategy(null, fromDataAnnotation) != null) { context.StopProcessing(); return; diff --git a/src/EFCore.SqlServer/Metadata/Conventions/SqlServerValueGenerationStrategyConvention.cs b/src/EFCore.SqlServer/Metadata/Conventions/SqlServerValueGenerationStrategyConvention.cs index f7e1278a4e4..3a6014ff497 100644 --- a/src/EFCore.SqlServer/Metadata/Conventions/SqlServerValueGenerationStrategyConvention.cs +++ b/src/EFCore.SqlServer/Metadata/Conventions/SqlServerValueGenerationStrategyConvention.cs @@ -38,7 +38,7 @@ public SqlServerValueGenerationStrategyConvention( /// Additional information associated with convention execution. public virtual void ProcessModelInitialized(IConventionModelBuilder modelBuilder, IConventionContext context) { - modelBuilder.ForSqlServerHasValueGenerationStrategy(SqlServerValueGenerationStrategy.IdentityColumn); + modelBuilder.HasValueGenerationStrategy(SqlServerValueGenerationStrategy.IdentityColumn); } /// @@ -57,7 +57,7 @@ public virtual void ProcessModelFinalized( var strategy = property.GetSqlServerValueGenerationStrategy(); if (strategy != SqlServerValueGenerationStrategy.None) { - property.Builder.ForSqlServerHasValueGenerationStrategy(strategy); + property.Builder.HasValueGenerationStrategy(strategy); } } } diff --git a/src/EFCore.Sqlite.Core/Extensions/SqlitePropertyBuilderExtensions.cs b/src/EFCore.Sqlite.Core/Extensions/SqlitePropertyBuilderExtensions.cs index f262ceab2b0..226dac15c90 100644 --- a/src/EFCore.Sqlite.Core/Extensions/SqlitePropertyBuilderExtensions.cs +++ b/src/EFCore.Sqlite.Core/Extensions/SqlitePropertyBuilderExtensions.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Sqlite.Metadata.Internal; @@ -20,7 +21,7 @@ public static class SqlitePropertyBuilderExtensions /// The builder for the property being configured. /// The SRID. /// The same builder instance so that multiple calls can be chained. - public static PropertyBuilder ForSqliteHasSrid([NotNull] this PropertyBuilder propertyBuilder, int srid) + public static PropertyBuilder HasSrid([NotNull] this PropertyBuilder propertyBuilder, int srid) { Check.NotNull(propertyBuilder, nameof(propertyBuilder)); @@ -35,10 +36,10 @@ public static PropertyBuilder ForSqliteHasSrid([NotNull] this PropertyBuilder pr /// The builder for the property being configured. /// The SRID. /// The same builder instance so that multiple calls can be chained. - public static PropertyBuilder ForSqliteHasSrid( + public static PropertyBuilder HasSrid( [NotNull] this PropertyBuilder propertyBuilder, int srid) - => (PropertyBuilder)ForSqliteHasSrid((PropertyBuilder)propertyBuilder, srid); + => (PropertyBuilder)HasSrid((PropertyBuilder)propertyBuilder, srid); /// /// Configures the SRID of the column that the property maps to when targeting SQLite. @@ -50,12 +51,12 @@ public static PropertyBuilder ForSqliteHasSrid( /// The same builder instance if the configuration was applied, /// null otherwise. /// - public static IConventionPropertyBuilder ForSqliteHasSrid( + public static IConventionPropertyBuilder HasSrid( [NotNull] this IConventionPropertyBuilder propertyBuilder, int? srid, bool fromDataAnnotation = false) { - if (propertyBuilder.ForSqliteCanSetSrid(srid, fromDataAnnotation)) + if (propertyBuilder.CanSetSrid(srid, fromDataAnnotation)) { propertyBuilder.Metadata.SetSqliteSrid(srid, fromDataAnnotation); @@ -72,7 +73,7 @@ public static IConventionPropertyBuilder ForSqliteHasSrid( /// The SRID. /// Indicates whether the configuration was specified using a data annotation. /// true if the given value can be set as the SRID for the column. - public static bool ForSqliteCanSetSrid( + public static bool CanSetSrid( [NotNull] this IConventionPropertyBuilder propertyBuilder, int? srid, bool fromDataAnnotation = false) @@ -91,12 +92,12 @@ public static bool ForSqliteCanSetSrid( /// The same builder instance if the configuration was applied, /// null otherwise. /// - public static IConventionPropertyBuilder ForSqliteHasDimension( + public static IConventionPropertyBuilder HasSpatialDimension( [NotNull] this IConventionPropertyBuilder propertyBuilder, [CanBeNull] string dimension, bool fromDataAnnotation = false) { - if (propertyBuilder.ForSqliteCanSetDimension(dimension, fromDataAnnotation)) + if (propertyBuilder.CanSetSpatialDimension(dimension, fromDataAnnotation)) { propertyBuilder.Metadata.SetSqliteDimension(dimension, fromDataAnnotation); @@ -113,7 +114,7 @@ public static IConventionPropertyBuilder ForSqliteHasDimension( /// The dimension. /// Indicates whether the configuration was specified using a data annotation. /// true if the given value can be set as the dimension for the column. - public static bool ForSqliteCanSetDimension( + public static bool CanSetSpatialDimension( [NotNull] this IConventionPropertyBuilder propertyBuilder, [CanBeNull] string dimension, bool fromDataAnnotation = false) @@ -121,5 +122,61 @@ public static bool ForSqliteCanSetDimension( SqliteAnnotationNames.Srid, dimension, fromDataAnnotation); + + /// + /// Configures the SRID of the column that the property maps to when targeting SQLite. + /// + /// The builder for the property being configured. + /// The SRID. + /// The same builder instance so that multiple calls can be chained. + [Obsolete("Use HasSrid")] + public static PropertyBuilder ForSqliteHasSrid([NotNull] this PropertyBuilder propertyBuilder, int srid) + => propertyBuilder.HasSrid(srid); + + /// + /// Configures the SRID of the column that the property maps to when targeting SQLite. + /// + /// The builder for the property being configured. + /// The SRID. + /// The same builder instance so that multiple calls can be chained. + [Obsolete("Use HasSrid")] + public static PropertyBuilder ForSqliteHasSrid( + [NotNull] this PropertyBuilder propertyBuilder, + int srid) + => propertyBuilder.HasSrid(srid); + + /// + /// Configures the SRID of the column that the property maps to when targeting SQLite. + /// + /// The builder for the property being configured. + /// The SRID. + /// Indicates whether the configuration was specified using a data annotation. + /// + /// The same builder instance if the configuration was applied, + /// null otherwise. + /// + [Obsolete("Use HasSrid")] + public static IConventionPropertyBuilder ForSqliteHasSrid( + [NotNull] this IConventionPropertyBuilder propertyBuilder, + int? srid, + bool fromDataAnnotation = false) + => propertyBuilder.HasSrid(srid, fromDataAnnotation); + + /// + /// Configures the dimension of the column that the property maps to when targeting SQLite. + /// + /// The builder for the property being configured. + /// The dimension. + /// Indicates whether the configuration was specified using a data annotation. + /// + /// The same builder instance if the configuration was applied, + /// null otherwise. + /// + [Obsolete("Use HasSpatialDimension")] + public static IConventionPropertyBuilder ForSqliteHasDimension( + [NotNull] this IConventionPropertyBuilder propertyBuilder, + [CanBeNull] string dimension, + bool fromDataAnnotation = false) + => propertyBuilder.HasSpatialDimension(dimension, fromDataAnnotation); } } diff --git a/src/EFCore.Sqlite.NTS/Extensions/SqliteNetTopologySuitePropertyBuilderExtensions.cs b/src/EFCore.Sqlite.NTS/Extensions/SqliteNetTopologySuitePropertyBuilderExtensions.cs index 477849995a5..83bfec94ca3 100644 --- a/src/EFCore.Sqlite.NTS/Extensions/SqliteNetTopologySuitePropertyBuilderExtensions.cs +++ b/src/EFCore.Sqlite.NTS/Extensions/SqliteNetTopologySuitePropertyBuilderExtensions.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Utilities; @@ -19,7 +20,7 @@ public static class SqliteNetTopologySuitePropertyBuilderExtensions /// The builder for the property being configured. /// The dimension ordinates. /// The same builder instance so that multiple calls can be chained. - public static PropertyBuilder ForSqliteHasDimension( + public static PropertyBuilder HasSpatialDimension( [NotNull] this PropertyBuilder propertyBuilder, Ordinates ordinates) { @@ -47,9 +48,33 @@ public static PropertyBuilder ForSqliteHasDimension( /// The builder for the property being configured. /// The dimension ordinates. /// The same builder instance so that multiple calls can be chained. + public static PropertyBuilder HasSpatialDimension( + [NotNull] this PropertyBuilder propertyBuilder, + Ordinates ordinates) + => (PropertyBuilder)HasSpatialDimension((PropertyBuilder)propertyBuilder, ordinates); + + /// + /// Configures the dimension of the column that the property maps to when targeting SQLite. + /// + /// The builder for the property being configured. + /// The dimension ordinates. + /// The same builder instance so that multiple calls can be chained. + [Obsolete("Use HasSpatialDimension")] + public static PropertyBuilder ForSqliteHasDimension( + [NotNull] this PropertyBuilder propertyBuilder, + Ordinates ordinates) + => propertyBuilder.HasSpatialDimension(ordinates); + + /// + /// Configures the dimension of the column that the property maps to when targeting SQLite. + /// + /// The builder for the property being configured. + /// The dimension ordinates. + /// The same builder instance so that multiple calls can be chained. + [Obsolete("Use HasSpatialDimension")] public static PropertyBuilder ForSqliteHasDimension( [NotNull] this PropertyBuilder propertyBuilder, Ordinates ordinates) - => (PropertyBuilder)ForSqliteHasDimension((PropertyBuilder)propertyBuilder, ordinates); + => propertyBuilder.HasSpatialDimension(ordinates); } } diff --git a/test/EFCore.Cosmos.FunctionalTests/EndToEndCosmosTest.cs b/test/EFCore.Cosmos.FunctionalTests/EndToEndCosmosTest.cs index e250eb5fa70..22c834cb039 100644 --- a/test/EFCore.Cosmos.FunctionalTests/EndToEndCosmosTest.cs +++ b/test/EFCore.Cosmos.FunctionalTests/EndToEndCosmosTest.cs @@ -270,7 +270,7 @@ public PartitionKeyContext(DbContextOptions dbContextOptions) protected override void OnModelCreating(ModelBuilder modelBuilder) { - modelBuilder.Entity().ForCosmosHasPartitionKey(c => c.PartitionKey); + modelBuilder.Entity().HasPartitionKey(c => c.PartitionKey); } } @@ -334,8 +334,8 @@ public ExtraCustomerContext(DbContextOptions dbContextOptions) protected override void OnModelCreating(ModelBuilder modelBuilder) { - modelBuilder.ForCosmosHasDefaultContainer(nameof(CustomerContext)); - modelBuilder.Entity().Property("EMail").ForCosmosToProperty("e-mail"); + modelBuilder.HasDefaultContainer(nameof(CustomerContext)); + modelBuilder.Entity().Property("EMail").ToJsonProperty("e-mail"); } } @@ -381,7 +381,7 @@ public UnmappedCustomerContext(DbContextOptions dbContextOptions) protected override void OnModelCreating(ModelBuilder modelBuilder) { - modelBuilder.Entity().Property(c => c.Name).ForCosmosToProperty(""); + modelBuilder.Entity().Property(c => c.Name).ToJsonProperty(""); } } diff --git a/test/EFCore.Cosmos.FunctionalTests/NestedDocumentsTest.cs b/test/EFCore.Cosmos.FunctionalTests/NestedDocumentsTest.cs index 8a86728f4ca..264ea9982d0 100644 --- a/test/EFCore.Cosmos.FunctionalTests/NestedDocumentsTest.cs +++ b/test/EFCore.Cosmos.FunctionalTests/NestedDocumentsTest.cs @@ -389,7 +389,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) modelBuilder.Entity( eb => eb.OwnsMany(v => v.Addresses, b => { - b.ForCosmosToProperty("Stored Addresses"); + b.ToJsonProperty("Stored Addresses"); })); } } diff --git a/test/EFCore.Cosmos.Tests/Infrastructure/CosmosModelValidatorTest.cs b/test/EFCore.Cosmos.Tests/Infrastructure/CosmosModelValidatorTest.cs index 9f1b0478d9e..31008ed106b 100644 --- a/test/EFCore.Cosmos.Tests/Infrastructure/CosmosModelValidatorTest.cs +++ b/test/EFCore.Cosmos.Tests/Infrastructure/CosmosModelValidatorTest.cs @@ -25,8 +25,8 @@ public virtual void Passes_on_valid_model() public virtual void Passes_on_valid_partition_keys() { var modelBuilder = CreateConventionalModelBuilder(); - modelBuilder.Entity().ForCosmosToContainer("Orders").ForCosmosHasPartitionKey(c => c.PartitionId); - modelBuilder.Entity().ForCosmosToContainer("Orders").ForCosmosHasPartitionKey(o => o.PartitionId) + modelBuilder.Entity().ToContainer("Orders").HasPartitionKey(c => c.PartitionId); + modelBuilder.Entity().ToContainer("Orders").HasPartitionKey(o => o.PartitionId) .Property(o => o.PartitionId).HasConversion(); var model = modelBuilder.Model; @@ -37,7 +37,7 @@ public virtual void Passes_on_valid_partition_keys() public virtual void Detects_missing_partition_key_property() { var modelBuilder = CreateConventionalModelBuilder(); - modelBuilder.Entity().ForCosmosHasPartitionKey("PartitionKey"); + modelBuilder.Entity().HasPartitionKey("PartitionKey"); var model = modelBuilder.Model; VerifyError(CosmosStrings.PartitionKeyMissingProperty(typeof(Order).Name, "PartitionKey"), model); @@ -47,8 +47,8 @@ public virtual void Detects_missing_partition_key_property() public virtual void Detects_missing_partition_key_on_first_type() { var modelBuilder = CreateConventionalModelBuilder(); - modelBuilder.Entity().ForCosmosToContainer("Orders"); - modelBuilder.Entity().ForCosmosToContainer("Orders").ForCosmosHasPartitionKey(c => c.PartitionId); + modelBuilder.Entity().ToContainer("Orders"); + modelBuilder.Entity().ToContainer("Orders").HasPartitionKey(c => c.PartitionId); var model = modelBuilder.Model; VerifyError(CosmosStrings.NoPartitionKey(typeof(Customer).Name, "Orders"), model); @@ -58,8 +58,8 @@ public virtual void Detects_missing_partition_key_on_first_type() public virtual void Detects_missing_partition_keys_one_last_type() { var modelBuilder = CreateConventionalModelBuilder(); - modelBuilder.Entity().ForCosmosToContainer("Orders").ForCosmosHasPartitionKey(c => c.PartitionId); - modelBuilder.Entity().ForCosmosToContainer("Orders"); + modelBuilder.Entity().ToContainer("Orders").HasPartitionKey(c => c.PartitionId); + modelBuilder.Entity().ToContainer("Orders"); var model = modelBuilder.Model; VerifyError(CosmosStrings.NoPartitionKey(typeof(Order).Name, "Orders"), model); @@ -69,9 +69,9 @@ public virtual void Detects_missing_partition_keys_one_last_type() public virtual void Detects_partition_keys_mapped_to_different_properties() { var modelBuilder = CreateConventionalModelBuilder(); - modelBuilder.Entity().ForCosmosToContainer("Orders").ForCosmosHasPartitionKey(c => c.PartitionId) - .Property(c => c.PartitionId).ForCosmosToProperty("pk"); - modelBuilder.Entity().ForCosmosToContainer("Orders").ForCosmosHasPartitionKey(c => c.PartitionId); + modelBuilder.Entity().ToContainer("Orders").HasPartitionKey(c => c.PartitionId) + .Property(c => c.PartitionId).ToJsonProperty("pk"); + modelBuilder.Entity().ToContainer("Orders").HasPartitionKey(c => c.PartitionId); var model = modelBuilder.Model; VerifyError(CosmosStrings.PartitionKeyStoreNameMismatch( @@ -82,8 +82,8 @@ public virtual void Detects_partition_keys_mapped_to_different_properties() public virtual void Detects_partition_key_of_different_type() { var modelBuilder = CreateConventionalModelBuilder(); - modelBuilder.Entity().ForCosmosToContainer("Orders").ForCosmosHasPartitionKey(c => c.PartitionId); - modelBuilder.Entity().ForCosmosToContainer("Orders").ForCosmosHasPartitionKey(o => o.PartitionId) + modelBuilder.Entity().ToContainer("Orders").HasPartitionKey(c => c.PartitionId); + modelBuilder.Entity().ToContainer("Orders").HasPartitionKey(o => o.PartitionId) .Property(c => c.PartitionId).HasConversion(); var model = modelBuilder.Model; @@ -95,8 +95,8 @@ public virtual void Detects_partition_key_of_different_type() public virtual void Detects_missing_discriminator() { var modelBuilder = CreateConventionalModelBuilder(); - modelBuilder.Entity().ForCosmosToContainer("Orders").HasNoDiscriminator(); - modelBuilder.Entity().ForCosmosToContainer("Orders"); + modelBuilder.Entity().ToContainer("Orders").HasNoDiscriminator(); + modelBuilder.Entity().ToContainer("Orders"); var model = modelBuilder.Model; VerifyError(CosmosStrings.NoDiscriminatorProperty(typeof(Customer).Name, "Orders"), model); @@ -106,8 +106,8 @@ public virtual void Detects_missing_discriminator() public virtual void Detects_missing_discriminator_value() { var modelBuilder = CreateConventionalModelBuilder(); - modelBuilder.Entity().ForCosmosToContainer("Orders").HasDiscriminator().HasValue(null); - modelBuilder.Entity().ForCosmosToContainer("Orders"); + modelBuilder.Entity().ToContainer("Orders").HasDiscriminator().HasValue(null); + modelBuilder.Entity().ToContainer("Orders"); var model = modelBuilder.Model; VerifyError(CosmosStrings.NoDiscriminatorValue(typeof(Customer).Name, "Orders"), model); @@ -117,8 +117,8 @@ public virtual void Detects_missing_discriminator_value() public virtual void Detects_duplicate_discriminator_values() { var modelBuilder = CreateConventionalModelBuilder(); - modelBuilder.Entity().ForCosmosToContainer("Orders").HasDiscriminator().HasValue("type"); - modelBuilder.Entity().ForCosmosToContainer("Orders").HasDiscriminator().HasValue("type"); + modelBuilder.Entity().ToContainer("Orders").HasDiscriminator().HasValue("type"); + modelBuilder.Entity().ToContainer("Orders").HasDiscriminator().HasValue("type"); var model = modelBuilder.Model; VerifyError(CosmosStrings.DuplicateDiscriminatorValue(typeof(Order).Name, "type", typeof(Customer).Name, "Orders"), model); diff --git a/test/EFCore.Cosmos.Tests/Metadata/CosmosBuilderExtensionsTest.cs b/test/EFCore.Cosmos.Tests/Metadata/CosmosBuilderExtensionsTest.cs index 5b6c6020003..16d1180c492 100644 --- a/test/EFCore.Cosmos.Tests/Metadata/CosmosBuilderExtensionsTest.cs +++ b/test/EFCore.Cosmos.Tests/Metadata/CosmosBuilderExtensionsTest.cs @@ -19,13 +19,13 @@ public void Can_get_and_set_collection_name() Assert.Equal(nameof(DbContext), entityType.Metadata.GetCosmosContainer()); - entityType.ForCosmosToContainer("Customizer"); + entityType.ToContainer("Customizer"); Assert.Equal("Customizer", entityType.Metadata.GetCosmosContainer()); - entityType.ForCosmosToContainer(null); + entityType.ToContainer(null); Assert.Equal(nameof(DbContext), entityType.Metadata.GetCosmosContainer()); - modelBuilder.ForCosmosHasDefaultContainer("Unicorn"); + modelBuilder.HasDefaultContainer("Unicorn"); Assert.Equal("Unicorn", entityType.Metadata.GetCosmosContainer()); } @@ -37,19 +37,19 @@ public void Can_get_and_set_partition_key_name() var entityTypeBuilder = modelBuilder.Entity(); var entityType = entityTypeBuilder.Metadata; - ((IConventionEntityType)entityType).Builder.ForCosmosHasPartitionKey("pk"); + ((IConventionEntityType)entityType).Builder.HasPartitionKey("pk"); Assert.Equal("pk", entityType.GetCosmosPartitionKeyPropertyName()); Assert.Equal(ConfigurationSource.Convention, ((IConventionEntityType)entityType).GetCosmosPartitionKeyPropertyNameConfigurationSource()); - entityTypeBuilder.ForCosmosHasPartitionKey("pk"); + entityTypeBuilder.HasPartitionKey("pk"); Assert.Equal("pk", entityType.GetCosmosPartitionKeyPropertyName()); Assert.Equal(ConfigurationSource.Explicit, ((IConventionEntityType)entityType).GetCosmosPartitionKeyPropertyNameConfigurationSource()); - Assert.False(((IConventionEntityType)entityType).Builder.ForCosmosCanSetPartitionKey("partition")); + Assert.False(((IConventionEntityType)entityType).Builder.CanSetPartitionKey("partition")); - entityTypeBuilder.ForCosmosHasPartitionKey(null); + entityTypeBuilder.HasPartitionKey(null); Assert.Null(entityType.GetCosmosPartitionKeyPropertyName()); Assert.Null(((IConventionEntityType)entityType).GetCosmosPartitionKeyPropertyNameConfigurationSource()); } @@ -63,19 +63,19 @@ public void Default_container_name_is_used_if_not_set() .Entity(); var entityType = modelBuilder.Model.FindEntityType(typeof(Customer)); - modelBuilder.ForCosmosHasDefaultContainer(null); + modelBuilder.HasDefaultContainer(null); Assert.Equal(nameof(Customer), entityType.GetCosmosContainer()); Assert.Null(modelBuilder.Model.GetCosmosDefaultContainer()); - modelBuilder.ForCosmosHasDefaultContainer("db0"); + modelBuilder.HasDefaultContainer("db0"); Assert.Equal("db0", entityType.GetCosmosContainer()); Assert.Equal("db0", modelBuilder.Model.GetCosmosDefaultContainer()); modelBuilder .Entity() - .ForCosmosToContainer("db1"); + .ToContainer("db1"); Assert.Equal("db1", entityType.GetCosmosContainer()); } diff --git a/test/EFCore.Cosmos.Tests/Metadata/CosmosMetadataExtensionsTest.cs b/test/EFCore.Cosmos.Tests/Metadata/CosmosMetadataExtensionsTest.cs index c2bebaad1b2..888f9f3ac3c 100644 --- a/test/EFCore.Cosmos.Tests/Metadata/CosmosMetadataExtensionsTest.cs +++ b/test/EFCore.Cosmos.Tests/Metadata/CosmosMetadataExtensionsTest.cs @@ -32,7 +32,7 @@ public void Can_get_and_set_collection_name() Assert.Equal(nameof(Customer), entityType.GetCosmosContainer()); Assert.Null(((IConventionEntityType)entityType).GetCosmosContainerConfigurationSource()); - ((IConventionModel)modelBuilder.Model).Builder.ForCosmosHasDefaultContainer("Unicorn"); + ((IConventionModel)modelBuilder.Model).Builder.HasDefaultContainer("Unicorn"); Assert.Equal("Unicorn", entityType.GetCosmosContainer()); } diff --git a/test/EFCore.CrossStore.FunctionalTests/CrossStoreFixture.cs b/test/EFCore.CrossStore.FunctionalTests/CrossStoreFixture.cs index 30f1b929d1b..00513c04ef1 100644 --- a/test/EFCore.CrossStore.FunctionalTests/CrossStoreFixture.cs +++ b/test/EFCore.CrossStore.FunctionalTests/CrossStoreFixture.cs @@ -35,7 +35,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder, DbContext con eb.ToTable("RelationalSimpleEntity"); eb.Property(typeof(string), SimpleEntity.ShadowPropertyName); eb.HasKey(e => e.Id); - eb.Property(e => e.Id).ForSqlServerUseIdentityColumn(); + eb.Property(e => e.Id).UseIdentityColumn(); }); } } diff --git a/test/EFCore.SqlServer.FunctionalTests/CommandConfigurationTest.cs b/test/EFCore.SqlServer.FunctionalTests/CommandConfigurationTest.cs index 23b80edeff0..31fb8373470 100644 --- a/test/EFCore.SqlServer.FunctionalTests/CommandConfigurationTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/CommandConfigurationTest.cs @@ -87,7 +87,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) { if (TestEnvironment.GetFlag(nameof(SqlServerCondition.SupportsSequences)) ?? true) { - modelBuilder.ForSqlServerUseSequenceHiLo(); + modelBuilder.UseHiLo(); } } } diff --git a/test/EFCore.SqlServer.FunctionalTests/GraphUpdatesSqlServerTestIdentity.cs b/test/EFCore.SqlServer.FunctionalTests/GraphUpdatesSqlServerTestIdentity.cs index bfc12cb4833..d1fa571428e 100644 --- a/test/EFCore.SqlServer.FunctionalTests/GraphUpdatesSqlServerTestIdentity.cs +++ b/test/EFCore.SqlServer.FunctionalTests/GraphUpdatesSqlServerTestIdentity.cs @@ -16,7 +16,7 @@ public class GraphUpdatesWithIdentitySqlServerFixture : GraphUpdatesSqlServerFix protected override void OnModelCreating(ModelBuilder modelBuilder, DbContext context) { - modelBuilder.ForSqlServerUseIdentityColumns(); + modelBuilder.UseIdentityColumns(); base.OnModelCreating(modelBuilder, context); } diff --git a/test/EFCore.SqlServer.FunctionalTests/GraphUpdatesSqlServerTestSequence.cs b/test/EFCore.SqlServer.FunctionalTests/GraphUpdatesSqlServerTestSequence.cs index 89d1a542341..7c399d2f92f 100644 --- a/test/EFCore.SqlServer.FunctionalTests/GraphUpdatesSqlServerTestSequence.cs +++ b/test/EFCore.SqlServer.FunctionalTests/GraphUpdatesSqlServerTestSequence.cs @@ -20,7 +20,7 @@ public class GraphUpdatesWithSequenceSqlServerFixture : GraphUpdatesSqlServerFix protected override void OnModelCreating(ModelBuilder modelBuilder, DbContext context) { - modelBuilder.ForSqlServerUseSequenceHiLo(); // ensure model uses sequences + modelBuilder.UseHiLo(); // ensure model uses sequences base.OnModelCreating(modelBuilder, context); } } diff --git a/test/EFCore.SqlServer.FunctionalTests/MemoryOptimizedTablesTest.cs b/test/EFCore.SqlServer.FunctionalTests/MemoryOptimizedTablesTest.cs index a69d2a6fb8b..624832011d8 100644 --- a/test/EFCore.SqlServer.FunctionalTests/MemoryOptimizedTablesTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/MemoryOptimizedTablesTest.cs @@ -87,12 +87,12 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) .Entity( eb => { - eb.ForSqlServerIsMemoryOptimized(); + eb.IsMemoryOptimized(); eb.HasIndex(e => e.Name).IsUnique(); eb.HasOne(e => e.BigUn).WithMany(e => e.FastUns).IsRequired().OnDelete(DeleteBehavior.Restrict); }); - modelBuilder.Entity().ForSqlServerIsMemoryOptimized(); + modelBuilder.Entity().IsMemoryOptimized(); } } diff --git a/test/EFCore.SqlServer.FunctionalTests/MonsterFixupChangedChangingSqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/MonsterFixupChangedChangingSqlServerTest.cs index b901f8a8d61..4c08b512a68 100644 --- a/test/EFCore.SqlServer.FunctionalTests/MonsterFixupChangedChangingSqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/MonsterFixupChangedChangingSqlServerTest.cs @@ -22,7 +22,7 @@ protected override void OnModelCreating(builder); - builder.Entity().Property(e => e.MessageId).ForSqlServerUseIdentityColumn(); + builder.Entity().Property(e => e.MessageId).UseIdentityColumn(); builder.Entity() .OwnsOne( @@ -33,8 +33,8 @@ protected override void OnModelCreating d.Height).HasColumnType("decimal(18,2)"); }); - builder.Entity().Property(e => e.PhotoId).ForSqlServerUseIdentityColumn(); - builder.Entity().Property(e => e.ReviewId).ForSqlServerUseIdentityColumn(); + builder.Entity().Property(e => e.PhotoId).UseIdentityColumn(); + builder.Entity().Property(e => e.ReviewId).UseIdentityColumn(); builder.Entity() .OwnsOne( diff --git a/test/EFCore.SqlServer.FunctionalTests/ProxyGraphUpdatesSqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/ProxyGraphUpdatesSqlServerTest.cs index dbd8d626f8f..7405f397bf9 100644 --- a/test/EFCore.SqlServer.FunctionalTests/ProxyGraphUpdatesSqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/ProxyGraphUpdatesSqlServerTest.cs @@ -47,7 +47,7 @@ protected override IServiceCollection AddServices(IServiceCollection serviceColl protected override void OnModelCreating(ModelBuilder modelBuilder, DbContext context) { - modelBuilder.ForSqlServerUseIdentityColumns(); + modelBuilder.UseIdentityColumns(); base.OnModelCreating(modelBuilder, context); } diff --git a/test/EFCore.SqlServer.FunctionalTests/SequenceEndToEndTest.cs b/test/EFCore.SqlServer.FunctionalTests/SequenceEndToEndTest.cs index 2bc0670f839..1f126df4877 100644 --- a/test/EFCore.SqlServer.FunctionalTests/SequenceEndToEndTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/SequenceEndToEndTest.cs @@ -345,7 +345,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) b => { b.HasKey(e => e.Identifier); - b.Property(e => e.Identifier).ForSqlServerUseSequenceHiLo(); + b.Property(e => e.Identifier).UseHiLo(); }); } } @@ -462,11 +462,11 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) b.HasKey(e => e.Identifier); if (_useSequence) { - b.Property(e => e.Identifier).ForSqlServerUseSequenceHiLo(); + b.Property(e => e.Identifier).UseHiLo(); } else { - b.Property(e => e.Identifier).ForSqlServerUseIdentityColumn(); + b.Property(e => e.Identifier).UseIdentityColumn(); } }); } diff --git a/test/EFCore.SqlServer.FunctionalTests/SqlAzure/Model/AdventureWorksContext.cs b/test/EFCore.SqlServer.FunctionalTests/SqlAzure/Model/AdventureWorksContext.cs index 8f49cf67403..c899d19aeb7 100644 --- a/test/EFCore.SqlServer.FunctionalTests/SqlAzure/Model/AdventureWorksContext.cs +++ b/test/EFCore.SqlServer.FunctionalTests/SqlAzure/Model/AdventureWorksContext.cs @@ -249,7 +249,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) .HasName("AK_SalesOrderHeader_rowguid") .IsUnique(); - entity.Property(e => e.SalesOrderID).ForSqlServerUseSequenceHiLo("SalesOrderNumber", "SalesLT"); + entity.Property(e => e.SalesOrderID).UseHiLo("SalesOrderNumber", "SalesLT"); entity.Property(e => e.CreditCardApprovalCode).HasColumnType("varchar(15)"); diff --git a/test/EFCore.SqlServer.FunctionalTests/SqlServerEndToEndTest.cs b/test/EFCore.SqlServer.FunctionalTests/SqlServerEndToEndTest.cs index 9d9f26ba97c..eb77ddabc26 100644 --- a/test/EFCore.SqlServer.FunctionalTests/SqlServerEndToEndTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/SqlServerEndToEndTest.cs @@ -201,7 +201,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) .Entity() .Property(e => e.Id) .HasColumnType("numeric(18, 0)") - .ForSqlServerUseIdentityColumn(); + .UseIdentityColumn(); modelBuilder .Entity() @@ -212,7 +212,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) modelBuilder .Entity() .Property(e => e.Id) - .ForSqlServerUseIdentityColumn(); + .UseIdentityColumn(); modelBuilder .Entity() diff --git a/test/EFCore.SqlServer.FunctionalTests/SqlServerMigrationSqlGeneratorTest.cs b/test/EFCore.SqlServer.FunctionalTests/SqlServerMigrationSqlGeneratorTest.cs index 070f83269d5..5086c76a4d0 100644 --- a/test/EFCore.SqlServer.FunctionalTests/SqlServerMigrationSqlGeneratorTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/SqlServerMigrationSqlGeneratorTest.cs @@ -382,8 +382,10 @@ public virtual void AlterColumnOperation_computed_with_index() Sql); } - [ConditionalFact] - public virtual void AlterColumnOperation_memoryOptimized_with_index() + [ConditionalTheory] + [InlineData(false)] + [InlineData(true)] + public virtual void AlterColumnOperation_memoryOptimized_with_index(bool obsolete) { Generate( modelBuilder => modelBuilder @@ -391,7 +393,16 @@ public virtual void AlterColumnOperation_memoryOptimized_with_index() .Entity( "Person", x => { - x.ForSqlServerIsMemoryOptimized(); + if (obsolete) + { +#pragma warning disable 618 + x.ForSqlServerIsMemoryOptimized(); +#pragma warning restore 618 + } + else + { + x.IsMemoryOptimized(); + } x.Property("Name"); x.HasKey("Name"); x.HasIndex("Name"); @@ -501,8 +512,10 @@ public virtual void AlterColumnOperation_with_index() Sql); } - [ConditionalFact] - public virtual void AlterColumnOperation_with_index_included_column() + [ConditionalTheory] + [InlineData(false)] + [InlineData(true)] + public virtual void AlterColumnOperation_with_index_included_column(bool obsolete) { Generate( modelBuilder => modelBuilder @@ -514,8 +527,17 @@ public virtual void AlterColumnOperation_with_index_included_column() x.Property("FirstName"); x.Property("LastName"); x.HasKey("Name"); - x.HasIndex("FirstName", "LastName") - .ForSqlServerInclude("Name"); + + if (obsolete) + { +#pragma warning disable 618 + x.HasIndex("FirstName", "LastName").ForSqlServerInclude("Name"); +#pragma warning restore 618 + } + else + { + x.HasIndex("FirstName", "LastName").IncludeProperties("Name"); + } }), new AlterColumnOperation { @@ -707,8 +729,10 @@ public virtual void AlterColumnOperation_with_added_index() Sql); } - [ConditionalFact] - public virtual void AlterColumnOperation_with_added_online_index() + [ConditionalTheory] + [InlineData(false)] + [InlineData(true)] + public virtual void AlterColumnOperation_with_added_online_index(bool obsolete) { Generate( modelBuilder => modelBuilder @@ -717,7 +741,17 @@ public virtual void AlterColumnOperation_with_added_online_index() "Person", x => { x.Property("Name").HasMaxLength(30); - x.HasIndex("Name").ForSqlServerIsCreatedOnline(); + + if (obsolete) + { +#pragma warning disable 618 + x.HasIndex("Name").ForSqlServerIsCreatedOnline(); +#pragma warning restore 618 + } + else + { + x.HasIndex("Name").IsCreatedOnline(); + } }), new AlterColumnOperation { @@ -850,7 +884,7 @@ public void AlterColumnOperation_with_new_comment() + EOL + "WHERE ([d].[parent_object_id] = OBJECT_ID(N'[dbo].[People]') AND [c].[name] = N'LuckyNumber');" + EOL + "IF @var0 IS NOT NULL EXEC(N'ALTER TABLE [dbo].[People] DROP CONSTRAINT [' + @var0 + '];');" + EOL + - "ALTER TABLE [dbo].[People] ALTER COLUMN [LuckyNumber] int NOT NULL;" + EOL + + "ALTER TABLE [dbo].[People] ALTER COLUMN [LuckyNumber] int NOT NULL;" + EOL + "GO" + EOL + EOL + "EXEC sp_addextendedproperty @name = N'Comment', @value = N'My Comment', @level0type = N'Schema', @level0name = N'dbo', @level1type = N'Table', @level1name = N'People', @level2type = N'Column', @level2name = N'LuckyNumber'", Sql); @@ -1287,13 +1321,24 @@ public virtual void CreateIndexOperation_unique_bound_not_null() Sql); } - [ConditionalFact] - public virtual void CreateIndexOperation_memoryOptimized_unique_nullable() + [ConditionalTheory] + [InlineData(false)] + [InlineData(true)] + public virtual void CreateIndexOperation_memoryOptimized_unique_nullable(bool obsolete) { Generate( modelBuilder => modelBuilder.Entity("People", x => { - x.ToTable("People", "dbo").ForSqlServerIsMemoryOptimized().Property("Name"); + if (obsolete) + { +#pragma warning disable 618 + x.ToTable("People", "dbo").ForSqlServerIsMemoryOptimized().Property("Name"); +#pragma warning restore 618 + } + else + { + x.ToTable("People", "dbo").IsMemoryOptimized().Property("Name"); + } x.Property("Id"); x.HasKey("Id"); }), @@ -1311,13 +1356,24 @@ public virtual void CreateIndexOperation_memoryOptimized_unique_nullable() Sql); } - [ConditionalFact] - public virtual void CreateIndexOperation_memoryOptimized_unique_nullable_with_filter() + [ConditionalTheory] + [InlineData(false)] + [InlineData(true)] + public virtual void CreateIndexOperation_memoryOptimized_unique_nullable_with_filter(bool obsolete) { Generate( modelBuilder => modelBuilder.Entity("People", x => { - x.ForSqlServerIsMemoryOptimized().Property("Name"); + if (obsolete) + { +#pragma warning disable 618 + x.ForSqlServerIsMemoryOptimized().Property("Name"); +#pragma warning restore 618 + } + else + { + x.IsMemoryOptimized().Property("Name"); + } x.Property("Id"); x.HasKey("Id"); }), @@ -1335,13 +1391,24 @@ public virtual void CreateIndexOperation_memoryOptimized_unique_nullable_with_fi Sql); } - [ConditionalFact] - public virtual void CreateIndexOperation_memoryOptimized_unique_nonclustered_not_nullable() + [ConditionalTheory] + [InlineData(false)] + [InlineData(true)] + public virtual void CreateIndexOperation_memoryOptimized_unique_nonclustered_not_nullable(bool obsolete) { Generate( modelBuilder => modelBuilder.Entity("People", x => { - x.ForSqlServerIsMemoryOptimized().Property("Name").IsRequired(); + if (obsolete) + { +#pragma warning disable 618 + x.ForSqlServerIsMemoryOptimized().Property("Name").IsRequired(); +#pragma warning restore 618 + } + else + { + x.IsMemoryOptimized().Property("Name").IsRequired(); + } x.HasKey("Name"); }), new CreateIndexOperation @@ -1431,13 +1498,24 @@ public override void DropIndexOperation() Sql); } - [ConditionalFact] - public virtual void DropIndexOperation_memoryOptimized() + [ConditionalTheory] + [InlineData(false)] + [InlineData(true)] + public virtual void DropIndexOperation_memoryOptimized(bool obsolete) { Generate( modelBuilder => modelBuilder.Entity("People", x => { - x.ForSqlServerIsMemoryOptimized(); + if (obsolete) + { +#pragma warning disable 618 + x.ForSqlServerIsMemoryOptimized(); +#pragma warning restore 618 + } + else + { + x.IsMemoryOptimized(); + } x.Property("Id"); x.HasKey("Id"); }), diff --git a/test/EFCore.SqlServer.FunctionalTests/SqlServerValueGenerationScenariosTest.cs b/test/EFCore.SqlServer.FunctionalTests/SqlServerValueGenerationScenariosTest.cs index b271739eee6..97c22d58b81 100644 --- a/test/EFCore.SqlServer.FunctionalTests/SqlServerValueGenerationScenariosTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/SqlServerValueGenerationScenariosTest.cs @@ -103,7 +103,7 @@ public BlogContextHiLo(string databaseName) protected override void OnModelCreating(ModelBuilder modelBuilder) { - modelBuilder.ForSqlServerUseSequenceHiLo(); + modelBuilder.UseHiLo(); modelBuilder.Entity( eb => diff --git a/test/EFCore.SqlServer.FunctionalTests/StoreGeneratedSqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/StoreGeneratedSqlServerTest.cs index a8de323c94f..f071d61db40 100644 --- a/test/EFCore.SqlServer.FunctionalTests/StoreGeneratedSqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/StoreGeneratedSqlServerTest.cs @@ -113,7 +113,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder, DbContext con modelBuilder.Entity( b => { - b.Property(e => e.Id).ForSqlServerUseIdentityColumn(); + b.Property(e => e.Id).UseIdentityColumn(); b.Property(e => e.Identity).HasDefaultValue("Banana Joe"); b.Property(e => e.IdentityReadOnlyBeforeSave).HasDefaultValue("Doughnut Sheriff"); b.Property(e => e.IdentityReadOnlyAfterSave).HasDefaultValue("Anton"); diff --git a/test/EFCore.SqlServer.Tests/Design/Internal/SqlServerAnnotationCodeGeneratorTest.cs b/test/EFCore.SqlServer.Tests/Design/Internal/SqlServerAnnotationCodeGeneratorTest.cs index 955806ded13..c1f84d2dc4e 100644 --- a/test/EFCore.SqlServer.Tests/Design/Internal/SqlServerAnnotationCodeGeneratorTest.cs +++ b/test/EFCore.SqlServer.Tests/Design/Internal/SqlServerAnnotationCodeGeneratorTest.cs @@ -11,8 +11,10 @@ namespace Microsoft.EntityFrameworkCore.Design.Internal { public class SqlServerAnnotationCodeGeneratorTest { - [ConditionalFact] - public void GenerateFluentApi_IKey_works_when_clustered() + [ConditionalTheory] + [InlineData(false)] + [InlineData(true)] + public void GenerateFluentApi_IKey_works_when_clustered(bool obsolete) { var generator = new SqlServerAnnotationCodeGenerator(new AnnotationCodeGeneratorDependencies()); var modelBuilder = new ModelBuilder(SqlServerConventionSetBuilder.Build()); @@ -21,20 +23,32 @@ public void GenerateFluentApi_IKey_works_when_clustered() x => { x.Property("Id"); - x.HasKey("Id").ForSqlServerIsClustered(); + + if (obsolete) + { +#pragma warning disable 618 + x.HasKey("Id").ForSqlServerIsClustered(); +#pragma warning restore 618 + } + else + { + x.HasKey("Id").IsClustered(); + } }); var key = modelBuilder.Model.FindEntityType("Post").GetKeys().Single(); var annotation = key.FindAnnotation(SqlServerAnnotationNames.Clustered); var result = generator.GenerateFluentApi(key, annotation); - Assert.Equal("ForSqlServerIsClustered", result.Method); + Assert.Equal("IsClustered", result.Method); Assert.Equal(0, result.Arguments.Count); } - [ConditionalFact] - public void GenerateFluentApi_IKey_works_when_nonclustered() + [ConditionalTheory] + [InlineData(false)] + [InlineData(true)] + public void GenerateFluentApi_IKey_works_when_nonclustered(bool obsolete) { var generator = new SqlServerAnnotationCodeGenerator(new AnnotationCodeGeneratorDependencies()); var modelBuilder = new ModelBuilder(SqlServerConventionSetBuilder.Build()); @@ -43,21 +57,33 @@ public void GenerateFluentApi_IKey_works_when_nonclustered() x => { x.Property("Id"); - x.HasKey("Id").ForSqlServerIsClustered(false); + + if (obsolete) + { +#pragma warning disable 618 + x.HasKey("Id").ForSqlServerIsClustered(false); +#pragma warning restore 618 + } + else + { + x.HasKey("Id").IsClustered(false); + } }); var key = modelBuilder.Model.FindEntityType("Post").GetKeys().Single(); var annotation = key.FindAnnotation(SqlServerAnnotationNames.Clustered); var result = generator.GenerateFluentApi(key, annotation); - Assert.Equal("ForSqlServerIsClustered", result.Method); + Assert.Equal("IsClustered", result.Method); Assert.Equal(1, result.Arguments.Count); Assert.Equal(false, result.Arguments[0]); } - [ConditionalFact] - public void GenerateFluentApi_IIndex_works_when_clustered() + [ConditionalTheory] + [InlineData(false)] + [InlineData(true)] + public void GenerateFluentApi_IIndex_works_when_clustered(bool obsolete) { var generator = new SqlServerAnnotationCodeGenerator(new AnnotationCodeGeneratorDependencies()); var modelBuilder = new ModelBuilder(SqlServerConventionSetBuilder.Build()); @@ -67,20 +93,31 @@ public void GenerateFluentApi_IIndex_works_when_clustered() { x.Property("Id"); x.Property("Name"); - x.HasIndex("Name").ForSqlServerIsClustered(); + if (obsolete) + { +#pragma warning disable 618 + x.HasIndex("Name").ForSqlServerIsClustered(); +#pragma warning restore 618 + } + else + { + x.HasIndex("Name").IsClustered(); + } }); var index = modelBuilder.Model.FindEntityType("Post").GetIndexes().Single(); var annotation = index.FindAnnotation(SqlServerAnnotationNames.Clustered); var result = generator.GenerateFluentApi(index, annotation); - Assert.Equal("ForSqlServerIsClustered", result.Method); + Assert.Equal("IsClustered", result.Method); Assert.Equal(0, result.Arguments.Count); } - [ConditionalFact] - public void GenerateFluentApi_IIndex_works_when_nonclustered() + [ConditionalTheory] + [InlineData(false)] + [InlineData(true)] + public void GenerateFluentApi_IIndex_works_when_nonclustered(bool obsolete) { var generator = new SqlServerAnnotationCodeGenerator(new AnnotationCodeGeneratorDependencies()); var modelBuilder = new ModelBuilder(SqlServerConventionSetBuilder.Build()); @@ -90,21 +127,32 @@ public void GenerateFluentApi_IIndex_works_when_nonclustered() { x.Property("Id"); x.Property("Name"); - x.HasIndex("Name").ForSqlServerIsClustered(false); + if (obsolete) + { +#pragma warning disable 618 + x.HasIndex("Name").ForSqlServerIsClustered(false); +#pragma warning restore 618 + } + else + { + x.HasIndex("Name").IsClustered(false); + } }); var index = modelBuilder.Model.FindEntityType("Post").GetIndexes().Single(); var annotation = index.FindAnnotation(SqlServerAnnotationNames.Clustered); var result = generator.GenerateFluentApi(index, annotation); - Assert.Equal("ForSqlServerIsClustered", result.Method); + Assert.Equal("IsClustered", result.Method); Assert.Equal(1, result.Arguments.Count); Assert.Equal(false, result.Arguments[0]); } - [ConditionalFact] - public void GenerateFluentApi_IIndex_works_with_includes() + [ConditionalTheory] + [InlineData(false)] + [InlineData(true)] + public void GenerateFluentApi_IIndex_works_with_includes(bool obsolete) { var generator = new SqlServerAnnotationCodeGenerator(new AnnotationCodeGeneratorDependencies()); var modelBuilder = new ModelBuilder(SqlServerConventionSetBuilder.Build()); @@ -115,14 +163,23 @@ public void GenerateFluentApi_IIndex_works_with_includes() x.Property("Id"); x.Property("FirstName"); x.Property("LastName"); - x.HasIndex("LastName").ForSqlServerInclude("FirstName"); + if (obsolete) + { +#pragma warning disable 618 + x.HasIndex("LastName").ForSqlServerInclude("FirstName"); +#pragma warning restore 618 + } + else + { + x.HasIndex("LastName").IncludeProperties("FirstName"); + } }); var index = modelBuilder.Model.FindEntityType("Post").GetIndexes().Single(); var annotation = index.FindAnnotation(SqlServerAnnotationNames.Include); var result = generator.GenerateFluentApi(index, annotation); - Assert.Equal("ForSqlServerInclude", result.Method); + Assert.Equal("IncludeProperties", result.Method); Assert.Equal(1, result.Arguments.Count); var properties = Assert.IsType(result.Arguments[0]); diff --git a/test/EFCore.SqlServer.Tests/Infrastructure/SqlServerModelValidatorTest.cs b/test/EFCore.SqlServer.Tests/Infrastructure/SqlServerModelValidatorTest.cs index 3ddfd2f976d..e8d5c8ea3a2 100644 --- a/test/EFCore.SqlServer.Tests/Infrastructure/SqlServerModelValidatorTest.cs +++ b/test/EFCore.SqlServer.Tests/Infrastructure/SqlServerModelValidatorTest.cs @@ -4,7 +4,6 @@ using System; using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Metadata.Internal; using Microsoft.EntityFrameworkCore.SqlServer.Diagnostics.Internal; using Microsoft.EntityFrameworkCore.SqlServer.Internal; using Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal; @@ -88,15 +87,26 @@ public virtual void Detects_duplicate_column_names_within_hierarchy_with_differe "nvarchar(max)"), modelBuilder.Model); } - [ConditionalFact] - public virtual void Detects_duplicate_column_names_within_hierarchy_with_different_value_generation_strategy() + [ConditionalTheory] + [InlineData(false)] + [InlineData(true)] + public virtual void Detects_duplicate_column_names_within_hierarchy_with_different_value_generation_strategy(bool obsolete) { var modelBuilder = CreateConventionalModelBuilder(); modelBuilder.Entity(); modelBuilder.Entity( cb => { - cb.Property(c => c.Identity).ForSqlServerUseIdentityColumn(); + if (obsolete) + { +#pragma warning disable 618 + cb.Property(c => c.Identity).UseSqlServerIdentityColumn(); +#pragma warning restore 618 + } + else + { + cb.Property(c => c.Identity).UseIdentityColumn(); + } cb.Property(c => c.Identity).HasColumnName(nameof(Cat.Identity)); }); modelBuilder.Entity( @@ -142,13 +152,25 @@ public virtual void Passes_for_incompatible_indexes_within_hierarchy_when_one_na Assert.Equal("IX_Animal_Name1", index2.GetName()); } - [ConditionalFact] - public virtual void Detects_incompatible_memory_optimized_shared_table() + [ConditionalTheory] + [InlineData(false)] + [InlineData(true)] + public virtual void Detects_incompatible_memory_optimized_shared_table(bool obsolete) { var modelBuilder = CreateConventionalModelBuilder(); modelBuilder.Entity().HasOne().WithOne().IsRequired().HasForeignKey(a => a.Id).HasPrincipalKey(b => b.Id); - modelBuilder.Entity().ToTable("Table").ForSqlServerIsMemoryOptimized(); + + if (obsolete) + { +#pragma warning disable 618 + modelBuilder.Entity().ToTable("Table").ForSqlServerIsMemoryOptimized(); +#pragma warning restore 618 + } + else + { + modelBuilder.Entity().ToTable("Table").IsMemoryOptimized(); + } modelBuilder.Entity().ToTable("Table"); VerifyError( @@ -156,16 +178,31 @@ public virtual void Detects_incompatible_memory_optimized_shared_table() modelBuilder.Model); } - [ConditionalFact] - public virtual void Detects_incompatible_non_clustered_shared_key() + [ConditionalTheory] + [InlineData(false)] + [InlineData(true)] + public virtual void Detects_incompatible_non_clustered_shared_key(bool obsolete) { var modelBuilder = CreateConventionalModelBuilder(); modelBuilder.Entity().HasOne().WithOne().IsRequired().HasForeignKey(a => a.Id).HasPrincipalKey(b => b.Id); - modelBuilder.Entity().ToTable("Table") - .HasKey(a => a.Id).ForSqlServerIsClustered(); - modelBuilder.Entity().ToTable("Table") - .HasKey(b => b.Id).ForSqlServerIsClustered(false); + + if (obsolete) + { +#pragma warning disable 618 + modelBuilder.Entity().ToTable("Table") + .HasKey(a => a.Id).ForSqlServerIsClustered(); + modelBuilder.Entity().ToTable("Table") + .HasKey(b => b.Id).ForSqlServerIsClustered(false); +#pragma warning restore 618 + } + else + { + modelBuilder.Entity().ToTable("Table") + .HasKey(a => a.Id).IsClustered(); + modelBuilder.Entity().ToTable("Table") + .HasKey(b => b.Id).IsClustered(false); + } VerifyError( SqlServerStrings.DuplicateKeyMismatchedClustering("{'Id'}", nameof(B), "{'Id'}", nameof(A), "Table", "PK_Table"), @@ -190,72 +227,158 @@ public virtual void Detects_default_nullable_decimal_mapping() VerifyWarning(SqlServerResources.LogDefaultDecimalTypeColumn(new TestLogger()).GenerateMessage("Price", nameof(Animal)), modelBuilder.Model); } - [ConditionalFact] - public void Detects_byte_identity_column() + [ConditionalTheory] + [InlineData(false)] + [InlineData(true)] + public void Detects_byte_identity_column(bool obsolete) { var modelBuilder = CreateConventionalModelBuilder(); modelBuilder.Entity().Property(d => d.Id).ValueGeneratedNever(); - modelBuilder.Entity().Property("Bite").ForSqlServerUseIdentityColumn(); + + if (obsolete) + { +#pragma warning disable 618 + modelBuilder.Entity().Property("Bite").UseSqlServerIdentityColumn(); +#pragma warning restore 618 + } + else + { + modelBuilder.Entity().Property("Bite").UseIdentityColumn(); + } VerifyWarning(SqlServerResources.LogByteIdentityColumn(new TestLogger()).GenerateMessage("Bite", nameof(Dog)), modelBuilder.Model); } - [ConditionalFact] - public void Detects_nullable_byte_identity_column() + [ConditionalTheory] + [InlineData(false)] + [InlineData(true)] + public void Detects_nullable_byte_identity_column(bool obsolete) { var modelBuilder = CreateConventionalModelBuilder(); modelBuilder.Entity().Property(d => d.Id).ValueGeneratedNever(); - modelBuilder.Entity().Property("Bite").ForSqlServerUseIdentityColumn(); + + if (obsolete) + { +#pragma warning disable 618 + modelBuilder.Entity().Property("Bite").UseSqlServerIdentityColumn(); +#pragma warning restore 618 + } + else + { + modelBuilder.Entity().Property("Bite").UseIdentityColumn(); + } VerifyWarning(SqlServerResources.LogByteIdentityColumn(new TestLogger()).GenerateMessage("Bite", nameof(Dog)), modelBuilder.Model); } - [ConditionalFact] - public void Passes_for_non_key_identity() + [ConditionalTheory] + [InlineData(false)] + [InlineData(true)] + public void Passes_for_non_key_identity(bool obsolete) { var modelBuilder = CreateConventionalModelBuilder(); modelBuilder.Entity().Property(d => d.Id).ValueGeneratedNever(); - modelBuilder.Entity().Property(c => c.Type).ForSqlServerUseIdentityColumn(); + + if (obsolete) + { +#pragma warning disable 618 + modelBuilder.Entity().Property(c => c.Type).UseSqlServerIdentityColumn(); +#pragma warning restore 618 + } + else + { + modelBuilder.Entity().Property(c => c.Type).UseIdentityColumn(); + } Validate(modelBuilder.Model); } - [ConditionalFact] - public void Detects_multiple_identity_properties() + [ConditionalTheory] + [InlineData(false)] + [InlineData(true)] + public void Detects_multiple_identity_properties(bool obsolete) { var modelBuilder = CreateConventionalModelBuilder(); modelBuilder.Entity().Property(d => d.Id).ValueGeneratedNever(); - modelBuilder.Entity().Property(c => c.Type).ForSqlServerUseIdentityColumn(); - modelBuilder.Entity().Property("Tag").ForSqlServerUseIdentityColumn(); + + if (obsolete) + { +#pragma warning disable 618 + modelBuilder.Entity().Property(c => c.Type).UseSqlServerIdentityColumn(); + modelBuilder.Entity().Property("Tag").UseSqlServerIdentityColumn(); +#pragma warning restore 618 + } + else + { + modelBuilder.Entity().Property(c => c.Type).UseIdentityColumn(); + modelBuilder.Entity().Property("Tag").UseIdentityColumn(); + } VerifyError(SqlServerStrings.MultipleIdentityColumns("'Dog.Tag', 'Dog.Type'", nameof(Dog)), modelBuilder.Model); } - [ConditionalFact] - public void Detects_non_key_SequenceHiLo() + [ConditionalTheory] + [InlineData(false)] + [InlineData(true)] + public void Detects_non_key_SequenceHiLo(bool obsolete) { var modelBuilder = CreateConventionalModelBuilder(); - modelBuilder.Entity().Property(c => c.Type).ForSqlServerUseSequenceHiLo(); + + if (obsolete) + { +#pragma warning disable 618 + modelBuilder.Entity().Property(c => c.Type).ForSqlServerUseSequenceHiLo(); +#pragma warning restore 618 + } + else + { + modelBuilder.Entity().Property(c => c.Type).UseHiLo(); + } VerifyError(SqlServerStrings.NonKeyValueGeneration(nameof(Dog.Type), nameof(Dog)), modelBuilder.Model); } - [ConditionalFact] - public void Passes_for_non_key_identity_on_model() + [ConditionalTheory] + [InlineData(false)] + [InlineData(true)] + public void Passes_for_non_key_identity_on_model(bool obsolete) { var modelBuilder = CreateConventionalModelBuilder(); - modelBuilder.ForSqlServerUseIdentityColumns(); + + if (obsolete) + { +#pragma warning disable 618 + modelBuilder.ForSqlServerUseIdentityColumns(); +#pragma warning restore 618 + } + else + { + modelBuilder.UseIdentityColumns(); + } + modelBuilder.Entity().Property(c => c.Id).ValueGeneratedNever(); modelBuilder.Entity().Property(c => c.Type).ValueGeneratedOnAdd(); Validate(modelBuilder.Model); } - [ConditionalFact] - public void Passes_for_non_key_SequenceHiLo_on_model() + [ConditionalTheory] + [InlineData(false)] + [InlineData(true)] + public void Passes_for_non_key_SequenceHiLo_on_model(bool obsolete) { var modelBuilder = CreateConventionalModelBuilder(); - modelBuilder.ForSqlServerUseSequenceHiLo(); + + if (obsolete) + { +#pragma warning disable 618 + modelBuilder.ForSqlServerUseSequenceHiLo(); +#pragma warning restore 618 + } + else + { + modelBuilder.UseHiLo(); + } modelBuilder.Entity().Property(c => c.Type).ValueGeneratedOnAdd(); Validate(modelBuilder.Model); @@ -301,42 +424,87 @@ protected virtual void ConfigureProperty(IMutableProperty property, string confi } } - [ConditionalFact] - public void Detects_missing_include_properties() + [ConditionalTheory] + [InlineData(false)] + [InlineData(true)] + public void Detects_missing_include_properties(bool obsolete) { var modelBuilder = CreateConventionalModelBuilder(); modelBuilder.Entity().Property(c => c.Type); - modelBuilder.Entity().HasIndex(nameof(Dog.Name)).ForSqlServerInclude(nameof(Dog.Type), "Tag"); + + if (obsolete) + { +#pragma warning disable 618 + modelBuilder.Entity().HasIndex(nameof(Dog.Name)).ForSqlServerInclude(nameof(Dog.Type), "Tag"); +#pragma warning restore 618 + } + else + { + modelBuilder.Entity().HasIndex(nameof(Dog.Name)).IncludeProperties(nameof(Dog.Type), "Tag"); + } VerifyError(SqlServerStrings.IncludePropertyNotFound(nameof(Dog), "Tag"), modelBuilder.Model); } - [ConditionalFact] - public void Detects_duplicate_include_properties() + [ConditionalTheory] + [InlineData(false)] + [InlineData(true)] + public void Detects_duplicate_include_properties(bool obsolete) { var modelBuilder = CreateConventionalModelBuilder(); modelBuilder.Entity().Property(c => c.Type); - modelBuilder.Entity().HasIndex(nameof(Dog.Name)).ForSqlServerInclude(nameof(Dog.Type), nameof(Dog.Type)); + if (obsolete) + { +#pragma warning disable 618 + modelBuilder.Entity().HasIndex(nameof(Dog.Name)).ForSqlServerInclude(nameof(Dog.Type), nameof(Dog.Type)); +#pragma warning restore 618 + } + else + { + modelBuilder.Entity().HasIndex(nameof(Dog.Name)).IncludeProperties(nameof(Dog.Type), nameof(Dog.Type)); + } VerifyError(SqlServerStrings.IncludePropertyDuplicated(nameof(Dog), nameof(Dog.Type)), modelBuilder.Model); } - [ConditionalFact] - public void Detects_indexed_include_properties() + [ConditionalTheory] + [InlineData(false)] + [InlineData(true)] + public void Detects_indexed_include_properties(bool obsolete) { var modelBuilder = CreateConventionalModelBuilder(); modelBuilder.Entity().Property(c => c.Type); - modelBuilder.Entity().HasIndex(nameof(Dog.Name)).ForSqlServerInclude(nameof(Dog.Name)); + if (obsolete) + { +#pragma warning disable 618 + modelBuilder.Entity().HasIndex(nameof(Dog.Name)).ForSqlServerInclude(nameof(Dog.Name)); +#pragma warning restore 618 + } + else + { + modelBuilder.Entity().HasIndex(nameof(Dog.Name)).IncludeProperties(nameof(Dog.Name)); + } VerifyError(SqlServerStrings.IncludePropertyInIndex(nameof(Dog), nameof(Dog.Name)), modelBuilder.Model); } - [ConditionalFact] - public void Passes_for_online_index() + [ConditionalTheory] + [InlineData(false)] + [InlineData(true)] + public void Passes_for_online_index(bool obsolete) { var modelBuilder = CreateConventionalModelBuilder(); modelBuilder.Entity().Property(c => c.Type); - modelBuilder.Entity().HasIndex(nameof(Dog.Name)).ForSqlServerIsCreatedOnline(); + if (obsolete) + { +#pragma warning disable 618 + modelBuilder.Entity().HasIndex(nameof(Dog.Name)).ForSqlServerIsCreatedOnline(); +#pragma warning restore 618 + } + else + { + modelBuilder.Entity().HasIndex(nameof(Dog.Name)).IsCreatedOnline(); + } Validate(modelBuilder.Model); } diff --git a/test/EFCore.SqlServer.Tests/Metadata/Conventions/SqlServerMemoryOptimizedTablesConventionTest.cs b/test/EFCore.SqlServer.Tests/Metadata/Conventions/SqlServerMemoryOptimizedTablesConventionTest.cs index 4ab8b4a8564..73784762c30 100644 --- a/test/EFCore.SqlServer.Tests/Metadata/Conventions/SqlServerMemoryOptimizedTablesConventionTest.cs +++ b/test/EFCore.SqlServer.Tests/Metadata/Conventions/SqlServerMemoryOptimizedTablesConventionTest.cs @@ -9,8 +9,10 @@ namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { public class SqlServerMemoryOptimizedTablesConventionTest { - [ConditionalFact] - public void Keys_and_indexes_are_nonclustered_for_memory_optimized_tables() + [ConditionalTheory] + [InlineData(false)] + [InlineData(true)] + public void Keys_and_indexes_are_nonclustered_for_memory_optimized_tables(bool obsolete) { var modelBuilder = SqlServerTestHelpers.Instance.CreateConventionBuilder(); @@ -19,7 +21,17 @@ public void Keys_and_indexes_are_nonclustered_for_memory_optimized_tables() Assert.True(modelBuilder.Model.FindEntityType(typeof(Order)).GetKeys().All(k => k.GetSqlServerIsClustered() == null)); Assert.True(modelBuilder.Model.FindEntityType(typeof(Order)).GetIndexes().All(k => k.GetSqlServerIsClustered() == null)); - modelBuilder.Entity().ForSqlServerIsMemoryOptimized(); + if (obsolete) + { +#pragma warning disable 618 + modelBuilder.Entity().ForSqlServerIsMemoryOptimized(); +#pragma warning restore 618 + } + else + { + modelBuilder.Entity().IsMemoryOptimized(); + } + modelBuilder.Entity().HasKey( o => new { @@ -31,7 +43,16 @@ public void Keys_and_indexes_are_nonclustered_for_memory_optimized_tables() Assert.True(modelBuilder.Model.FindEntityType(typeof(Order)).GetKeys().All(k => k.GetSqlServerIsClustered() == false)); Assert.True(modelBuilder.Model.FindEntityType(typeof(Order)).GetIndexes().All(k => k.GetSqlServerIsClustered() == false)); - modelBuilder.Entity().ForSqlServerIsMemoryOptimized(false); + if (obsolete) + { +#pragma warning disable 618 + modelBuilder.Entity().ForSqlServerIsMemoryOptimized(false); +#pragma warning restore 618 + } + else + { + modelBuilder.Entity().IsMemoryOptimized(false); + } Assert.True(modelBuilder.Model.FindEntityType(typeof(Order)).GetKeys().All(k => k.GetSqlServerIsClustered() == null)); Assert.True(modelBuilder.Model.FindEntityType(typeof(Order)).GetIndexes().All(k => k.GetSqlServerIsClustered() == null)); diff --git a/test/EFCore.SqlServer.Tests/Metadata/Conventions/SqlServerValueGenerationStrategyConventionTest.cs b/test/EFCore.SqlServer.Tests/Metadata/Conventions/SqlServerValueGenerationStrategyConventionTest.cs index 522c2171a01..54a57198ccb 100644 --- a/test/EFCore.SqlServer.Tests/Metadata/Conventions/SqlServerValueGenerationStrategyConventionTest.cs +++ b/test/EFCore.SqlServer.Tests/Metadata/Conventions/SqlServerValueGenerationStrategyConventionTest.cs @@ -29,7 +29,7 @@ public void Annotations_are_added_when_conventional_model_builder_is_used() public void Annotations_are_added_when_conventional_model_builder_is_used_with_sequences() { var model = SqlServerTestHelpers.Instance.CreateConventionBuilder() - .ForSqlServerUseSequenceHiLo() + .UseHiLo() .Model; model.RemoveAnnotation(CoreAnnotationNames.ProductVersion); diff --git a/test/EFCore.SqlServer.Tests/Metadata/SqlServerBuilderExtensionsTest.cs b/test/EFCore.SqlServer.Tests/Metadata/SqlServerBuilderExtensionsTest.cs index 993fb6d0d37..c74ba691d2e 100644 --- a/test/EFCore.SqlServer.Tests/Metadata/SqlServerBuilderExtensionsTest.cs +++ b/test/EFCore.SqlServer.Tests/Metadata/SqlServerBuilderExtensionsTest.cs @@ -63,85 +63,175 @@ public void Can_set_index_filter() Assert.Equal("SqlServer-specific expression", index.GetFilter()); } - [ConditionalFact] - public void Can_set_MemoryOptimized() + [ConditionalTheory] + [InlineData(false)] + [InlineData(true)] + public void Can_set_MemoryOptimized(bool obsolete) { var modelBuilder = CreateConventionModelBuilder(); - modelBuilder - .Entity() - .ForSqlServerIsMemoryOptimized(); + if (obsolete) + { +#pragma warning disable 618 + modelBuilder + .Entity() + .ForSqlServerIsMemoryOptimized(); +#pragma warning restore 618 + } + else + { + modelBuilder + .Entity() + .IsMemoryOptimized(); + } var entityType = modelBuilder.Model.FindEntityType(typeof(Customer)); Assert.True(entityType.GetSqlServerIsMemoryOptimized()); - modelBuilder - .Entity() - .ForSqlServerIsMemoryOptimized(false); + if (obsolete) + { +#pragma warning disable 618 + modelBuilder + .Entity() + .ForSqlServerIsMemoryOptimized(false); +#pragma warning restore 618 + } + else + { + modelBuilder + .Entity() + .IsMemoryOptimized(false); + } Assert.False(entityType.GetSqlServerIsMemoryOptimized()); } - [ConditionalFact] - public void Can_set_MemoryOptimized_non_generic() + [ConditionalTheory] + [InlineData(false)] + [InlineData(true)] + public void Can_set_MemoryOptimized_non_generic(bool obsolete) { var modelBuilder = CreateConventionModelBuilder(); - modelBuilder - .Entity(typeof(Customer)) - .ForSqlServerIsMemoryOptimized(); + if (obsolete) + { +#pragma warning disable 618 + modelBuilder + .Entity(typeof(Customer)) + .ForSqlServerIsMemoryOptimized(); +#pragma warning restore 618 + } + else + { + modelBuilder + .Entity(typeof(Customer)) + .IsMemoryOptimized(); + } var entityType = modelBuilder.Model.FindEntityType(typeof(Customer)); Assert.True(entityType.GetSqlServerIsMemoryOptimized()); - modelBuilder - .Entity(typeof(Customer)) - .ForSqlServerIsMemoryOptimized(false); + if (obsolete) + { +#pragma warning disable 618 + modelBuilder + .Entity(typeof(Customer)) + .ForSqlServerIsMemoryOptimized(false); +#pragma warning restore 618 + } + else + { + modelBuilder + .Entity(typeof(Customer)) + .IsMemoryOptimized(false); + } Assert.False(entityType.GetSqlServerIsMemoryOptimized()); } - [ConditionalFact] - public void Can_set_index_clustering() + [ConditionalTheory] + [InlineData(false)] + [InlineData(true)] + public void Can_set_index_clustering(bool obsolete) { var modelBuilder = CreateConventionModelBuilder(); - modelBuilder - .Entity() - .HasIndex(e => e.Id) - .ForSqlServerIsClustered(); + if (obsolete) + { +#pragma warning disable 618 + modelBuilder + .Entity() + .HasIndex(e => e.Id) + .ForSqlServerIsClustered(); +#pragma warning restore 618 + } + else + { + modelBuilder + .Entity() + .HasIndex(e => e.Id) + .IsClustered(); + } var index = modelBuilder.Model.FindEntityType(typeof(Customer)).GetIndexes().Single(); Assert.True(index.GetSqlServerIsClustered().Value); } - [ConditionalFact] - public void Can_set_key_clustering() + [ConditionalTheory] + [InlineData(false)] + [InlineData(true)] + public void Can_set_key_clustering(bool obsolete) { var modelBuilder = CreateConventionModelBuilder(); - modelBuilder - .Entity() - .HasKey(e => e.Id) - .ForSqlServerIsClustered(); + if (obsolete) + { +#pragma warning disable 618 + modelBuilder + .Entity() + .HasKey(e => e.Id) + .ForSqlServerIsClustered(); +#pragma warning restore 618 + } + else + { + modelBuilder + .Entity() + .HasKey(e => e.Id) + .IsClustered(); + } var key = modelBuilder.Model.FindEntityType(typeof(Customer)).FindPrimaryKey(); Assert.True(key.GetSqlServerIsClustered().Value); } - [ConditionalFact] - public void Can_set_index_include() + [ConditionalTheory] + [InlineData(false)] + [InlineData(true)] + public void Can_set_index_include(bool obsolete) { var modelBuilder = CreateConventionModelBuilder(); - modelBuilder - .Entity() - .HasIndex(e => e.Name) - .ForSqlServerInclude(e => e.Offset); + if (obsolete) + { +#pragma warning disable 618 + modelBuilder + .Entity() + .HasIndex(e => e.Name) + .ForSqlServerInclude(e => e.Offset); +#pragma warning restore 618 + } + else + { + modelBuilder + .Entity() + .HasIndex(e => e.Name) + .IncludeProperties(e => e.Offset); + } var index = modelBuilder.Model.FindEntityType(typeof(Customer)).GetIndexes().Single(); @@ -151,16 +241,31 @@ public void Can_set_index_include() c => Assert.Equal(nameof(Customer.Offset), c)); } - [ConditionalFact] - public void Can_set_index_include_after_unique_using_generic_builder() + [ConditionalTheory] + [InlineData(false)] + [InlineData(true)] + public void Can_set_index_include_after_unique_using_generic_builder(bool obsolete) { var modelBuilder = CreateConventionModelBuilder(); - modelBuilder - .Entity() - .HasIndex(e => e.Name) - .IsUnique() - .ForSqlServerInclude(e => e.Offset); + if (obsolete) + { +#pragma warning disable 618 + modelBuilder + .Entity() + .HasIndex(e => e.Name) + .IsUnique() + .ForSqlServerInclude(e => e.Offset); +#pragma warning restore 618 + } + else + { + modelBuilder + .Entity() + .HasIndex(e => e.Name) + .IsUnique() + .IncludeProperties(e => e.Offset); + } var index = modelBuilder.Model.FindEntityType(typeof(Customer)).GetIndexes().Single(); @@ -171,16 +276,31 @@ public void Can_set_index_include_after_unique_using_generic_builder() c => Assert.Equal(nameof(Customer.Offset), c)); } - [ConditionalFact] - public void Can_set_index_include_after_annotation_using_generic_builder() + [ConditionalTheory] + [InlineData(false)] + [InlineData(true)] + public void Can_set_index_include_after_annotation_using_generic_builder(bool obsolete) { var modelBuilder = CreateConventionModelBuilder(); - modelBuilder - .Entity() - .HasIndex(e => e.Name) - .HasAnnotation("Test:ShouldBeTrue", true) - .ForSqlServerInclude(e => e.Offset); + if (obsolete) + { +#pragma warning disable 618 + modelBuilder + .Entity() + .HasIndex(e => e.Name) + .HasAnnotation("Test:ShouldBeTrue", true) + .ForSqlServerInclude(e => e.Offset); +#pragma warning restore 618 + } + else + { + modelBuilder + .Entity() + .HasIndex(e => e.Name) + .HasAnnotation("Test:ShouldBeTrue", true) + .IncludeProperties(e => e.Offset); + } var index = modelBuilder.Model.FindEntityType(typeof(Customer)).GetIndexes().Single(); @@ -195,15 +315,29 @@ public void Can_set_index_include_after_annotation_using_generic_builder() c => Assert.Equal(nameof(Customer.Offset), c)); } - [ConditionalFact] - public void Can_set_index_include_non_generic() + [ConditionalTheory] + [InlineData(false)] + [InlineData(true)] + public void Can_set_index_include_non_generic(bool obsolete) { var modelBuilder = CreateConventionModelBuilder(); - modelBuilder - .Entity() - .HasIndex(e => e.Name) - .ForSqlServerInclude(nameof(Customer.Offset)); + if (obsolete) + { +#pragma warning disable 618 + modelBuilder + .Entity() + .HasIndex(e => e.Name) + .ForSqlServerInclude(nameof(Customer.Offset)); +#pragma warning restore 618 + } + else + { + modelBuilder + .Entity() + .HasIndex(e => e.Name) + .IncludeProperties(nameof(Customer.Offset)); + } var index = modelBuilder.Model.FindEntityType(typeof(Customer)).GetIndexes().Single(); @@ -213,42 +347,81 @@ public void Can_set_index_include_non_generic() c => Assert.Equal(nameof(Customer.Offset), c)); } - [ConditionalFact] - public void Can_set_index_online() + [ConditionalTheory] + [InlineData(false)] + [InlineData(true)] + public void Can_set_index_online(bool obsolete) { var modelBuilder = CreateConventionModelBuilder(); - modelBuilder - .Entity() - .HasIndex(e => e.Name) - .ForSqlServerIsCreatedOnline(); + if (obsolete) + { +#pragma warning disable 618 + modelBuilder + .Entity() + .HasIndex(e => e.Name) + .ForSqlServerIsCreatedOnline(); +#pragma warning restore 618 + } + else + { + modelBuilder + .Entity() + .HasIndex(e => e.Name) + .IsCreatedOnline(); + } var index = modelBuilder.Model.FindEntityType(typeof(Customer)).GetIndexes().Single(); Assert.True(index.GetSqlServerIsCreatedOnline()); } - [ConditionalFact] - public void Can_set_index_online_non_generic() + [ConditionalTheory] + [InlineData(false)] + [InlineData(true)] + public void Can_set_index_online_non_generic(bool obsolete) { var modelBuilder = CreateConventionModelBuilder(); - modelBuilder - .Entity() - .HasIndex(e => e.Name) - .ForSqlServerIsCreatedOnline(); + if (obsolete) + { +#pragma warning disable 618 + modelBuilder + .Entity() + .HasIndex(e => e.Name) + .ForSqlServerIsCreatedOnline(); +#pragma warning restore 618 + } + else + { + modelBuilder + .Entity() + .HasIndex(e => e.Name) + .IsCreatedOnline(); + } var index = modelBuilder.Model.FindEntityType(typeof(Customer)).GetIndexes().Single(); Assert.True(index.GetSqlServerIsCreatedOnline()); } - [ConditionalFact] - public void Can_set_sequences_for_model() + [ConditionalTheory] + [InlineData(false)] + [InlineData(true)] + public void Can_set_sequences_for_model(bool obsolete) { var modelBuilder = CreateConventionModelBuilder(); - modelBuilder.ForSqlServerUseSequenceHiLo(); + if (obsolete) + { +#pragma warning disable 618 + modelBuilder.ForSqlServerUseSequenceHiLo(); +#pragma warning restore 618 + } + else + { + modelBuilder.UseHiLo(); + } var relationalExtensions = modelBuilder.Model; var sqlServerExtensions = modelBuilder.Model; @@ -261,12 +434,23 @@ public void Can_set_sequences_for_model() Assert.NotNull(sqlServerExtensions.FindSequence(SqlServerModelExtensions.DefaultHiLoSequenceName)); } - [ConditionalFact] - public void Can_set_sequences_with_name_for_model() + [ConditionalTheory] + [InlineData(false)] + [InlineData(true)] + public void Can_set_sequences_with_name_for_model(bool obsolete) { var modelBuilder = CreateConventionModelBuilder(); - modelBuilder.ForSqlServerUseSequenceHiLo("Snook"); + if (obsolete) + { +#pragma warning disable 618 + modelBuilder.ForSqlServerUseSequenceHiLo("Snook"); +#pragma warning restore 618 + } + else + { + modelBuilder.UseHiLo("Snook"); + } var relationalExtensions = modelBuilder.Model; var sqlServerExtensions = modelBuilder.Model; @@ -288,12 +472,23 @@ public void Can_set_sequences_with_name_for_model() Assert.Same(typeof(long), sequence.ClrType); } - [ConditionalFact] - public void Can_set_sequences_with_schema_and_name_for_model() + [ConditionalTheory] + [InlineData(false)] + [InlineData(true)] + public void Can_set_sequences_with_schema_and_name_for_model(bool obsolete) { var modelBuilder = CreateConventionModelBuilder(); - modelBuilder.ForSqlServerUseSequenceHiLo("Snook", "Tasty"); + if (obsolete) + { +#pragma warning disable 618 + modelBuilder.ForSqlServerUseSequenceHiLo("Snook", "Tasty"); +#pragma warning restore 618 + } + else + { + modelBuilder.UseHiLo("Snook", "Tasty"); + } var relationalExtensions = modelBuilder.Model; var sqlServerExtensions = modelBuilder.Model; @@ -314,8 +509,10 @@ public void Can_set_sequences_with_schema_and_name_for_model() Assert.Same(typeof(long), sequence.ClrType); } - [ConditionalFact] - public void Can_set_use_of_existing_relational_sequence_for_model() + [ConditionalTheory] + [InlineData(false)] + [InlineData(true)] + public void Can_set_use_of_existing_relational_sequence_for_model(bool obsolete) { var modelBuilder = CreateConventionModelBuilder(); @@ -326,7 +523,16 @@ public void Can_set_use_of_existing_relational_sequence_for_model() .HasMin(111) .HasMax(2222); - modelBuilder.ForSqlServerUseSequenceHiLo("Snook", "Tasty"); + if (obsolete) + { +#pragma warning disable 618 + modelBuilder.ForSqlServerUseSequenceHiLo("Snook", "Tasty"); +#pragma warning restore 618 + } + else + { + modelBuilder.UseHiLo("Snook", "Tasty"); + } var relationalExtensions = modelBuilder.Model; var sqlServerExtensions = modelBuilder.Model; @@ -339,8 +545,10 @@ public void Can_set_use_of_existing_relational_sequence_for_model() ValidateSchemaNamedSpecificSequence(sqlServerExtensions.FindSequence("Snook", "Tasty")); } - [ConditionalFact] - public void Can_set_use_of_existing_SQL_sequence_for_model() + [ConditionalTheory] + [InlineData(false)] + [InlineData(true)] + public void Can_set_use_of_existing_SQL_sequence_for_model(bool obsolete) { var modelBuilder = CreateConventionModelBuilder(); @@ -351,7 +559,16 @@ public void Can_set_use_of_existing_SQL_sequence_for_model() .HasMin(111) .HasMax(2222); - modelBuilder.ForSqlServerUseSequenceHiLo("Snook", "Tasty"); + if (obsolete) + { +#pragma warning disable 618 + modelBuilder.ForSqlServerUseSequenceHiLo("Snook", "Tasty"); +#pragma warning restore 618 + } + else + { + modelBuilder.UseHiLo("Snook", "Tasty"); + } var relationalExtensions = modelBuilder.Model; var sqlServerExtensions = modelBuilder.Model; @@ -375,12 +592,23 @@ private static void ValidateSchemaNamedSpecificSequence(ISequence sequence) Assert.Same(typeof(int), sequence.ClrType); } - [ConditionalFact] - public void Can_set_identities_for_model() + [ConditionalTheory] + [InlineData(false)] + [InlineData(true)] + public void Can_set_identities_for_model(bool obsolete) { var modelBuilder = CreateConventionModelBuilder(); - modelBuilder.ForSqlServerUseIdentityColumns(); + if (obsolete) + { +#pragma warning disable 618 + modelBuilder.ForSqlServerUseIdentityColumns(); +#pragma warning restore 618 + } + else + { + modelBuilder.UseIdentityColumns(); + } var model = modelBuilder.Model; @@ -391,8 +619,10 @@ public void Can_set_identities_for_model() Assert.Null(model.FindSequence(SqlServerModelExtensions.DefaultHiLoSequenceName)); } - [ConditionalFact] - public void Setting_SqlServer_identities_for_model_is_lower_priority_than_relational_default_values() + [ConditionalTheory] + [InlineData(false)] + [InlineData(true)] + public void Setting_SqlServer_identities_for_model_is_lower_priority_than_relational_default_values(bool obsolete) { var modelBuilder = CreateConventionModelBuilder(); @@ -405,7 +635,16 @@ public void Setting_SqlServer_identities_for_model_is_lower_priority_than_relati eb.Property(e => e.Offset).HasDefaultValueSql("Now"); }); - modelBuilder.ForSqlServerUseIdentityColumns(); + if (obsolete) + { +#pragma warning disable 618 + modelBuilder.ForSqlServerUseIdentityColumns(); +#pragma warning restore 618 + } + else + { + modelBuilder.UseIdentityColumns(); + } var model = modelBuilder.Model; var idProperty = model.FindEntityType(typeof(Customer)).FindProperty(nameof(Customer.Id)); @@ -427,15 +666,29 @@ public void Setting_SqlServer_identities_for_model_is_lower_priority_than_relati Assert.Equal("Now", offsetProperty.GetDefaultValueSql()); } - [ConditionalFact] - public void Can_set_sequence_for_property() + [ConditionalTheory] + [InlineData(false)] + [InlineData(true)] + public void Can_set_sequence_for_property(bool obsolete) { var modelBuilder = CreateConventionModelBuilder(); - modelBuilder - .Entity() - .Property(e => e.Id) - .ForSqlServerUseSequenceHiLo(); + if (obsolete) + { +#pragma warning disable 618 + modelBuilder + .Entity() + .Property(e => e.Id) + .ForSqlServerUseSequenceHiLo(); +#pragma warning restore 618 + } + else + { + modelBuilder + .Entity() + .Property(e => e.Id) + .UseHiLo(); + } var model = modelBuilder.Model; var property = model.FindEntityType(typeof(Customer)).FindProperty("Id"); @@ -448,15 +701,29 @@ public void Can_set_sequence_for_property() Assert.NotNull(model.FindSequence(SqlServerModelExtensions.DefaultHiLoSequenceName)); } - [ConditionalFact] - public void Can_set_sequences_with_name_for_property() + [ConditionalTheory] + [InlineData(false)] + [InlineData(true)] + public void Can_set_sequences_with_name_for_property(bool obsolete) { var modelBuilder = CreateConventionModelBuilder(); - modelBuilder - .Entity() - .Property(e => e.Id) - .ForSqlServerUseSequenceHiLo("Snook"); + if (obsolete) + { +#pragma warning disable 618 + modelBuilder + .Entity() + .Property(e => e.Id) + .ForSqlServerUseSequenceHiLo("Snook"); +#pragma warning restore 618 + } + else + { + modelBuilder + .Entity() + .Property(e => e.Id) + .UseHiLo("Snook"); + } var model = modelBuilder.Model; var property = model.FindEntityType(typeof(Customer)).FindProperty("Id"); @@ -479,15 +746,29 @@ public void Can_set_sequences_with_name_for_property() Assert.Same(typeof(long), sequence.ClrType); } - [ConditionalFact] - public void Can_set_sequences_with_schema_and_name_for_property() + [ConditionalTheory] + [InlineData(false)] + [InlineData(true)] + public void Can_set_sequences_with_schema_and_name_for_property(bool obsolete) { var modelBuilder = CreateConventionModelBuilder(); - modelBuilder - .Entity() - .Property(e => e.Id) - .ForSqlServerUseSequenceHiLo("Snook", "Tasty"); + if (obsolete) + { +#pragma warning disable 618 + modelBuilder + .Entity() + .Property(e => e.Id) + .ForSqlServerUseSequenceHiLo("Snook", "Tasty"); +#pragma warning restore 618 + } + else + { + modelBuilder + .Entity() + .Property(e => e.Id) + .UseHiLo("Snook", "Tasty"); + } var model = modelBuilder.Model; var property = model.FindEntityType(typeof(Customer)).FindProperty("Id"); @@ -509,8 +790,10 @@ public void Can_set_sequences_with_schema_and_name_for_property() Assert.Same(typeof(long), sequence.ClrType); } - [ConditionalFact] - public void Can_set_use_of_existing_relational_sequence_for_property() + [ConditionalTheory] + [InlineData(false)] + [InlineData(true)] + public void Can_set_use_of_existing_relational_sequence_for_property(bool obsolete) { var modelBuilder = CreateConventionModelBuilder(); @@ -521,10 +804,22 @@ public void Can_set_use_of_existing_relational_sequence_for_property() .HasMin(111) .HasMax(2222); - modelBuilder - .Entity() - .Property(e => e.Id) - .ForSqlServerUseSequenceHiLo("Snook", "Tasty"); + if (obsolete) + { +#pragma warning disable 618 + modelBuilder + .Entity() + .Property(e => e.Id) + .ForSqlServerUseSequenceHiLo("Snook", "Tasty"); +#pragma warning restore 618 + } + else + { + modelBuilder + .Entity() + .Property(e => e.Id) + .UseHiLo("Snook", "Tasty"); + } var model = modelBuilder.Model; var property = model.FindEntityType(typeof(Customer)).FindProperty("Id"); @@ -538,16 +833,31 @@ public void Can_set_use_of_existing_relational_sequence_for_property() ValidateSchemaNamedSpecificSequence(model.FindSequence("Snook", "Tasty")); } - [ConditionalFact] - public void Can_set_use_of_existing_relational_sequence_for_property_using_nested_closure() + [ConditionalTheory] + [InlineData(false)] + [InlineData(true)] + public void Can_set_use_of_existing_relational_sequence_for_property_using_nested_closure(bool obsolete) { var modelBuilder = CreateConventionModelBuilder(); - modelBuilder - .HasSequence("Snook", "Tasty", b => b.IncrementsBy(11).StartsAt(1729).HasMin(111).HasMax(2222)) - .Entity() - .Property(e => e.Id) - .ForSqlServerUseSequenceHiLo("Snook", "Tasty"); + if (obsolete) + { +#pragma warning disable 618 + modelBuilder + .HasSequence("Snook", "Tasty", b => b.IncrementsBy(11).StartsAt(1729).HasMin(111).HasMax(2222)) + .Entity() + .Property(e => e.Id) + .ForSqlServerUseSequenceHiLo("Snook", "Tasty"); +#pragma warning restore 618 + } + else + { + modelBuilder + .HasSequence("Snook", "Tasty", b => b.IncrementsBy(11).StartsAt(1729).HasMin(111).HasMax(2222)) + .Entity() + .Property(e => e.Id) + .UseHiLo("Snook", "Tasty"); + } var model = modelBuilder.Model; var property = model.FindEntityType(typeof(Customer)).FindProperty("Id"); @@ -561,8 +871,10 @@ public void Can_set_use_of_existing_relational_sequence_for_property_using_neste ValidateSchemaNamedSpecificSequence(model.FindSequence("Snook", "Tasty")); } - [ConditionalFact] - public void Can_set_use_of_existing_SQL_sequence_for_property() + [ConditionalTheory] + [InlineData(false)] + [InlineData(true)] + public void Can_set_use_of_existing_SQL_sequence_for_property(bool obsolete) { var modelBuilder = CreateConventionModelBuilder(); @@ -573,10 +885,22 @@ public void Can_set_use_of_existing_SQL_sequence_for_property() .HasMin(111) .HasMax(2222); - modelBuilder - .Entity() - .Property(e => e.Id) - .ForSqlServerUseSequenceHiLo("Snook", "Tasty"); + if (obsolete) + { +#pragma warning disable 618 + modelBuilder + .Entity() + .Property(e => e.Id) + .ForSqlServerUseSequenceHiLo("Snook", "Tasty"); +#pragma warning restore 618 + } + else + { + modelBuilder + .Entity() + .Property(e => e.Id) + .UseHiLo("Snook", "Tasty"); + } var model = modelBuilder.Model; var property = model.FindEntityType(typeof(Customer)).FindProperty("Id"); @@ -589,8 +913,10 @@ public void Can_set_use_of_existing_SQL_sequence_for_property() ValidateSchemaNamedSpecificSequence(model.FindSequence("Snook", "Tasty")); } - [ConditionalFact] - public void Can_set_use_of_existing_SQL_sequence_for_property_using_nested_closure() + [ConditionalTheory] + [InlineData(false)] + [InlineData(true)] + public void Can_set_use_of_existing_SQL_sequence_for_property_using_nested_closure(bool obsolete) { var modelBuilder = CreateConventionModelBuilder(); @@ -602,10 +928,24 @@ public void Can_set_use_of_existing_SQL_sequence_for_property_using_nested_closu .StartsAt(1729) .HasMin(111) .HasMax(2222); - }) - .Entity() - .Property(e => e.Id) - .ForSqlServerUseSequenceHiLo("Snook", "Tasty"); + }); + + if (obsolete) + { +#pragma warning disable 618 + modelBuilder + .Entity() + .Property(e => e.Id) + .ForSqlServerUseSequenceHiLo("Snook", "Tasty"); +#pragma warning restore 618 + } + else + { + modelBuilder + .Entity() + .Property(e => e.Id) + .UseHiLo("Snook", "Tasty"); + } var model = modelBuilder.Model; var property = model.FindEntityType(typeof(Customer)).FindProperty("Id"); @@ -618,15 +958,29 @@ public void Can_set_use_of_existing_SQL_sequence_for_property_using_nested_closu ValidateSchemaNamedSpecificSequence(model.FindSequence("Snook", "Tasty")); } - [ConditionalFact] - public void Can_set_identities_for_property() + [ConditionalTheory] + [InlineData(false)] + [InlineData(true)] + public void Can_set_identities_for_property(bool obsolete) { var modelBuilder = CreateConventionModelBuilder(); - modelBuilder - .Entity() - .Property(e => e.Id) - .ForSqlServerUseIdentityColumn(); + if (obsolete) + { +#pragma warning disable 618 + modelBuilder + .Entity() + .Property(e => e.Id) + .UseSqlServerIdentityColumn(); +#pragma warning restore 618 + } + else + { + modelBuilder + .Entity() + .Property(e => e.Id) + .UseIdentityColumn(); + } var model = modelBuilder.Model; var property = model.FindEntityType(typeof(Customer)).FindProperty("Id"); @@ -641,15 +995,29 @@ public void Can_set_identities_for_property() Assert.Null(model.FindSequence(SqlServerModelExtensions.DefaultHiLoSequenceName)); } - [ConditionalFact] - public void Can_set_identities_with_seed_and_identity_for_property() + [ConditionalTheory] + [InlineData(false)] + [InlineData(true)] + public void Can_set_identities_with_seed_and_identity_for_property(bool obsolete) { var modelBuilder = CreateConventionModelBuilder(); - modelBuilder - .Entity() - .Property(e => e.Id) - .ForSqlServerUseIdentityColumn(100, 5); + if (obsolete) + { +#pragma warning disable 618 + modelBuilder + .Entity() + .Property(e => e.Id) + .UseSqlServerIdentityColumn(100, 5); +#pragma warning restore 618 + } + else + { + modelBuilder + .Entity() + .Property(e => e.Id) + .UseIdentityColumn(100, 5); + } var model = modelBuilder.Model; var property = model.FindEntityType(typeof(Customer)).FindProperty("Id"); @@ -664,59 +1032,126 @@ public void Can_set_identities_with_seed_and_identity_for_property() Assert.Null(model.FindSequence(SqlServerModelExtensions.DefaultHiLoSequenceName)); } - [ConditionalFact] - public void SqlServer_entity_methods_dont_break_out_of_the_generics() + [ConditionalTheory] + [InlineData(false)] + [InlineData(true)] + public void SqlServer_entity_methods_dont_break_out_of_the_generics(bool obsolete) { var modelBuilder = CreateConventionModelBuilder(); - AssertIsGeneric( - modelBuilder - .Entity() - .ForSqlServerIsMemoryOptimized()); + if (obsolete) + { +#pragma warning disable 618 + AssertIsGeneric( + modelBuilder + .Entity() + .ForSqlServerIsMemoryOptimized()); +#pragma warning restore 618 + } + else + { + AssertIsGeneric( + modelBuilder + .Entity() + .IsMemoryOptimized()); + } } - [ConditionalFact] - public void SqlServer_entity_methods_have_non_generic_overloads() + [ConditionalTheory] + [InlineData(false)] + [InlineData(true)] + public void SqlServer_entity_methods_have_non_generic_overloads(bool obsolete) { var modelBuilder = CreateConventionModelBuilder(); - modelBuilder - .Entity(typeof(Customer)) - .ForSqlServerIsMemoryOptimized(); + if (obsolete) + { +#pragma warning disable 618 + modelBuilder + .Entity(typeof(Customer)) + .ForSqlServerIsMemoryOptimized(); +#pragma warning restore 618 + } + else + { + modelBuilder + .Entity(typeof(Customer)) + .IsMemoryOptimized(); + } } - [ConditionalFact] - public void SqlServer_property_methods_dont_break_out_of_the_generics() + [ConditionalTheory] + [InlineData(false)] + [InlineData(true)] + public void SqlServer_property_methods_dont_break_out_of_the_generics(bool obsolete) { var modelBuilder = CreateConventionModelBuilder(); - AssertIsGeneric( - modelBuilder - .Entity() - .Property(e => e.Id) - .ForSqlServerUseSequenceHiLo()); - - AssertIsGeneric( - modelBuilder - .Entity() - .Property(e => e.Id) - .ForSqlServerUseIdentityColumn()); + if (obsolete) + { +#pragma warning disable 618 + AssertIsGeneric( + modelBuilder + .Entity() + .Property(e => e.Id) + .ForSqlServerUseSequenceHiLo()); + + AssertIsGeneric( + modelBuilder + .Entity() + .Property(e => e.Id) + .UseSqlServerIdentityColumn()); +#pragma warning restore 618 + } + else + { + AssertIsGeneric( + modelBuilder + .Entity() + .Property(e => e.Id) + .UseHiLo()); + + AssertIsGeneric( + modelBuilder + .Entity() + .Property(e => e.Id) + .UseIdentityColumn()); + } } - [ConditionalFact] - public void SqlServer_property_methods_have_non_generic_overloads() + [ConditionalTheory] + [InlineData(false)] + [InlineData(true)] + public void SqlServer_property_methods_have_non_generic_overloads(bool obsolete) { var modelBuilder = CreateConventionModelBuilder(); - modelBuilder - .Entity(typeof(Customer)) - .Property(typeof(int), "Id") - .ForSqlServerUseSequenceHiLo(); + if (obsolete) + { +#pragma warning disable 618 + modelBuilder + .Entity(typeof(Customer)) + .Property(typeof(int), "Id") + .ForSqlServerUseSequenceHiLo(); - modelBuilder - .Entity(typeof(Customer)) - .Property(typeof(int), "Id") - .ForSqlServerUseIdentityColumn(); + modelBuilder + .Entity(typeof(Customer)) + .Property(typeof(int), "Id") + .UseSqlServerIdentityColumn(); +#pragma warning restore 618 + } + else + { + modelBuilder + .Entity(typeof(Customer)) + .Property(typeof(int), "Id") + .UseHiLo(); + + modelBuilder + .Entity(typeof(Customer)) + .Property(typeof(int), "Id") + .UseIdentityColumn(); + } } [ConditionalFact] diff --git a/test/EFCore.SqlServer.Tests/Metadata/SqlServerMetadataBuilderExtensionsTest.cs b/test/EFCore.SqlServer.Tests/Metadata/SqlServerMetadataBuilderExtensionsTest.cs index 2c316e1e088..02ffac84273 100644 --- a/test/EFCore.SqlServer.Tests/Metadata/SqlServerMetadataBuilderExtensionsTest.cs +++ b/test/EFCore.SqlServer.Tests/Metadata/SqlServerMetadataBuilderExtensionsTest.cs @@ -23,16 +23,16 @@ public void Can_access_model() var builder = CreateBuilder(); Assert.NotNull(builder - .ForSqlServerHasValueGenerationStrategy(SqlServerValueGenerationStrategy.SequenceHiLo)); + .HasValueGenerationStrategy(SqlServerValueGenerationStrategy.SequenceHiLo)); Assert.Equal(SqlServerValueGenerationStrategy.SequenceHiLo, builder.Metadata.GetSqlServerValueGenerationStrategy()); Assert.NotNull(builder - .ForSqlServerHasValueGenerationStrategy(SqlServerValueGenerationStrategy.IdentityColumn, fromDataAnnotation: true)); + .HasValueGenerationStrategy(SqlServerValueGenerationStrategy.IdentityColumn, fromDataAnnotation: true)); Assert.Equal( SqlServerValueGenerationStrategy.IdentityColumn, builder.Metadata.GetSqlServerValueGenerationStrategy()); Assert.Null(builder - .ForSqlServerHasValueGenerationStrategy(SqlServerValueGenerationStrategy.SequenceHiLo)); + .HasValueGenerationStrategy(SqlServerValueGenerationStrategy.SequenceHiLo)); Assert.Equal(SqlServerValueGenerationStrategy.IdentityColumn, builder.Metadata.GetSqlServerValueGenerationStrategy()); Assert.Equal( @@ -45,13 +45,13 @@ public void Can_access_entity_type() { var typeBuilder = CreateBuilder().Entity(typeof(Splot)); - Assert.NotNull(typeBuilder.ForSqlServerIsMemoryOptimized(true)); + Assert.NotNull(typeBuilder.IsMemoryOptimized(true)); Assert.True(typeBuilder.Metadata.GetSqlServerIsMemoryOptimized()); - Assert.NotNull(typeBuilder.ForSqlServerIsMemoryOptimized(false, fromDataAnnotation: true)); + Assert.NotNull(typeBuilder.IsMemoryOptimized(false, fromDataAnnotation: true)); Assert.False(typeBuilder.Metadata.GetSqlServerIsMemoryOptimized()); - Assert.Null(typeBuilder.ForSqlServerIsMemoryOptimized(true)); + Assert.Null(typeBuilder.IsMemoryOptimized(true)); Assert.False(typeBuilder.Metadata.GetSqlServerIsMemoryOptimized()); Assert.Equal( @@ -66,13 +66,13 @@ public void Can_access_property() .Entity(typeof(Splot)) .Property(typeof(int), "Id"); - Assert.NotNull(propertyBuilder.ForSqlServerHasHiLoSequence("Splew", null)); + Assert.NotNull(propertyBuilder.HasHiLoSequence("Splew", null)); Assert.Equal("Splew", propertyBuilder.Metadata.GetSqlServerHiLoSequenceName()); - Assert.NotNull(propertyBuilder.ForSqlServerHasHiLoSequence("Splow", null, fromDataAnnotation: true)); + Assert.NotNull(propertyBuilder.HasHiLoSequence("Splow", null, fromDataAnnotation: true)); Assert.Equal("Splow", propertyBuilder.Metadata.GetSqlServerHiLoSequenceName()); - Assert.Null(propertyBuilder.ForSqlServerHasHiLoSequence("Splod", null)); + Assert.Null(propertyBuilder.HasHiLoSequence("Splod", null)); Assert.Equal("Splow", propertyBuilder.Metadata.GetSqlServerHiLoSequenceName()); Assert.Equal( @@ -90,12 +90,12 @@ public void Throws_setting_sequence_generation_for_invalid_type() Assert.Equal( SqlServerStrings.SequenceBadType("Name", nameof(Splot), "string"), Assert.Throws( - () => propertyBuilder.ForSqlServerHasValueGenerationStrategy(SqlServerValueGenerationStrategy.SequenceHiLo)).Message); + () => propertyBuilder.HasValueGenerationStrategy(SqlServerValueGenerationStrategy.SequenceHiLo)).Message); Assert.Equal( SqlServerStrings.SequenceBadType("Name", nameof(Splot), "string"), Assert.Throws( - () => new PropertyBuilder((IMutableProperty)propertyBuilder.Metadata).ForSqlServerUseSequenceHiLo()).Message); + () => new PropertyBuilder((IMutableProperty)propertyBuilder.Metadata).UseHiLo()).Message); } [ConditionalFact] @@ -108,12 +108,12 @@ public void Throws_setting_identity_generation_for_invalid_type_only_with_explic Assert.Equal( SqlServerStrings.IdentityBadType("Name", nameof(Splot), "string"), Assert.Throws( - () => propertyBuilder.ForSqlServerHasValueGenerationStrategy(SqlServerValueGenerationStrategy.IdentityColumn)).Message); + () => propertyBuilder.HasValueGenerationStrategy(SqlServerValueGenerationStrategy.IdentityColumn)).Message); Assert.Equal( SqlServerStrings.IdentityBadType("Name", nameof(Splot), "string"), Assert.Throws( - () => new PropertyBuilder((IMutableProperty)propertyBuilder.Metadata).ForSqlServerUseIdentityColumn()).Message); + () => new PropertyBuilder((IMutableProperty)propertyBuilder.Metadata).UseIdentityColumn()).Message); } [ConditionalFact] @@ -124,13 +124,13 @@ public void Can_access_key() var idProperty = entityTypeBuilder.Property(typeof(string), "Id").Metadata; var keyBuilder = entityTypeBuilder.HasKey(new[] { idProperty }); - Assert.NotNull(keyBuilder.ForSqlServerIsClustered(true)); + Assert.NotNull(keyBuilder.IsClustered(true)); Assert.True(keyBuilder.Metadata.GetSqlServerIsClustered()); - Assert.NotNull(keyBuilder.ForSqlServerIsClustered(false, fromDataAnnotation: true)); + Assert.NotNull(keyBuilder.IsClustered(false, fromDataAnnotation: true)); Assert.False(keyBuilder.Metadata.GetSqlServerIsClustered()); - Assert.Null(keyBuilder.ForSqlServerIsClustered(true)); + Assert.Null(keyBuilder.IsClustered(true)); Assert.False(keyBuilder.Metadata.GetSqlServerIsClustered()); Assert.Equal( @@ -138,21 +138,51 @@ public void Can_access_key() a => a.Name.StartsWith(SqlServerAnnotationNames.Prefix, StringComparison.Ordinal))); } - [ConditionalFact] - public void Can_access_index() + [ConditionalTheory] + [InlineData(false)] + [InlineData(true)] + public void Can_access_index(bool obsolete) { var modelBuilder = CreateBuilder(); var entityTypeBuilder = modelBuilder.Entity(typeof(Splot)); var idProperty = entityTypeBuilder.Property(typeof(int), "Id").Metadata; var indexBuilder = entityTypeBuilder.HasIndex(new[] { idProperty }); - Assert.NotNull(indexBuilder.ForSqlServerIsClustered(true)); + if (obsolete) + { +#pragma warning disable 618 + Assert.NotNull(indexBuilder.ForSqlServerIsClustered(true)); +#pragma warning restore 618 + } + else + { + Assert.NotNull(indexBuilder.IsClustered(true)); + } Assert.True(indexBuilder.Metadata.GetSqlServerIsClustered()); - Assert.NotNull(indexBuilder.ForSqlServerIsClustered(false, fromDataAnnotation: true)); + if (obsolete) + { +#pragma warning disable 618 + Assert.NotNull(indexBuilder.ForSqlServerIsClustered(false, fromDataAnnotation: true)); +#pragma warning restore 618 + } + else + { + Assert.NotNull(indexBuilder.IsClustered(false, fromDataAnnotation: true)); + } Assert.False(indexBuilder.Metadata.GetSqlServerIsClustered()); - Assert.Null(indexBuilder.ForSqlServerIsClustered(true)); + + if (obsolete) + { +#pragma warning disable 618 + Assert.Null(indexBuilder.ForSqlServerIsClustered(true)); +#pragma warning restore 618 + } + else + { + Assert.Null(indexBuilder.IsClustered(true)); + } Assert.False(indexBuilder.Metadata.GetSqlServerIsClustered()); Assert.Equal( diff --git a/test/EFCore.SqlServer.Tests/Migrations/SqlServerModelDifferTest.cs b/test/EFCore.SqlServer.Tests/Migrations/SqlServerModelDifferTest.cs index 1460ac3091a..caaeed9a39c 100644 --- a/test/EFCore.SqlServer.Tests/Migrations/SqlServerModelDifferTest.cs +++ b/test/EFCore.SqlServer.Tests/Migrations/SqlServerModelDifferTest.cs @@ -31,15 +31,15 @@ public void Alter_table_to_MemoryOptimized() x => { x.Property("Id"); - x.HasKey("Id").ForSqlServerIsClustered(false); + x.HasKey("Id").IsClustered(false); }), target => target.Entity( "Person", x => { x.Property("Id"); - x.HasKey("Id").ForSqlServerIsClustered(false); - x.ForSqlServerIsMemoryOptimized(); + x.HasKey("Id").IsClustered(false); + x.IsMemoryOptimized(); }), operations => { @@ -65,15 +65,15 @@ public void Alter_table_from_MemoryOptimized() x => { x.Property("Id"); - x.HasKey("Id").ForSqlServerIsClustered(false); - x.ForSqlServerIsMemoryOptimized(); + x.HasKey("Id").IsClustered(false); + x.IsMemoryOptimized(); }), target => target.Entity( "Person", x => { x.Property("Id"); - x.HasKey("Id").ForSqlServerIsClustered(false); + x.HasKey("Id").IsClustered(false); }), operations => { @@ -214,7 +214,7 @@ public void Alter_primary_key_clustering() { x.ToTable("Ram", "bah"); x.Property("Id"); - x.HasKey("Id").ForSqlServerIsClustered(false); + x.HasKey("Id").IsClustered(false); }), target => target.Entity( "Ram", @@ -222,7 +222,7 @@ public void Alter_primary_key_clustering() { x.ToTable("Ram", "bah"); x.Property("Id"); - x.HasKey("Id").ForSqlServerIsClustered(); + x.HasKey("Id").IsClustered(); }), operations => { @@ -251,7 +251,7 @@ public void Add_non_clustered_primary_key_with_owned() x => { x.Property("Id"); - x.HasKey("Id").ForSqlServerIsClustered(false); + x.HasKey("Id").IsClustered(false); x.OwnsOne("Address", "Address"); }), operations => @@ -276,7 +276,7 @@ public void Alter_unique_constraint_clustering() x.ToTable("Ewe", "bah"); x.Property("Id"); x.Property("AlternateId"); - x.HasAlternateKey("AlternateId").ForSqlServerIsClustered(false); + x.HasAlternateKey("AlternateId").IsClustered(false); }), target => target.Entity( "Ewe", @@ -285,7 +285,7 @@ public void Alter_unique_constraint_clustering() x.ToTable("Ewe", "bah"); x.Property("Id"); x.Property("AlternateId"); - x.HasAlternateKey("AlternateId").ForSqlServerIsClustered(); + x.HasAlternateKey("AlternateId").IsClustered(); }), operations => { @@ -364,7 +364,7 @@ public void Add_SequenceHiLo_with_seed_data() x => { x.ToTable("Firefly", "dbo"); - x.Property("SequenceId").ForSqlServerUseSequenceHiLo(schema: "dbo"); + x.Property("SequenceId").UseHiLo(schema: "dbo"); x.HasData( new { @@ -414,7 +414,7 @@ public void Alter_index_clustering() x.ToTable("Mutton", "bah"); x.Property("Id"); x.Property("Value"); - x.HasIndex("Value").ForSqlServerIsClustered(false); + x.HasIndex("Value").IsClustered(false); }), target => target.Entity( "Mutton", @@ -423,7 +423,7 @@ public void Alter_index_clustering() x.ToTable("Mutton", "bah"); x.Property("Id"); x.Property("Value"); - x.HasIndex("Value").ForSqlServerIsClustered(); + x.HasIndex("Value").IsClustered(); }), operations => { @@ -677,7 +677,7 @@ public void Dont_rebuild_index_with_equal_include() x.Property("Zip"); x.Property("City"); x.HasIndex("Zip") - .ForSqlServerInclude("City"); + .IncludeProperties("City"); }), target => target .Entity( @@ -688,7 +688,7 @@ public void Dont_rebuild_index_with_equal_include() x.Property("Zip"); x.Property("City"); x.HasIndex("Zip") - .ForSqlServerInclude("City"); + .IncludeProperties("City"); }), operations => Assert.Equal(0, operations.Count)); } @@ -707,7 +707,7 @@ public void Rebuild_index_with_different_include() x.Property("City"); x.Property("Street"); x.HasIndex("Zip") - .ForSqlServerInclude("City"); + .IncludeProperties("City"); }), target => target .Entity( @@ -719,7 +719,7 @@ public void Rebuild_index_with_different_include() x.Property("City"); x.Property("Street"); x.HasIndex("Zip") - .ForSqlServerInclude("Street"); + .IncludeProperties("Street"); }), operations => { @@ -755,7 +755,7 @@ public void Dont_rebuild_index_with_unchanged_online_option() x.Property("Zip"); x.Property("City"); x.HasIndex("Zip") - .ForSqlServerIsCreatedOnline(); + .IsCreatedOnline(); }), target => target .Entity( @@ -766,7 +766,7 @@ public void Dont_rebuild_index_with_unchanged_online_option() x.Property("Zip"); x.Property("City"); x.HasIndex("Zip") - .ForSqlServerIsCreatedOnline(); + .IsCreatedOnline(); }), operations => Assert.Equal(0, operations.Count)); } @@ -796,7 +796,7 @@ public void Rebuild_index_when_changing_online_option() x.Property("City"); x.Property("Street"); x.HasIndex("Zip") - .ForSqlServerIsCreatedOnline(); + .IsCreatedOnline(); }), operations => { diff --git a/test/EFCore.SqlServer.Tests/ModelBuilding/SqlServerModelBuilderGenericTest.cs b/test/EFCore.SqlServer.Tests/ModelBuilding/SqlServerModelBuilderGenericTest.cs index 4dc70110796..373302e9f18 100644 --- a/test/EFCore.SqlServer.Tests/ModelBuilding/SqlServerModelBuilderGenericTest.cs +++ b/test/EFCore.SqlServer.Tests/ModelBuilding/SqlServerModelBuilderGenericTest.cs @@ -35,11 +35,11 @@ public virtual void Index_has_a_filter_if_nonclustered_unique_with_nullable_prop Assert.Equal("[Name] IS NOT NULL", index.GetFilter()); - indexBuilder.ForSqlServerIsClustered(); + indexBuilder.IsClustered(); Assert.Null(index.GetFilter()); - indexBuilder.ForSqlServerIsClustered(false); + indexBuilder.IsClustered(false); Assert.Equal("[Name] IS NOT NULL", index.GetFilter()); @@ -298,7 +298,7 @@ public virtual void Owned_types_can_be_mapped_to_different_tables() tb.WithOwner() .HasConstraintName("AlternateLabelFK"); tb.ToTable("TT", "TS"); - tb.ForSqlServerIsMemoryOptimized(); + tb.IsMemoryOptimized(); tb.OwnsOne( l => l.AnotherBookLabel, ab => { @@ -427,7 +427,7 @@ public virtual void Owned_type_collections_can_be_mapped_to_different_tables() r => { r.HasKey(o => o.OrderId); - r.ForSqlServerIsMemoryOptimized(); + r.IsMemoryOptimized(); r.Ignore(o => o.OrderCombination); r.Ignore(o => o.Details); }); diff --git a/test/EFCore.SqlServer.Tests/ModelBuilding/SqlServerTestModelBuilderExtensions.cs b/test/EFCore.SqlServer.Tests/ModelBuilding/SqlServerTestModelBuilderExtensions.cs index 17fd03ef0b8..99b24a2a48d 100644 --- a/test/EFCore.SqlServer.Tests/ModelBuilding/SqlServerTestModelBuilderExtensions.cs +++ b/test/EFCore.SqlServer.Tests/ModelBuilding/SqlServerTestModelBuilderExtensions.cs @@ -8,15 +8,15 @@ namespace Microsoft.EntityFrameworkCore.ModelBuilding { public static class SqlServerTestModelBuilderExtensions { - public static ModelBuilderTest.TestIndexBuilder ForSqlServerIsClustered( + public static ModelBuilderTest.TestIndexBuilder IsClustered( this ModelBuilderTest.TestIndexBuilder builder, bool clustered = true) { var indexBuilder = builder.GetInfrastructure(); - indexBuilder.ForSqlServerIsClustered(clustered); + indexBuilder.IsClustered(clustered); return builder; } - public static ModelBuilderTest.TestOwnedNavigationBuilder ForSqlServerIsMemoryOptimized IsMemoryOptimized( this ModelBuilderTest.TestOwnedNavigationBuilder builder, bool memoryOptimized = true) where TEntity : class @@ -25,10 +25,10 @@ public static ModelBuilderTest.TestIndexBuilder ForSqlServerIsClustered( switch (builder) { case IInfrastructure> genericBuilder: - genericBuilder.Instance.ForSqlServerIsMemoryOptimized(memoryOptimized); + genericBuilder.Instance.IsMemoryOptimized(memoryOptimized); break; case IInfrastructure nongenericBuilder: - nongenericBuilder.Instance.ForSqlServerIsMemoryOptimized(memoryOptimized); + nongenericBuilder.Instance.IsMemoryOptimized(memoryOptimized); break; } diff --git a/test/EFCore.SqlServer.Tests/SqlServerValueGeneratorCacheTest.cs b/test/EFCore.SqlServer.Tests/SqlServerValueGeneratorCacheTest.cs index cc35000ab87..1a7b0228f4a 100644 --- a/test/EFCore.SqlServer.Tests/SqlServerValueGeneratorCacheTest.cs +++ b/test/EFCore.SqlServer.Tests/SqlServerValueGeneratorCacheTest.cs @@ -120,7 +120,7 @@ public void Block_size_is_obtained_from_default_sequence() var property = modelBuilder .Entity() .Property(e => e.Id) - .ForSqlServerUseSequenceHiLo() + .UseHiLo() .Metadata; modelBuilder.FinalizeModel(); @@ -138,7 +138,7 @@ public void Block_size_is_obtained_from_named_sequence() var property = modelBuilder .Entity() .Property(e => e.Id) - .ForSqlServerUseSequenceHiLo("DaneelOlivaw") + .UseHiLo("DaneelOlivaw") .Metadata; modelBuilder.FinalizeModel(); @@ -154,7 +154,7 @@ public void Block_size_is_obtained_from_model_default_sequence() var modelBuilder = CreateConventionModelBuilder(); var property = modelBuilder - .ForSqlServerUseSequenceHiLo() + .UseHiLo() .Entity() .Property(e => e.Id) .Metadata; @@ -172,7 +172,7 @@ public void Block_size_is_obtained_from_named_model_default_sequence() var modelBuilder = CreateConventionModelBuilder(); var property = modelBuilder - .ForSqlServerUseSequenceHiLo("DaneelOlivaw") + .UseHiLo("DaneelOlivaw") .Entity() .Property(e => e.Id) .Metadata; @@ -193,7 +193,7 @@ public void Block_size_is_obtained_from_specified_sequence() .HasSequence("DaneelOlivaw", b => b.IncrementsBy(11)) .Entity() .Property(e => e.Id) - .ForSqlServerUseSequenceHiLo("DaneelOlivaw") + .UseHiLo("DaneelOlivaw") .Metadata; modelBuilder.FinalizeModel(); @@ -212,7 +212,7 @@ public void Non_positive_block_sizes_are_not_allowed() .HasSequence("DaneelOlivaw", b => b.IncrementsBy(-1)) .Entity() .Property(e => e.Id) - .ForSqlServerUseSequenceHiLo("DaneelOlivaw") + .UseHiLo("DaneelOlivaw") .Metadata; var cache = new SqlServerValueGeneratorCache(new ValueGeneratorCacheDependencies()); @@ -231,7 +231,7 @@ public void Block_size_is_obtained_from_specified_model_default_sequence() var modelBuilder = CreateConventionModelBuilder(); var property = modelBuilder - .ForSqlServerUseSequenceHiLo("DaneelOlivaw") + .UseHiLo("DaneelOlivaw") .HasSequence("DaneelOlivaw", b => b.IncrementsBy(11)) .Entity() .Property(e => e.Id) @@ -252,7 +252,7 @@ public void Sequence_name_is_obtained_from_default_sequence() var property = modelBuilder .Entity() .Property(e => e.Id) - .ForSqlServerUseSequenceHiLo() + .UseHiLo() .Metadata; modelBuilder.FinalizeModel(); @@ -270,7 +270,7 @@ public void Sequence_name_is_obtained_from_named_sequence() var property = modelBuilder .Entity() .Property(e => e.Id) - .ForSqlServerUseSequenceHiLo("DaneelOlivaw") + .UseHiLo("DaneelOlivaw") .Metadata; modelBuilder.FinalizeModel(); @@ -286,7 +286,7 @@ public void Sequence_name_is_obtained_from_model_default_sequence() var modelBuilder = CreateConventionModelBuilder(); var property = modelBuilder - .ForSqlServerUseSequenceHiLo() + .UseHiLo() .Entity() .Property(e => e.Id) .Metadata; @@ -304,7 +304,7 @@ public void Sequence_name_is_obtained_from_named_model_default_sequence() var modelBuilder = CreateConventionModelBuilder(); var property = modelBuilder - .ForSqlServerUseSequenceHiLo("DaneelOlivaw") + .UseHiLo("DaneelOlivaw") .Entity() .Property(e => e.Id) .Metadata; @@ -325,7 +325,7 @@ public void Sequence_name_is_obtained_from_specified_sequence() .HasSequence("DaneelOlivaw", b => b.IncrementsBy(11)) .Entity() .Property(e => e.Id) - .ForSqlServerUseSequenceHiLo("DaneelOlivaw") + .UseHiLo("DaneelOlivaw") .Metadata; modelBuilder.FinalizeModel(); @@ -341,7 +341,7 @@ public void Sequence_name_is_obtained_from_specified_model_default_sequence() var modelBuilder = CreateConventionModelBuilder(); var property = modelBuilder - .ForSqlServerUseSequenceHiLo("DaneelOlivaw") + .UseHiLo("DaneelOlivaw") .HasSequence("DaneelOlivaw", b => b.IncrementsBy(11)) .Entity() .Property(e => e.Id) @@ -362,7 +362,7 @@ public void Schema_qualified_sequence_name_is_obtained_from_named_sequence() var property = modelBuilder .Entity() .Property(e => e.Id) - .ForSqlServerUseSequenceHiLo("DaneelOlivaw", "R") + .UseHiLo("DaneelOlivaw", "R") .Metadata; modelBuilder.FinalizeModel(); @@ -379,7 +379,7 @@ public void Schema_qualified_sequence_name_is_obtained_from_named_model_default_ var modelBuilder = CreateConventionModelBuilder(); var property = modelBuilder - .ForSqlServerUseSequenceHiLo("DaneelOlivaw", "R") + .UseHiLo("DaneelOlivaw", "R") .Entity() .Property(e => e.Id) .Metadata; @@ -401,7 +401,7 @@ public void Schema_qualified_sequence_name_is_obtained_from_specified_sequence() .HasSequence("DaneelOlivaw", "R", b => b.IncrementsBy(11)) .Entity() .Property(e => e.Id) - .ForSqlServerUseSequenceHiLo("DaneelOlivaw", "R") + .UseHiLo("DaneelOlivaw", "R") .Metadata; modelBuilder.FinalizeModel(); @@ -418,7 +418,7 @@ public void Schema_qualified_sequence_name_is_obtained_from_specified_model_defa var modelBuilder = CreateConventionModelBuilder(); var property = modelBuilder - .ForSqlServerUseSequenceHiLo("DaneelOlivaw", "R") + .UseHiLo("DaneelOlivaw", "R") .HasSequence("DaneelOlivaw", "R", b => b.IncrementsBy(11)) .Entity() .Property(e => e.Id) @@ -455,9 +455,9 @@ private static IModel CreateModel() modelBuilder.Entity( b => { - b.Property(e => e.Zeppelin).ForSqlServerUseSequenceHiLo("Heaven"); - b.Property(e => e.Stairway).ForSqlServerUseSequenceHiLo("Heaven"); - b.Property(e => e.WholeLotta).ForSqlServerUseSequenceHiLo("Rosie"); + b.Property(e => e.Zeppelin).UseHiLo("Heaven"); + b.Property(e => e.Stairway).UseHiLo("Heaven"); + b.Property(e => e.WholeLotta).UseHiLo("Rosie"); }); return modelBuilder.Model; diff --git a/test/EFCore.SqlServer.Tests/SqlServerValueGeneratorSelectorTest.cs b/test/EFCore.SqlServer.Tests/SqlServerValueGeneratorSelectorTest.cs index b12a2c899e2..dde3e256acd 100644 --- a/test/EFCore.SqlServer.Tests/SqlServerValueGeneratorSelectorTest.cs +++ b/test/EFCore.SqlServer.Tests/SqlServerValueGeneratorSelectorTest.cs @@ -48,7 +48,7 @@ private void AssertGenerator(string propertyName, bool setSequences = if (setSequences) { - builder.ForSqlServerUseSequenceHiLo(); + builder.UseHiLo(); Assert.NotNull(builder.Model.FindSequence(SqlServerModelExtensions.DefaultHiLoSequenceName)); } @@ -164,10 +164,10 @@ public void Returns_generator_configured_on_model_when_property_is_identity() builder.Entity(); builder - .ForSqlServerUseSequenceHiLo() + .UseHiLo() .HasSequence(SqlServerModelExtensions.DefaultHiLoSequenceName); - var model = builder.ForSqlServerUseSequenceHiLo().FinalizeModel(); + var model = builder.UseHiLo().FinalizeModel(); var entityType = model.FindEntityType(typeof(AnEntity)); var selector = SqlServerTestHelpers.Instance.CreateContextServices(model).GetRequiredService(); diff --git a/test/EFCore.Sqlite.Tests/Metadata/Builders/SqliteBuilderExtensionsTest.cs b/test/EFCore.Sqlite.Tests/Metadata/Builders/SqliteBuilderExtensionsTest.cs index f20677d774c..28aa5c20a52 100644 --- a/test/EFCore.Sqlite.Tests/Metadata/Builders/SqliteBuilderExtensionsTest.cs +++ b/test/EFCore.Sqlite.Tests/Metadata/Builders/SqliteBuilderExtensionsTest.cs @@ -8,57 +8,129 @@ namespace Microsoft.EntityFrameworkCore.Metadata.Builders { public class SqliteBuilderExtensionsTest { - [ConditionalFact] - public void Can_set_srid() + [ConditionalTheory] + [InlineData(false)] + [InlineData(true)] + public void Can_set_srid(bool obsolete) { var modelBuilder = CreateConventionModelBuilder(); + if (obsolete) + { +#pragma warning disable 618 + modelBuilder + .Entity() + .Property(e => e.Geometry) + .ForSqliteHasSrid(1); +#pragma warning restore 618 + } + else + { + modelBuilder + .Entity() + .Property(e => e.Geometry) + .HasSrid(1); + } + var property = modelBuilder .Entity() .Property(e => e.Geometry) - .ForSqliteHasSrid(1) .Metadata; Assert.Equal(1, property.GetSqliteSrid()); } - [ConditionalFact] - public void Can_set_srid_non_generic() + [ConditionalTheory] + [InlineData(false)] + [InlineData(true)] + public void Can_set_srid_non_generic(bool obsolete) { var modelBuilder = CreateConventionModelBuilder(); + if (obsolete) + { +#pragma warning disable 618 + modelBuilder + .Entity() + .Property("Geometry") + .ForSqliteHasSrid(1); +#pragma warning restore 618 + } + else + { + modelBuilder + .Entity() + .Property("Geometry") + .HasSrid(1); + } + var property = modelBuilder .Entity() .Property("Geometry") - .ForSqliteHasSrid(1) .Metadata; Assert.Equal(1, property.GetSqliteSrid()); } - [ConditionalFact] - public void Can_set_srid_convention() + [ConditionalTheory] + [InlineData(false)] + [InlineData(true)] + public void Can_set_srid_convention(bool obsolete) { var modelBuilder = ((IConventionModel)CreateConventionModelBuilder().Model).Builder; + if (obsolete) + { +#pragma warning disable 618 + modelBuilder + .Entity(typeof(Customer)) + .Property(typeof(string), "Geometry") + .ForSqliteHasSrid(1); +#pragma warning restore 618 + } + else + { + modelBuilder + .Entity(typeof(Customer)) + .Property(typeof(string), "Geometry") + .HasSrid(1); + } + var property = modelBuilder .Entity(typeof(Customer)) .Property(typeof(string), "Geometry") - .ForSqliteHasSrid(1) .Metadata; Assert.Equal(1, property.GetSqliteSrid()); } - [ConditionalFact] - public void Can_set_dimension_convention() + [ConditionalTheory] + [InlineData(false)] + [InlineData(true)] + public void Can_set_dimension_convention(bool obsolete) { var modelBuilder = ((IConventionModel)CreateConventionModelBuilder().Model).Builder; + if (obsolete) + { +#pragma warning disable 618 + modelBuilder + .Entity(typeof(Customer)) + .Property(typeof(string), "Geometry") + .ForSqliteHasDimension("Z"); +#pragma warning restore 618 + } + else + { + modelBuilder + .Entity(typeof(Customer)) + .Property(typeof(string), "Geometry") + .HasSpatialDimension("Z"); + } + var property = modelBuilder .Entity(typeof(Customer)) .Property(typeof(string), "Geometry") - .ForSqliteHasDimension("Z") .Metadata; Assert.Equal("Z", property.GetSqliteDimension());