Skip to content

Commit

Permalink
add missing APIs to BulkCopy
Browse files Browse the repository at this point in the history
  • Loading branch information
mgravell committed Aug 30, 2019
1 parent b663914 commit ed90d66
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
26 changes: 24 additions & 2 deletions Dapper.ProviderTools/BulkCopy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,20 @@ public abstract class BulkCopy : IDisposable
return DynamicBulkCopy.Create(obj);
}

/// <summary>
/// Create a BulkCopy instance for the connection provided
/// </summary>
public static BulkCopy Create(DbConnection connection)
{
var bcp = TryCreate(connection);
if (bcp == null)
{
if (connection == null) throw new ArgumentNullException(nameof(connection));
throw new NotSupportedException("Unable to create BulkCopy for " + connection.GetType().FullName);
}
return bcp;
}

/// <summary>
/// Provide an external registration for a given connection type
/// </summary>
Expand Down Expand Up @@ -74,15 +88,23 @@ private static readonly ConcurrentDictionary<Type, Func<DbConnection, object>?>
/// <summary>
/// Write a set of data to the server
/// </summary>
public abstract void WriteToServer(DataRow[] source);
/// <summary>
/// Write a set of data to the server
/// </summary>
public abstract void WriteToServer(IDataReader source);
/// <summary>
/// Write a set of data to the server
/// </summary>
public abstract Task WriteToServerAsync(DbDataReader source, CancellationToken cancellationToken);
public abstract Task WriteToServerAsync(DbDataReader source, CancellationToken cancellationToken = default);
/// <summary>
/// Write a set of data to the server
/// </summary>
public abstract Task WriteToServerAsync(DataTable source, CancellationToken cancellationToken = default);
/// <summary>
/// Write a set of data to the server
/// </summary>
public abstract Task WriteToServerAsync(DataTable source, CancellationToken cancellationToken);
public abstract Task WriteToServerAsync(DataRow[] source, CancellationToken cancellationToken = default);
/// <summary>
/// Add a mapping between two columns by name
/// </summary>
Expand Down
4 changes: 4 additions & 0 deletions Dapper.ProviderTools/Internal/DynamicBulkCopy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public override void AddColumnMapping(int sourceColumn, int destinationColumn)

public override void WriteToServer(DataTable source)
=> _wrapped.WriteToServer(source);
public override void WriteToServer(DataRow[] source)
=> _wrapped.WriteToServer(source);

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

public override Task WriteToServerAsync(DataTable source, CancellationToken cancellationToken)
=> _wrapped.WriteToServer(source, cancellationToken);
public override Task WriteToServerAsync(DataRow[] source, CancellationToken cancellationToken)
=> _wrapped.WriteToServer(source, cancellationToken);

protected override void Dispose(bool disposing)
{
Expand Down

0 comments on commit ed90d66

Please sign in to comment.