@@ -16,6 +16,8 @@ public class DataMerge : DisposableBase, IDataMerge
16
16
private readonly IDataSession _dataSession ;
17
17
private readonly DataMergeDefinition _mergeDefinition ;
18
18
19
+ private int _commandTimeout = 0 ;
20
+
19
21
/// <summary>
20
22
/// Initializes a new instance of the <see cref="DataMerge"/> class.
21
23
/// </summary>
@@ -137,6 +139,16 @@ public IDataMerge Mode(DataMergeMode mergeMode)
137
139
return this ;
138
140
}
139
141
142
+ /// <summary>
143
+ /// Sets the wait time before terminating the attempt to execute a command and generating an error.
144
+ /// </summary>
145
+ /// <param name="timeout">TThe time in seconds to wait for the command to execute.</param>
146
+ /// A fluent <see langword="interface" /> to a <see cref="DataMerge " /> operation.
147
+ public IDataMerge CommandTimeout ( int timeout )
148
+ {
149
+ _commandTimeout = timeout ;
150
+ return this ;
151
+ }
140
152
141
153
/// <summary>
142
154
/// Merges the specified <paramref name="data"/> into the <see cref="TargetTable"/>.
@@ -531,15 +543,17 @@ private void Merge(IDataReader reader, int rows, Action<DbCommand> executeFactor
531
543
}
532
544
533
545
// run merge statement
534
- using ( var mergeCommand = _dataSession . Connection . CreateCommand ( ) )
535
- {
536
- mergeCommand . CommandText = mergeSql ;
537
- mergeCommand . CommandType = CommandType . Text ;
538
- mergeCommand . Transaction = sqlTransaction ;
546
+ using var mergeCommand = _dataSession . Connection . CreateCommand ( ) ;
539
547
540
- // run merge with factory
541
- executeFactory ( mergeCommand ) ;
542
- }
548
+ mergeCommand . CommandText = mergeSql ;
549
+ mergeCommand . CommandType = CommandType . Text ;
550
+ mergeCommand . Transaction = sqlTransaction ;
551
+
552
+ if ( _commandTimeout > 0 )
553
+ mergeCommand . CommandTimeout = _commandTimeout ;
554
+
555
+ // run merge with factory
556
+ executeFactory ( mergeCommand ) ;
543
557
}
544
558
finally
545
559
{
@@ -614,6 +628,9 @@ await bulkCopy
614
628
mergeCommand . CommandType = CommandType . Text ;
615
629
mergeCommand . Transaction = sqlTransaction ;
616
630
631
+ if ( _commandTimeout > 0 )
632
+ mergeCommand . CommandTimeout = _commandTimeout ;
633
+
617
634
// run merge with factory
618
635
await executeFactory ( mergeCommand , cancellationToken )
619
636
. ConfigureAwait ( false ) ;
0 commit comments