From 27681c37d3c98475823cca5e1ca52d3094dcda48 Mon Sep 17 00:00:00 2001 From: Shay Rojansky Date: Mon, 21 Jun 2021 01:29:54 +0200 Subject: [PATCH 1/6] ADO.NET batching API Closes #28633 --- .../ref/System.Data.Common.cs | 58 ++++++++++++++++++ .../src/System.Data.Common.csproj | 3 + .../src/System/Data/Common/DbBatch.cs | 61 +++++++++++++++++++ .../src/System/Data/Common/DbBatchCommand.cs | 23 +++++++ .../Data/Common/DbBatchCommandCollection.cs | 37 +++++++++++ .../src/System/Data/Common/DbConnection.cs | 6 ++ .../src/System/Data/Common/DbException.cs | 4 ++ .../System/Data/Common/DbProviderFactory.cs | 6 ++ 8 files changed, 198 insertions(+) create mode 100644 src/libraries/System.Data.Common/src/System/Data/Common/DbBatch.cs create mode 100644 src/libraries/System.Data.Common/src/System/Data/Common/DbBatchCommand.cs create mode 100644 src/libraries/System.Data.Common/src/System/Data/Common/DbBatchCommandCollection.cs diff --git a/src/libraries/System.Data.Common/ref/System.Data.Common.cs b/src/libraries/System.Data.Common/ref/System.Data.Common.cs index a4bc1f651f202b..c7ba6e482864d0 100644 --- a/src/libraries/System.Data.Common/ref/System.Data.Common.cs +++ b/src/libraries/System.Data.Common/ref/System.Data.Common.cs @@ -1919,6 +1919,56 @@ public void RemoveAt(string sourceTable) { } System.Data.ITableMapping System.Data.ITableMappingCollection.Add(string sourceTableName, string dataSetTableName) { throw null; } System.Data.ITableMapping System.Data.ITableMappingCollection.GetByDataSetTable(string dataSetTableName) { throw null; } } + public abstract class DbBatch : System.IDisposable, System.IAsyncDisposable + { + public System.Data.Common.DbBatchCommandCollection BatchCommands { get { throw null; } } + protected abstract System.Data.Common.DbBatchCommandCollection DbBatchCommands { get; } + public abstract int Timeout { get; set; } + public System.Data.Common.DbConnection? Connection { get; set; } + protected abstract System.Data.Common.DbConnection? DbConnection { get; set; } + public System.Data.Common.DbTransaction? Transaction { get; set; } + protected abstract System.Data.Common.DbTransaction? DbTransaction { get; set; } + public System.Data.Common.DbDataReader ExecuteReader() { throw null; } + protected abstract System.Data.Common.DbDataReader ExecuteDbDataReader(); + public System.Threading.Tasks.Task ExecuteReaderAsync(System.Threading.CancellationToken cancellationToken = default) { throw null; } + protected abstract System.Threading.Tasks.Task ExecuteDbDataReaderAsync(System.Threading.CancellationToken cancellationToken); + public abstract int ExecuteNonQuery(); + public abstract System.Threading.Tasks.Task ExecuteNonQueryAsync(System.Threading.CancellationToken cancellationToken = default); + public abstract object? ExecuteScalar(); + public abstract System.Threading.Tasks.Task ExecuteScalarAsync(System.Threading.CancellationToken cancellationToken = default); + public abstract void Prepare(); + public abstract System.Threading.Tasks.Task PrepareAsync(System.Threading.CancellationToken cancellationToken = default); + public abstract void Cancel(); + public System.Data.Common.DbBatchCommand CreateBatchCommand() { throw null; } + protected virtual System.Data.Common.DbBatchCommand CreateDbBatchCommand() { throw null; } + public virtual void Dispose() { throw null; } + public virtual System.Threading.Tasks.ValueTask DisposeAsync() { throw null; } + } + public abstract class DbBatchCommand + { + public abstract string CommandText { get; set; } + public abstract CommandType CommandType { get; set; } + public abstract CommandBehavior CommandBehavior { get; set; } + public abstract int RecordsAffected { get; set; } + public DbParameterCollection Parameters { get { throw null; } } + protected abstract DbParameterCollection DbParameterCollection { get; } + } + public abstract class DbBatchCommandCollection : System.Collections.Generic.IList + { + public abstract System.Collections.Generic.IEnumerator GetEnumerator(); + System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { throw null; } + public abstract void Add(System.Data.Common.DbBatchCommand item); + public abstract void Clear(); + public abstract bool Contains(System.Data.Common.DbBatchCommand item); + public abstract void CopyTo(System.Data.Common.DbBatchCommand[] array, int arrayIndex); + public abstract bool Remove(System.Data.Common.DbBatchCommand item); + public abstract int Count { get; } + public abstract bool IsReadOnly { get; } + public abstract int IndexOf(DbBatchCommand item); + public abstract void Insert(int index, DbBatchCommand item); + public abstract void RemoveAt(int index); + public abstract DbBatchCommand this[int index] { get; set; } + } public abstract partial class DbColumn { protected DbColumn() { } @@ -2077,6 +2127,9 @@ public virtual event System.Data.StateChangeEventHandler? StateChange { add { } public virtual System.Threading.Tasks.Task ChangeDatabaseAsync(string databaseName, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public abstract void Close(); public virtual System.Threading.Tasks.Task CloseAsync() { throw null; } + public virtual bool CanCreateBatch { get { throw null; } } + public System.Data.Common.DbBatch CreateBatch() { throw null; } + protected virtual System.Data.Common.DbBatch CreateDbBatch() { throw null; } public System.Data.Common.DbCommand CreateCommand() { throw null; } protected abstract System.Data.Common.DbCommand CreateDbCommand(); public virtual System.Threading.Tasks.ValueTask DisposeAsync() { throw null; } @@ -2367,6 +2420,8 @@ protected DbException(string? message, System.Exception? innerException) { } protected DbException(string? message, int errorCode) { } public virtual bool IsTransient { get { throw null; } } public virtual string? SqlState { get { throw null; } } + public System.Data.Common.DbBatchCommand? BatchCommand { get { throw null; } } + public virtual System.Data.Common.DbBatchCommand? DbBatchCommand { get { throw null; } } } public static partial class DbMetaDataCollectionNames { @@ -2528,9 +2583,12 @@ public static void RegisterFactory(string providerInvariantName, [System.Diagnos public abstract partial class DbProviderFactory { protected DbProviderFactory() { } + public virtual bool CanCreateBatch { get { throw null; } } public virtual bool CanCreateCommandBuilder { get { throw null; } } public virtual bool CanCreateDataAdapter { get { throw null; } } public virtual bool CanCreateDataSourceEnumerator { get { throw null; } } + public virtual System.Data.Common.DbBatch CreateBatch() { throw null; } + public virtual System.Data.Common.DbBatchCommand CreateBatchCommand() { throw null; } public virtual System.Data.Common.DbCommand? CreateCommand() { throw null; } public virtual System.Data.Common.DbCommandBuilder? CreateCommandBuilder() { throw null; } public virtual System.Data.Common.DbConnection? CreateConnection() { throw null; } diff --git a/src/libraries/System.Data.Common/src/System.Data.Common.csproj b/src/libraries/System.Data.Common/src/System.Data.Common.csproj index 5e445cebc31df6..b836c7f2c8e149 100644 --- a/src/libraries/System.Data.Common/src/System.Data.Common.csproj +++ b/src/libraries/System.Data.Common/src/System.Data.Common.csproj @@ -183,6 +183,9 @@ + + + Component diff --git a/src/libraries/System.Data.Common/src/System/Data/Common/DbBatch.cs b/src/libraries/System.Data.Common/src/System/Data/Common/DbBatch.cs new file mode 100644 index 00000000000000..acd9f073190176 --- /dev/null +++ b/src/libraries/System.Data.Common/src/System/Data/Common/DbBatch.cs @@ -0,0 +1,61 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Threading; +using System.Threading.Tasks; + +namespace System.Data.Common +{ + public abstract class DbBatch : IDisposable, IAsyncDisposable + { + public DbBatchCommandCollection BatchCommands => DbBatchCommands; + + protected abstract DbBatchCommandCollection DbBatchCommands { get; } + + public abstract int Timeout { get; set; } + + public DbConnection? Connection { get; set; } + + protected abstract DbConnection? DbConnection { get; set; } + + public DbTransaction? Transaction { get; set; } + + protected abstract DbTransaction? DbTransaction { get; set; } + + public DbDataReader ExecuteReader() + => ExecuteDbDataReader(); + + protected abstract DbDataReader ExecuteDbDataReader(); + + public Task ExecuteReaderAsync(CancellationToken cancellationToken = default) + => ExecuteDbDataReaderAsync(cancellationToken); + + protected abstract Task ExecuteDbDataReaderAsync(CancellationToken cancellationToken); + + public abstract int ExecuteNonQuery(); + + public abstract Task ExecuteNonQueryAsync(CancellationToken cancellationToken = default); + + public abstract object? ExecuteScalar(); + + public abstract Task ExecuteScalarAsync(CancellationToken cancellationToken = default); + + public abstract void Prepare(); + + public abstract Task PrepareAsync(CancellationToken cancellationToken = default); + + public abstract void Cancel(); + + public DbBatchCommand CreateBatchCommand() => CreateDbBatchCommand(); + + protected virtual DbBatchCommand CreateDbBatchCommand() => throw new NotSupportedException(); + + public virtual void Dispose() {} + + public virtual ValueTask DisposeAsync() + { + Dispose(); + return default; + } + } +} diff --git a/src/libraries/System.Data.Common/src/System/Data/Common/DbBatchCommand.cs b/src/libraries/System.Data.Common/src/System/Data/Common/DbBatchCommand.cs new file mode 100644 index 00000000000000..8fbe80a30efbf3 --- /dev/null +++ b/src/libraries/System.Data.Common/src/System/Data/Common/DbBatchCommand.cs @@ -0,0 +1,23 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.ComponentModel; +using System.Diagnostics.CodeAnalysis; + +namespace System.Data.Common +{ + public abstract class DbBatchCommand + { + public abstract string CommandText { get; set; } + + public abstract CommandType CommandType { get; set; } + + public abstract CommandBehavior CommandBehavior { get; set; } + + public abstract int RecordsAffected { get; set; } + + public DbParameterCollection Parameters => DbParameterCollection; + + protected abstract DbParameterCollection DbParameterCollection { get; } + } +} diff --git a/src/libraries/System.Data.Common/src/System/Data/Common/DbBatchCommandCollection.cs b/src/libraries/System.Data.Common/src/System/Data/Common/DbBatchCommandCollection.cs new file mode 100644 index 00000000000000..736cc5cbb093f6 --- /dev/null +++ b/src/libraries/System.Data.Common/src/System/Data/Common/DbBatchCommandCollection.cs @@ -0,0 +1,37 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Collections; +using System.Collections.Generic; + +namespace System.Data.Common +{ + public abstract class DbBatchCommandCollection : IList + { + public abstract IEnumerator GetEnumerator(); + + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); + + public abstract void Add(DbBatchCommand item); + + public abstract void Clear(); + + public abstract bool Contains(DbBatchCommand item); + + public abstract void CopyTo(DbBatchCommand[] array, int arrayIndex); + + public abstract bool Remove(DbBatchCommand item); + + public abstract int Count { get; } + + public abstract bool IsReadOnly { get; } + + public abstract int IndexOf(DbBatchCommand item); + + public abstract void Insert(int index, DbBatchCommand item); + + public abstract void RemoveAt(int index); + + public abstract DbBatchCommand this[int index] { get; set; } + } +} diff --git a/src/libraries/System.Data.Common/src/System/Data/Common/DbConnection.cs b/src/libraries/System.Data.Common/src/System/Data/Common/DbConnection.cs index a749668b456770..d983aad07c71bf 100644 --- a/src/libraries/System.Data.Common/src/System/Data/Common/DbConnection.cs +++ b/src/libraries/System.Data.Common/src/System/Data/Common/DbConnection.cs @@ -128,6 +128,12 @@ public virtual Task ChangeDatabaseAsync(string databaseName, CancellationToken c } } + public virtual bool CanCreateBatch => false; + + public DbBatch CreateBatch() => CreateDbBatch(); + + protected virtual DbBatch CreateDbBatch() => throw new NotSupportedException(); + public DbCommand CreateCommand() => CreateDbCommand(); IDbCommand IDbConnection.CreateCommand() => CreateDbCommand(); diff --git a/src/libraries/System.Data.Common/src/System/Data/Common/DbException.cs b/src/libraries/System.Data.Common/src/System/Data/Common/DbException.cs index 25bebd95cd50ae..ccc1f629b9b0bd 100644 --- a/src/libraries/System.Data.Common/src/System/Data/Common/DbException.cs +++ b/src/libraries/System.Data.Common/src/System/Data/Common/DbException.cs @@ -41,5 +41,9 @@ protected DbException(System.Runtime.Serialization.SerializationInfo info, Syste /// A standard SQL 5-character return code, or . /// public virtual string? SqlState => null; + + public DbBatchCommand? BatchCommand => DbBatchCommand; + + public virtual DbBatchCommand? DbBatchCommand { get; } } } diff --git a/src/libraries/System.Data.Common/src/System/Data/Common/DbProviderFactory.cs b/src/libraries/System.Data.Common/src/System/Data/Common/DbProviderFactory.cs index 6065bc6acd8e22..7282338b5407a4 100644 --- a/src/libraries/System.Data.Common/src/System/Data/Common/DbProviderFactory.cs +++ b/src/libraries/System.Data.Common/src/System/Data/Common/DbProviderFactory.cs @@ -13,6 +13,8 @@ public abstract partial class DbProviderFactory protected DbProviderFactory() { } + public virtual bool CanCreateBatch => false; + public virtual bool CanCreateDataSourceEnumerator => false; public virtual bool CanCreateDataAdapter @@ -47,6 +49,10 @@ public virtual bool CanCreateCommandBuilder } } + public virtual DbBatch CreateBatch() => throw new NotSupportedException(); + + public virtual DbBatchCommand CreateBatchCommand() => throw new NotSupportedException(); + public virtual DbCommand? CreateCommand() => null; public virtual DbCommandBuilder? CreateCommandBuilder() => null; From ca73eb264142706bc49a7c0abf3d21a3df9e2c14 Mon Sep 17 00:00:00 2001 From: Shay Rojansky Date: Mon, 21 Jun 2021 15:47:51 +0300 Subject: [PATCH 2/6] Fix connection/transaction delegation --- .../src/System/Data/Common/DbBatch.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/libraries/System.Data.Common/src/System/Data/Common/DbBatch.cs b/src/libraries/System.Data.Common/src/System/Data/Common/DbBatch.cs index acd9f073190176..0896adcc8fcf09 100644 --- a/src/libraries/System.Data.Common/src/System/Data/Common/DbBatch.cs +++ b/src/libraries/System.Data.Common/src/System/Data/Common/DbBatch.cs @@ -14,11 +14,19 @@ public abstract class DbBatch : IDisposable, IAsyncDisposable public abstract int Timeout { get; set; } - public DbConnection? Connection { get; set; } + public DbConnection? Connection + { + get => DbConnection; + set => DbConnection = value; + } protected abstract DbConnection? DbConnection { get; set; } - public DbTransaction? Transaction { get; set; } + public DbTransaction? Transaction + { + get => DbTransaction; + set => DbTransaction = value; + } protected abstract DbTransaction? DbTransaction { get; set; } From 4e8bfe7109fd2127c50bd1f4b60e0fc39dbd01ff Mon Sep 17 00:00:00 2001 From: Shay Rojansky Date: Mon, 21 Jun 2021 19:03:05 +0300 Subject: [PATCH 3/6] Make DbException.DbBatchCommand protected Thanks @ninofloris --- src/libraries/System.Data.Common/ref/System.Data.Common.cs | 2 +- .../System.Data.Common/src/System/Data/Common/DbException.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libraries/System.Data.Common/ref/System.Data.Common.cs b/src/libraries/System.Data.Common/ref/System.Data.Common.cs index c7ba6e482864d0..e49e8bd5361eb8 100644 --- a/src/libraries/System.Data.Common/ref/System.Data.Common.cs +++ b/src/libraries/System.Data.Common/ref/System.Data.Common.cs @@ -2421,7 +2421,7 @@ protected DbException(string? message, int errorCode) { } public virtual bool IsTransient { get { throw null; } } public virtual string? SqlState { get { throw null; } } public System.Data.Common.DbBatchCommand? BatchCommand { get { throw null; } } - public virtual System.Data.Common.DbBatchCommand? DbBatchCommand { get { throw null; } } + protected virtual System.Data.Common.DbBatchCommand? DbBatchCommand { get { throw null; } } } public static partial class DbMetaDataCollectionNames { diff --git a/src/libraries/System.Data.Common/src/System/Data/Common/DbException.cs b/src/libraries/System.Data.Common/src/System/Data/Common/DbException.cs index ccc1f629b9b0bd..55b0bce2fddc92 100644 --- a/src/libraries/System.Data.Common/src/System/Data/Common/DbException.cs +++ b/src/libraries/System.Data.Common/src/System/Data/Common/DbException.cs @@ -44,6 +44,6 @@ protected DbException(System.Runtime.Serialization.SerializationInfo info, Syste public DbBatchCommand? BatchCommand => DbBatchCommand; - public virtual DbBatchCommand? DbBatchCommand { get; } + protected virtual DbBatchCommand? DbBatchCommand => null; } } From 64f11337c1fae4acaf951d68268cc2ea60baffe3 Mon Sep 17 00:00:00 2001 From: Shay Rojansky Date: Tue, 29 Jun 2021 15:56:56 +0300 Subject: [PATCH 4/6] Move CommandBehavior from DbBatchCommand to DbBatch.ExecuteReader --- .../ref/System.Data.Common.cs | 8 ++++---- .../src/System/Data/Common/DbBatch.cs | 17 ++++++++++++----- .../src/System/Data/Common/DbBatchCommand.cs | 2 -- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/libraries/System.Data.Common/ref/System.Data.Common.cs b/src/libraries/System.Data.Common/ref/System.Data.Common.cs index e49e8bd5361eb8..4c866979a2f856 100644 --- a/src/libraries/System.Data.Common/ref/System.Data.Common.cs +++ b/src/libraries/System.Data.Common/ref/System.Data.Common.cs @@ -1928,10 +1928,11 @@ public abstract class DbBatch : System.IDisposable, System.IAsyncDisposable protected abstract System.Data.Common.DbConnection? DbConnection { get; set; } public System.Data.Common.DbTransaction? Transaction { get; set; } protected abstract System.Data.Common.DbTransaction? DbTransaction { get; set; } - public System.Data.Common.DbDataReader ExecuteReader() { throw null; } - protected abstract System.Data.Common.DbDataReader ExecuteDbDataReader(); + public System.Data.Common.DbDataReader ExecuteReader(System.Data.CommandBehavior behavior = System.Data.CommandBehavior.Default) { throw null; } + protected abstract System.Data.Common.DbDataReader ExecuteDbDataReader(System.Data.CommandBehavior behavior); public System.Threading.Tasks.Task ExecuteReaderAsync(System.Threading.CancellationToken cancellationToken = default) { throw null; } - protected abstract System.Threading.Tasks.Task ExecuteDbDataReaderAsync(System.Threading.CancellationToken cancellationToken); + public System.Threading.Tasks.Task ExecuteReaderAsync(System.Data.CommandBehavior behavior, System.Threading.CancellationToken cancellationToken = default) { throw null; } + protected abstract System.Threading.Tasks.Task ExecuteDbDataReaderAsync(System.Data.CommandBehavior behavior, System.Threading.CancellationToken cancellationToken); public abstract int ExecuteNonQuery(); public abstract System.Threading.Tasks.Task ExecuteNonQueryAsync(System.Threading.CancellationToken cancellationToken = default); public abstract object? ExecuteScalar(); @@ -1948,7 +1949,6 @@ public abstract class DbBatchCommand { public abstract string CommandText { get; set; } public abstract CommandType CommandType { get; set; } - public abstract CommandBehavior CommandBehavior { get; set; } public abstract int RecordsAffected { get; set; } public DbParameterCollection Parameters { get { throw null; } } protected abstract DbParameterCollection DbParameterCollection { get; } diff --git a/src/libraries/System.Data.Common/src/System/Data/Common/DbBatch.cs b/src/libraries/System.Data.Common/src/System/Data/Common/DbBatch.cs index 0896adcc8fcf09..4238ce1fdadc1b 100644 --- a/src/libraries/System.Data.Common/src/System/Data/Common/DbBatch.cs +++ b/src/libraries/System.Data.Common/src/System/Data/Common/DbBatch.cs @@ -30,15 +30,22 @@ public DbTransaction? Transaction protected abstract DbTransaction? DbTransaction { get; set; } - public DbDataReader ExecuteReader() - => ExecuteDbDataReader(); + public DbDataReader ExecuteReader(CommandBehavior behavior = CommandBehavior.Default) + => ExecuteDbDataReader(behavior); - protected abstract DbDataReader ExecuteDbDataReader(); + protected abstract DbDataReader ExecuteDbDataReader(CommandBehavior behavior); public Task ExecuteReaderAsync(CancellationToken cancellationToken = default) - => ExecuteDbDataReaderAsync(cancellationToken); + => ExecuteDbDataReaderAsync(CommandBehavior.Default, cancellationToken); - protected abstract Task ExecuteDbDataReaderAsync(CancellationToken cancellationToken); + public Task ExecuteReaderAsync( + CommandBehavior behavior, + CancellationToken cancellationToken = default) + => ExecuteDbDataReaderAsync(behavior, cancellationToken); + + protected abstract Task ExecuteDbDataReaderAsync( + CommandBehavior behavior, + CancellationToken cancellationToken); public abstract int ExecuteNonQuery(); diff --git a/src/libraries/System.Data.Common/src/System/Data/Common/DbBatchCommand.cs b/src/libraries/System.Data.Common/src/System/Data/Common/DbBatchCommand.cs index 8fbe80a30efbf3..018cf2363bd780 100644 --- a/src/libraries/System.Data.Common/src/System/Data/Common/DbBatchCommand.cs +++ b/src/libraries/System.Data.Common/src/System/Data/Common/DbBatchCommand.cs @@ -12,8 +12,6 @@ public abstract class DbBatchCommand public abstract CommandType CommandType { get; set; } - public abstract CommandBehavior CommandBehavior { get; set; } - public abstract int RecordsAffected { get; set; } public DbParameterCollection Parameters => DbParameterCollection; From dc741dd17b68f81ddee0b15ecc8b64bd7dcb665f Mon Sep 17 00:00:00 2001 From: Shay Rojansky Date: Thu, 1 Jul 2021 14:47:51 +0300 Subject: [PATCH 5/6] Made DbBatchCommand.RecordsAffected getter-only --- src/libraries/System.Data.Common/ref/System.Data.Common.cs | 2 +- .../System.Data.Common/src/System/Data/Common/DbBatchCommand.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libraries/System.Data.Common/ref/System.Data.Common.cs b/src/libraries/System.Data.Common/ref/System.Data.Common.cs index 4c866979a2f856..7972cdfcc6595f 100644 --- a/src/libraries/System.Data.Common/ref/System.Data.Common.cs +++ b/src/libraries/System.Data.Common/ref/System.Data.Common.cs @@ -1949,7 +1949,7 @@ public abstract class DbBatchCommand { public abstract string CommandText { get; set; } public abstract CommandType CommandType { get; set; } - public abstract int RecordsAffected { get; set; } + public abstract int RecordsAffected { get; } public DbParameterCollection Parameters { get { throw null; } } protected abstract DbParameterCollection DbParameterCollection { get; } } diff --git a/src/libraries/System.Data.Common/src/System/Data/Common/DbBatchCommand.cs b/src/libraries/System.Data.Common/src/System/Data/Common/DbBatchCommand.cs index 018cf2363bd780..fa6f306e5aaa0e 100644 --- a/src/libraries/System.Data.Common/src/System/Data/Common/DbBatchCommand.cs +++ b/src/libraries/System.Data.Common/src/System/Data/Common/DbBatchCommand.cs @@ -12,7 +12,7 @@ public abstract class DbBatchCommand public abstract CommandType CommandType { get; set; } - public abstract int RecordsAffected { get; set; } + public abstract int RecordsAffected { get; } public DbParameterCollection Parameters => DbParameterCollection; From 3b6a3ba8998682bcdfa74f719ec6274f4b5cb78e Mon Sep 17 00:00:00 2001 From: Shay Rojansky Date: Thu, 1 Jul 2021 14:51:57 +0300 Subject: [PATCH 6/6] Make DbBatch.CreateDbBatchCommand abstract --- src/libraries/System.Data.Common/ref/System.Data.Common.cs | 2 +- .../System.Data.Common/src/System/Data/Common/DbBatch.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libraries/System.Data.Common/ref/System.Data.Common.cs b/src/libraries/System.Data.Common/ref/System.Data.Common.cs index 7972cdfcc6595f..1bec60c93e3511 100644 --- a/src/libraries/System.Data.Common/ref/System.Data.Common.cs +++ b/src/libraries/System.Data.Common/ref/System.Data.Common.cs @@ -1941,7 +1941,7 @@ public abstract class DbBatch : System.IDisposable, System.IAsyncDisposable public abstract System.Threading.Tasks.Task PrepareAsync(System.Threading.CancellationToken cancellationToken = default); public abstract void Cancel(); public System.Data.Common.DbBatchCommand CreateBatchCommand() { throw null; } - protected virtual System.Data.Common.DbBatchCommand CreateDbBatchCommand() { throw null; } + protected abstract System.Data.Common.DbBatchCommand CreateDbBatchCommand(); public virtual void Dispose() { throw null; } public virtual System.Threading.Tasks.ValueTask DisposeAsync() { throw null; } } diff --git a/src/libraries/System.Data.Common/src/System/Data/Common/DbBatch.cs b/src/libraries/System.Data.Common/src/System/Data/Common/DbBatch.cs index 4238ce1fdadc1b..a3b6e352428ce7 100644 --- a/src/libraries/System.Data.Common/src/System/Data/Common/DbBatch.cs +++ b/src/libraries/System.Data.Common/src/System/Data/Common/DbBatch.cs @@ -63,7 +63,7 @@ protected abstract Task ExecuteDbDataReaderAsync( public DbBatchCommand CreateBatchCommand() => CreateDbBatchCommand(); - protected virtual DbBatchCommand CreateDbBatchCommand() => throw new NotSupportedException(); + protected abstract DbBatchCommand CreateDbBatchCommand(); public virtual void Dispose() {}