Skip to content

Commit ed90d66

Browse files
committed
add missing APIs to BulkCopy
1 parent b663914 commit ed90d66

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

Dapper.ProviderTools/BulkCopy.cs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,20 @@ public abstract class BulkCopy : IDisposable
3030
return DynamicBulkCopy.Create(obj);
3131
}
3232

33+
/// <summary>
34+
/// Create a BulkCopy instance for the connection provided
35+
/// </summary>
36+
public static BulkCopy Create(DbConnection connection)
37+
{
38+
var bcp = TryCreate(connection);
39+
if (bcp == null)
40+
{
41+
if (connection == null) throw new ArgumentNullException(nameof(connection));
42+
throw new NotSupportedException("Unable to create BulkCopy for " + connection.GetType().FullName);
43+
}
44+
return bcp;
45+
}
46+
3347
/// <summary>
3448
/// Provide an external registration for a given connection type
3549
/// </summary>
@@ -74,15 +88,23 @@ private static readonly ConcurrentDictionary<Type, Func<DbConnection, object>?>
7488
/// <summary>
7589
/// Write a set of data to the server
7690
/// </summary>
91+
public abstract void WriteToServer(DataRow[] source);
92+
/// <summary>
93+
/// Write a set of data to the server
94+
/// </summary>
7795
public abstract void WriteToServer(IDataReader source);
7896
/// <summary>
7997
/// Write a set of data to the server
8098
/// </summary>
81-
public abstract Task WriteToServerAsync(DbDataReader source, CancellationToken cancellationToken);
99+
public abstract Task WriteToServerAsync(DbDataReader source, CancellationToken cancellationToken = default);
100+
/// <summary>
101+
/// Write a set of data to the server
102+
/// </summary>
103+
public abstract Task WriteToServerAsync(DataTable source, CancellationToken cancellationToken = default);
82104
/// <summary>
83105
/// Write a set of data to the server
84106
/// </summary>
85-
public abstract Task WriteToServerAsync(DataTable source, CancellationToken cancellationToken);
107+
public abstract Task WriteToServerAsync(DataRow[] source, CancellationToken cancellationToken = default);
86108
/// <summary>
87109
/// Add a mapping between two columns by name
88110
/// </summary>

Dapper.ProviderTools/Internal/DynamicBulkCopy.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ public override void AddColumnMapping(int sourceColumn, int destinationColumn)
3232

3333
public override void WriteToServer(DataTable source)
3434
=> _wrapped.WriteToServer(source);
35+
public override void WriteToServer(DataRow[] source)
36+
=> _wrapped.WriteToServer(source);
3537

3638
public override void WriteToServer(IDataReader source)
3739
=> _wrapped.WriteToServer(source);
@@ -41,6 +43,8 @@ public override Task WriteToServerAsync(DbDataReader source, CancellationToken c
4143

4244
public override Task WriteToServerAsync(DataTable source, CancellationToken cancellationToken)
4345
=> _wrapped.WriteToServer(source, cancellationToken);
46+
public override Task WriteToServerAsync(DataRow[] source, CancellationToken cancellationToken)
47+
=> _wrapped.WriteToServer(source, cancellationToken);
4448

4549
protected override void Dispose(bool disposing)
4650
{

0 commit comments

Comments
 (0)