Skip to content

Commit 0405be8

Browse files
committed
DefaultBulkOptions
1 parent 5d709f6 commit 0405be8

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

src/EntityFrameworkCore.SqlServer.SimpleBulks/Extensions/ConnectionContextExtensions.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ namespace EntityFrameworkCore.SqlServer.SimpleBulks.Extensions;
77

88
public static class ConnectionContextExtensions
99
{
10+
private static readonly BulkOptions DefaultBulkOptions = new BulkOptions()
11+
{
12+
BatchSize = 0,
13+
Timeout = 30,
14+
};
15+
1016
public static void EnsureOpen(this ConnectionContext connection)
1117
{
1218
var connectionState = connection.Connection.State;
@@ -39,11 +45,7 @@ public static void EnsureClosed(this ConnectionContext connection)
3945

4046
public static SqlCommand CreateTextCommand(this ConnectionContext connection, string commandText, BulkOptions options = null)
4147
{
42-
options ??= new BulkOptions()
43-
{
44-
BatchSize = 0,
45-
Timeout = 30,
46-
};
48+
options ??= DefaultBulkOptions;
4749

4850
var command = connection.Connection.CreateCommand();
4951
command.Transaction = connection.Transaction;

src/EntityFrameworkCore.SqlServer.SimpleBulks/Extensions/DataTableExtensions.cs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ namespace EntityFrameworkCore.SqlServer.SimpleBulks.Extensions;
99

1010
public static class DataTableExtensions
1111
{
12+
private static readonly BulkOptions DefaultBulkOptions = new BulkOptions()
13+
{
14+
BatchSize = 0,
15+
Timeout = 30,
16+
};
17+
1218
public static string GenerateTableDefinition(this DataTable table, string tableName,
1319
IReadOnlyDictionary<string, string> columnNameMappings,
1420
IReadOnlyDictionary<string, string> columnTypeMappings)
@@ -32,11 +38,7 @@ public static string GenerateTableDefinition(this DataTable table, string tableN
3238

3339
public static void SqlBulkCopy(this DataTable dataTable, string tableName, IReadOnlyDictionary<string, string> columnNameMappings, SqlConnection connection, SqlTransaction transaction, BulkOptions options = null)
3440
{
35-
options ??= new BulkOptions()
36-
{
37-
BatchSize = 0,
38-
Timeout = 30,
39-
};
41+
options ??= DefaultBulkOptions;
4042

4143
using var bulkCopy = new SqlBulkCopy(connection, SqlBulkCopyOptions.Default, transaction)
4244
{
@@ -55,11 +57,7 @@ public static void SqlBulkCopy(this DataTable dataTable, string tableName, IRead
5557

5658
public static async Task SqlBulkCopyAsync(this DataTable dataTable, string tableName, IReadOnlyDictionary<string, string> columnNameMappings, SqlConnection connection, SqlTransaction transaction, BulkOptions options = null, CancellationToken cancellationToken = default)
5759
{
58-
options ??= new BulkOptions()
59-
{
60-
BatchSize = 0,
61-
Timeout = 30,
62-
};
60+
options ??= DefaultBulkOptions;
6361

6462
using var bulkCopy = new SqlBulkCopy(connection, SqlBulkCopyOptions.Default, transaction)
6563
{

0 commit comments

Comments
 (0)