Skip to content

Commit 687df08

Browse files
authored
Merge pull request #18 from SebastianStehle/copy-timeout
Do not hardcode copy timeout.
2 parents 236bf15 + 5c6e2c7 commit 687df08

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

src/PhenX.EntityFrameworkCore.BulkInsert.SqlServer/SqlServerBulkInsertProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ CancellationToken ctk
4444
using var bulkCopy = new SqlBulkCopy(connection, SqlBulkCopyOptions.TableLock, sqlTransaction);
4545
bulkCopy.DestinationTableName = tableName;
4646
bulkCopy.BatchSize = options.BatchSize ?? 50_000;
47-
bulkCopy.BulkCopyTimeout = 60;
47+
bulkCopy.BulkCopyTimeout = options.GetCopyTimeoutInSeconds();
4848

4949
foreach (var prop in properties)
5050
{

src/PhenX.EntityFrameworkCore.BulkInsert/Options/BulkInsertOptions.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace PhenX.EntityFrameworkCore.BulkInsert.Options;
1+
namespace PhenX.EntityFrameworkCore.BulkInsert.Options;
22

33
/// <summary>
44
/// Bulk insert general options.
@@ -32,4 +32,14 @@ public class BulkInsertOptions
3232
/// </list>
3333
/// </summary>
3434
public int? BatchSize { get; set; }
35+
36+
/// <summary>
37+
/// The timeout to copy records.
38+
/// </summary>
39+
public TimeSpan CopyTimeout = TimeSpan.FromMinutes(10);
40+
41+
internal int GetCopyTimeoutInSeconds()
42+
{
43+
return Math.Max(0, (int)CopyTimeout.TotalSeconds);
44+
}
3545
}

0 commit comments

Comments
 (0)