diff --git a/src/NHibernate/AdoNet/DbBatchBatcher.cs b/src/NHibernate/AdoNet/DbBatchBatcher.cs
index 35e795d50c..4914a10776 100644
--- a/src/NHibernate/AdoNet/DbBatchBatcher.cs
+++ b/src/NHibernate/AdoNet/DbBatchBatcher.cs
@@ -66,15 +66,8 @@ private void LogBatchCommand(DbCommand batchUpdate)
private void AddCommandToBatch(DbCommand batchUpdate)
{
- var dbBatchCommand = _currentBatch.CreateBatchCommand();
- dbBatchCommand.CommandText = batchUpdate.CommandText;
- dbBatchCommand.CommandType = batchUpdate.CommandType;
-
- foreach (var param in batchUpdate.Parameters)
- {
- dbBatchCommand.Parameters.Add(((ICloneable) param).Clone());
- }
-
+ var dbBatchCommand = Driver.CreateDbBatchCommandFromDbCommand(_currentBatch, batchUpdate);
+
_currentBatch.BatchCommands.Add(dbBatchCommand);
}
diff --git a/src/NHibernate/Driver/DbProviderFactoryDriveConnectionCommandProvider.cs b/src/NHibernate/Driver/DbProviderFactoryDriveConnectionCommandProvider.cs
index 337ce6bf65..d177354845 100644
--- a/src/NHibernate/Driver/DbProviderFactoryDriveConnectionCommandProvider.cs
+++ b/src/NHibernate/Driver/DbProviderFactoryDriveConnectionCommandProvider.cs
@@ -28,7 +28,7 @@ public DbCommand CreateCommand()
#if NET6_0_OR_GREATER
public DbBatch CreateBatch() => dbProviderFactory.CreateBatch();
- public bool CanCreateBatch => dbProviderFactory.CanCreateBatch && dbProviderFactory.CreateCommand() is ICloneable;
+ public bool CanCreateBatch => dbProviderFactory.CanCreateBatch && dbProviderFactory.CreateCommand().CreateParameter() is ICloneable;
#endif
}
}
diff --git a/src/NHibernate/Driver/DriverBase.cs b/src/NHibernate/Driver/DriverBase.cs
index eaee002c60..74feae035b 100644
--- a/src/NHibernate/Driver/DriverBase.cs
+++ b/src/NHibernate/Driver/DriverBase.cs
@@ -371,6 +371,25 @@ public virtual DbBatch CreateBatch()
public virtual bool CanCreateBatch => false;
+ ///
+ /// Override to use a custom mechanism to create a from a .
+ /// The default implementation relies on the parameters implementing (and properly supporting)
+ ///
+ ///
+ ///
+ ///
+ public virtual DbBatchCommand CreateDbBatchCommandFromDbCommand(DbBatch dbBatch, DbCommand dbCommand)
+ {
+ var dbBatchCommand = dbBatch.CreateBatchCommand();
+ dbBatchCommand.CommandText = dbCommand.CommandText;
+ dbBatchCommand.CommandType = dbCommand.CommandType;
+
+ foreach (var param in dbCommand.Parameters)
+ {
+ dbBatchCommand.Parameters.Add(((ICloneable) param).Clone());
+ }
+ return dbBatchCommand;
+ }
#endif
diff --git a/src/NHibernate/Driver/IDriver.cs b/src/NHibernate/Driver/IDriver.cs
index 479166362f..ec77500dab 100644
--- a/src/NHibernate/Driver/IDriver.cs
+++ b/src/NHibernate/Driver/IDriver.cs
@@ -165,11 +165,46 @@ public interface IDriver
DateTime MinDate { get; }
#if NET6_0_OR_GREATER
+ ///
+ /// Create a
+ ///
+ ///
+ ///
DbBatch CreateBatch() => throw new NotImplementedException();
+
+ ///
+ /// Can this driver create es?
+ ///
bool CanCreateBatch => false;
+ ///
+ /// Make any adjustments to each object before it is added to the batcher.
+ ///
+ /// The batch.
+ ///
+ /// This method should be executed before adding each single batch to the batcher.
+ /// If you have to adjust parameters values/type (when the command is fullfilled) this is a good place to do it.
+ ///
void AdjustBatch(DbBatch dbBatch) => throw new NotImplementedException();
+
+ ///
+ /// Prepare the by calling .
+ /// May be a no-op if the driver does not support preparing commands, or for any other reason.
+ ///
+ /// The batch.
void PrepareBatch(DbBatch dbBatch) => throw new NotImplementedException();
+
+ ///
+ /// Creates (clones) a from a ,
+ /// copying its ,
+ /// and all its parameters.
+ /// The returned will not be added to
+ ///
+ ///
+ ///
+ ///
+ ///
+ DbBatchCommand CreateDbBatchCommandFromDbCommand(DbBatch dbBatch, DbCommand dbCommand) => throw new NotImplementedException();
#endif
}
}
diff --git a/src/NHibernate/Driver/ReflectionDriveConnectionCommandProvider.cs b/src/NHibernate/Driver/ReflectionDriveConnectionCommandProvider.cs
index b4705f6a4e..7ff2705c0c 100644
--- a/src/NHibernate/Driver/ReflectionDriveConnectionCommandProvider.cs
+++ b/src/NHibernate/Driver/ReflectionDriveConnectionCommandProvider.cs
@@ -25,7 +25,7 @@ public ReflectionDriveConnectionCommandProvider(System.Type connectionType, Syst
_canCreateBatch = new Lazy(() => {
using (var connection = CreateConnection())
{
- return connection.CanCreateBatch && connection.CreateCommand() is ICloneable;
+ return connection.CanCreateBatch && connection.CreateCommand().CreateParameter() is ICloneable;
}
});
#endif