From 1602b465efd8b89109c6e2698c6cea4696e754d2 Mon Sep 17 00:00:00 2001 From: Brice Lambson Date: Wed, 12 Aug 2020 12:38:17 -0700 Subject: [PATCH] API Review Changes Part of #20409 --- .../Extensions/RelationalIndexExtensions.cs | 3 +-- .../RelationalPropertyBuilderExtensions.cs | 27 +++++++++++++++++-- .../Migrations/Internal/Migrator.cs | 12 ++++----- .../Storage/ISqlGenerationHelper.cs | 4 +-- .../Storage/RelationalSqlGenerationHelper.cs | 4 +-- .../Internal/SqlServerSqlGenerationHelper.cs | 2 +- .../Internal/SqliteSqlGenerationHelper.cs | 2 +- .../ConventionEntityTypeExtensions.cs | 3 +-- .../ConventionPropertyExtensions.cs | 5 ++-- src/EFCore/Metadata/Internal/EntityType.cs | 4 +-- .../QueryCompilationContextDependencies.cs | 6 ----- test/EFCore.Tests/ApiConsistencyTestBase.cs | 3 --- 12 files changed, 42 insertions(+), 33 deletions(-) diff --git a/src/EFCore.Relational/Extensions/RelationalIndexExtensions.cs b/src/EFCore.Relational/Extensions/RelationalIndexExtensions.cs index 8e7c91f7263..3951a89a696 100644 --- a/src/EFCore.Relational/Extensions/RelationalIndexExtensions.cs +++ b/src/EFCore.Relational/Extensions/RelationalIndexExtensions.cs @@ -175,9 +175,8 @@ public static string SetDatabaseName([NotNull] this IConventionIndex index, [Can /// The index. /// The value to set. /// Indicates whether the configuration was specified using a data annotation. - /// The configured value. [Obsolete("Use SetDatabaseName() instead.")] - public static string SetName([NotNull] this IConventionIndex index, [CanBeNull] string name, bool fromDataAnnotation = false) + public static void SetName([NotNull] this IConventionIndex index, [CanBeNull] string name, bool fromDataAnnotation = false) => SetDatabaseName(index, name, fromDataAnnotation); /// diff --git a/src/EFCore.Relational/Extensions/RelationalPropertyBuilderExtensions.cs b/src/EFCore.Relational/Extensions/RelationalPropertyBuilderExtensions.cs index 894ebeed952..2edf2d7f7ea 100644 --- a/src/EFCore.Relational/Extensions/RelationalPropertyBuilderExtensions.cs +++ b/src/EFCore.Relational/Extensions/RelationalPropertyBuilderExtensions.cs @@ -397,6 +397,17 @@ public static PropertyBuilder HasComputedColumnSql([NotNull] this PropertyBuilde return propertyBuilder; } + /// + /// Configures the property to map to a computed column when targeting a relational database. + /// + /// The builder for the property being configured. + /// The SQL expression that computes values for the column. + /// The same builder instance so that multiple calls can be chained. + public static PropertyBuilder HasComputedColumnSql( + [NotNull] this PropertyBuilder propertyBuilder, + [CanBeNull] string sql) + => HasComputedColumnSql(propertyBuilder, sql, null); + /// /// Configures the property to map to a computed column when targeting a relational database. /// @@ -411,7 +422,7 @@ public static PropertyBuilder HasComputedColumnSql([NotNull] this PropertyBuilde public static PropertyBuilder HasComputedColumnSql( [NotNull] this PropertyBuilder propertyBuilder, [CanBeNull] string sql, - bool? stored = null) + bool? stored) { Check.NotNull(propertyBuilder, nameof(propertyBuilder)); Check.NullButNotEmpty(sql, nameof(sql)); @@ -443,6 +454,18 @@ public static PropertyBuilder HasComputedColumnSql( [NotNull] this PropertyBuilder propertyBuilder) => (PropertyBuilder)HasComputedColumnSql((PropertyBuilder)propertyBuilder); + /// + /// Configures the property to map to a computed column when targeting a relational database. + /// + /// The type of the property being configured. + /// The builder for the property being configured. + /// The SQL expression that computes values for the column. + /// The same builder instance so that multiple calls can be chained. + public static PropertyBuilder HasComputedColumnSql( + [NotNull] this PropertyBuilder propertyBuilder, + [CanBeNull] string sql) + => HasComputedColumnSql(propertyBuilder, sql, null); + /// /// Configures the property to map to a computed column when targeting a relational database. /// @@ -458,7 +481,7 @@ public static PropertyBuilder HasComputedColumnSql( public static PropertyBuilder HasComputedColumnSql( [NotNull] this PropertyBuilder propertyBuilder, [CanBeNull] string sql, - bool? stored = null) + bool? stored) => (PropertyBuilder)HasComputedColumnSql((PropertyBuilder)propertyBuilder, sql, stored); /// diff --git a/src/EFCore.Relational/Migrations/Internal/Migrator.cs b/src/EFCore.Relational/Migrations/Internal/Migrator.cs index 8976b4098c4..565ff797938 100644 --- a/src/EFCore.Relational/Migrations/Internal/Migrator.cs +++ b/src/EFCore.Relational/Migrations/Internal/Migrator.cs @@ -359,14 +359,14 @@ public virtual string GenerateScript( if (!transactionStarted && !command.TransactionSuppressed) { builder - .AppendLine(_sqlGenerationHelper.StartTransaction) + .AppendLine(_sqlGenerationHelper.StartTransactionStatement) .Append(_sqlGenerationHelper.BatchTerminator); transactionStarted = true; } if (transactionStarted && command.TransactionSuppressed) { builder - .AppendLine(_sqlGenerationHelper.Commit) + .AppendLine(_sqlGenerationHelper.CommitTransactionStatement) .Append(_sqlGenerationHelper.BatchTerminator); transactionStarted = false; } @@ -393,7 +393,7 @@ public virtual string GenerateScript( if (!noTransactions && transactionStarted) { builder - .AppendLine(_sqlGenerationHelper.Commit) + .AppendLine(_sqlGenerationHelper.CommitTransactionStatement) .Append(_sqlGenerationHelper.BatchTerminator); transactionStarted = false; } @@ -410,14 +410,14 @@ public virtual string GenerateScript( if (!transactionStarted && !command.TransactionSuppressed) { builder - .AppendLine(_sqlGenerationHelper.StartTransaction) + .AppendLine(_sqlGenerationHelper.StartTransactionStatement) .Append(_sqlGenerationHelper.BatchTerminator); transactionStarted = true; } if (transactionStarted && command.TransactionSuppressed) { builder - .AppendLine(_sqlGenerationHelper.Commit) + .AppendLine(_sqlGenerationHelper.CommitTransactionStatement) .Append(_sqlGenerationHelper.BatchTerminator); transactionStarted = false; } @@ -444,7 +444,7 @@ public virtual string GenerateScript( if (!noTransactions && transactionStarted) { builder - .AppendLine(_sqlGenerationHelper.Commit) + .AppendLine(_sqlGenerationHelper.CommitTransactionStatement) .Append(_sqlGenerationHelper.BatchTerminator); transactionStarted = false; } diff --git a/src/EFCore.Relational/Storage/ISqlGenerationHelper.cs b/src/EFCore.Relational/Storage/ISqlGenerationHelper.cs index e6ac87bb3eb..ea889383ab4 100644 --- a/src/EFCore.Relational/Storage/ISqlGenerationHelper.cs +++ b/src/EFCore.Relational/Storage/ISqlGenerationHelper.cs @@ -36,12 +36,12 @@ public interface ISqlGenerationHelper /// /// Gets the SQL for a START TRANSACTION statement. /// - string StartTransaction { get; } + string StartTransactionStatement { get; } /// /// Gets the SQL for a COMMIT statement. /// - string Commit { get; } + string CommitTransactionStatement { get; } /// /// The default single-line comment prefix. diff --git a/src/EFCore.Relational/Storage/RelationalSqlGenerationHelper.cs b/src/EFCore.Relational/Storage/RelationalSqlGenerationHelper.cs index 85d30316b74..5cc26b94038 100644 --- a/src/EFCore.Relational/Storage/RelationalSqlGenerationHelper.cs +++ b/src/EFCore.Relational/Storage/RelationalSqlGenerationHelper.cs @@ -46,10 +46,10 @@ public RelationalSqlGenerationHelper([NotNull] RelationalSqlGenerationHelperDepe public virtual string BatchTerminator => Environment.NewLine; /// - public virtual string StartTransaction => "START TRANSACTION" + StatementTerminator; + public virtual string StartTransactionStatement => "START TRANSACTION" + StatementTerminator; /// - public virtual string Commit => "COMMIT" + StatementTerminator; + public virtual string CommitTransactionStatement => "COMMIT" + StatementTerminator; /// /// The default single-line comment prefix. diff --git a/src/EFCore.SqlServer/Storage/Internal/SqlServerSqlGenerationHelper.cs b/src/EFCore.SqlServer/Storage/Internal/SqlServerSqlGenerationHelper.cs index eeb6dd2c0ae..1d40f8ab682 100644 --- a/src/EFCore.SqlServer/Storage/Internal/SqlServerSqlGenerationHelper.cs +++ b/src/EFCore.SqlServer/Storage/Internal/SqlServerSqlGenerationHelper.cs @@ -50,7 +50,7 @@ public SqlServerSqlGenerationHelper([NotNull] RelationalSqlGenerationHelperDepen /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public override string StartTransaction => "BEGIN TRANSACTION" + StatementTerminator; + public override string StartTransactionStatement => "BEGIN TRANSACTION" + StatementTerminator; /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to diff --git a/src/EFCore.Sqlite.Core/Storage/Internal/SqliteSqlGenerationHelper.cs b/src/EFCore.Sqlite.Core/Storage/Internal/SqliteSqlGenerationHelper.cs index 4f1cc294bf9..30c306d1643 100644 --- a/src/EFCore.Sqlite.Core/Storage/Internal/SqliteSqlGenerationHelper.cs +++ b/src/EFCore.Sqlite.Core/Storage/Internal/SqliteSqlGenerationHelper.cs @@ -41,7 +41,7 @@ public SqliteSqlGenerationHelper([NotNull] RelationalSqlGenerationHelperDependen /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public override string StartTransaction + public override string StartTransactionStatement => "BEGIN TRANSACTION" + StatementTerminator; /// diff --git a/src/EFCore/Extensions/ConventionEntityTypeExtensions.cs b/src/EFCore/Extensions/ConventionEntityTypeExtensions.cs index cb129c97e0d..0ad132b0c7c 100644 --- a/src/EFCore/Extensions/ConventionEntityTypeExtensions.cs +++ b/src/EFCore/Extensions/ConventionEntityTypeExtensions.cs @@ -639,9 +639,8 @@ public static LambdaExpression SetQueryFilter( /// The entity type. /// The LINQ query used as the default source. /// Indicates whether the configuration was specified using a data annotation. - /// The configured entity type. [Obsolete("Use InMemoryEntityTypeExtensions.SetInMemoryQuery")] - public static LambdaExpression SetDefiningQuery( + public static void SetDefiningQuery( [NotNull] this IConventionEntityType entityType, [CanBeNull] LambdaExpression definingQuery, bool fromDataAnnotation = false) diff --git a/src/EFCore/Extensions/ConventionPropertyExtensions.cs b/src/EFCore/Extensions/ConventionPropertyExtensions.cs index 06f2815befa..a1cc5af56bf 100644 --- a/src/EFCore/Extensions/ConventionPropertyExtensions.cs +++ b/src/EFCore/Extensions/ConventionPropertyExtensions.cs @@ -358,9 +358,8 @@ public static ValueComparer SetValueComparer( /// The property. /// The comparer, or to remove any previously set comparer. /// Indicates whether the configuration was specified using a data annotation. - /// The configured value. [Obsolete("Use SetValueComparer. Only a single value comparer is allowed for a given property.")] - public static ValueComparer SetKeyValueComparer( + public static void SetKeyValueComparer( [NotNull] this IConventionProperty property, [CanBeNull] ValueComparer comparer, bool fromDataAnnotation = false) @@ -383,7 +382,7 @@ public static ValueComparer SetKeyValueComparer( /// The comparer, or to remove any previously set comparer. /// Indicates whether the configuration was specified using a data annotation. [Obsolete("Use SetValueComparer. Only a single value comparer is allowed for a given property.")] - public static ValueComparer SetStructuralValueComparer( + public static void SetStructuralValueComparer( [NotNull] this IConventionProperty property, [CanBeNull] ValueComparer comparer, bool fromDataAnnotation = false) diff --git a/src/EFCore/Metadata/Internal/EntityType.cs b/src/EFCore/Metadata/Internal/EntityType.cs index e3222f096fc..c18e2f946dc 100644 --- a/src/EFCore/Metadata/Internal/EntityType.cs +++ b/src/EFCore/Metadata/Internal/EntityType.cs @@ -3127,11 +3127,9 @@ public virtual string CheckQueryFilter([CanBeNull] LambdaExpression queryFilter) /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [Obsolete] - public virtual LambdaExpression SetDefiningQuery([CanBeNull] LambdaExpression definingQuery, ConfigurationSource configurationSource) + public virtual void SetDefiningQuery([CanBeNull] LambdaExpression definingQuery, ConfigurationSource configurationSource) { this.SetOrRemoveAnnotation(CoreAnnotationNames.DefiningQuery, definingQuery, configurationSource); - - return definingQuery; } /// diff --git a/src/EFCore/Query/QueryCompilationContextDependencies.cs b/src/EFCore/Query/QueryCompilationContextDependencies.cs index 4dfff949d6f..2d52a39727f 100644 --- a/src/EFCore/Query/QueryCompilationContextDependencies.cs +++ b/src/EFCore/Query/QueryCompilationContextDependencies.cs @@ -98,12 +98,6 @@ public QueryCompilationContextDependencies( /// public Type ContextType => _currentContext.Context.GetType(); - /// - /// The flag indicating if default query tracking behavior is tracking. - /// - [Obsolete("Use " + nameof(QueryTrackingBehavior) + " instead.")] - public bool IsTracking => _currentContext.Context.ChangeTracker.QueryTrackingBehavior == QueryTrackingBehavior.TrackAll; - /// /// The default query tracking behavior. /// diff --git a/test/EFCore.Tests/ApiConsistencyTestBase.cs b/test/EFCore.Tests/ApiConsistencyTestBase.cs index bf75c269cbb..9584652fcbe 100644 --- a/test/EFCore.Tests/ApiConsistencyTestBase.cs +++ b/test/EFCore.Tests/ApiConsistencyTestBase.cs @@ -1020,9 +1020,6 @@ protected ApiConsistencyFixtureBase() typeof(ProviderConventionSetBuilderDependencies).GetProperty(nameof(ProviderConventionSetBuilderDependencies.ContextType)), typeof(QueryCompilationContextDependencies).GetProperty(nameof(QueryCompilationContextDependencies.ContextType)), typeof(QueryCompilationContextDependencies).GetProperty(nameof(QueryCompilationContextDependencies.QueryTrackingBehavior)), -#pragma warning disable CS0618 // Type or member is obsolete - typeof(QueryCompilationContextDependencies).GetProperty(nameof(QueryCompilationContextDependencies.IsTracking)), -#pragma warning restore CS0618 // Type or member is obsolete typeof(QueryContextDependencies).GetProperty(nameof(QueryContextDependencies.StateManager)), #pragma warning disable CS0618 // Type or member is obsolete typeof(QueryContextDependencies).GetProperty(nameof(QueryContextDependencies.QueryProvider))