Link Search Menu Expand Document

OracleBulkArrayBinder


This class is an async, array-bind based alternative to OracleBulkCopy. ODP.NET’s OracleBulkCopy has no true async equivalent of OracleBulkCopy.WriteToServer(IDataReader) — unlike SqlBulkCopy for SQL Server, it exposes no genuinely asynchronous write API — so this class issues batched INSERT INTO ... VALUES (:p0, :p1, ...) statements with OracleCommand.ArrayBindCount set instead, executed via the real OracleCommand.ExecuteNonQueryAsync(CancellationToken).

It is part of RepoDb.Oracle.BulkOperations and implements IDisposable.

This is the class the library itself uses behind the Async overloads of BulkInsert and the staging-table load of BulkMerge, BulkUpdate, BulkDelete and BulkDeleteByKey. Using it directly is only necessary for a custom bulk-write path outside of those operations.

Properties

NameDescription
DestinationTableNameThe target table to write to.
BulkCopyTimeoutThe command timeout, in seconds, applied to every batch’s INSERT. Left at the driver default when not set.
BatchSizeThe number of rows bound per INSERT execution. When not set, it is derived automatically from the column count, capped by ODP.NET’s 65,535 bindable-parameter limit.
TransactionThe OracleTransaction each batch’s INSERT is enlisted in.
ColumnMappingsAn OracleBulkArrayBinderColumnMappingCollection of explicit source-to-destination column mappings. When left empty, columns are mapped by name.

Create a new Instance

using (var connection = new OracleConnection(connectionString))
{
    await connection.OpenAsync();

    using var arrayBinder = new OracleBulkArrayBinder(connection)
    {
        DestinationTableName = "Person",
        BatchSize = 1000,
        BulkCopyTimeout = 120
    };
}

Usability

Call BindArrayAsync() with either an IDataReader or a DataTable to write rows. Both overloads return the number of rows written.

Via an IDataReader (e.g. DataEntityDataReader):

using (var connection = new OracleConnection(connectionString))
{
    await connection.OpenAsync();

    var people = GetPeople(100000);
    using var reader = new DataEntityDataReader<Person>(people);
    using var arrayBinder = new OracleBulkArrayBinder(connection)
    {
        DestinationTableName = "Person"
    };

    var writtenRows = await arrayBinder.BindArrayAsync(reader);
}

Via a DataTable:

using (var connection = new OracleConnection(connectionString))
{
    await connection.OpenAsync();

    var table = GetPeopleAsDataTable();
    using var arrayBinder = new OracleBulkArrayBinder(connection)
    {
        DestinationTableName = "Person"
    };

    var writtenRows = await arrayBinder.BindArrayAsync(table);
}

With explicit column mappings:

using (var connection = new OracleConnection(connectionString))
{
    await connection.OpenAsync();

    using var arrayBinder = new OracleBulkArrayBinder(connection)
    {
        DestinationTableName = "Person"
    };
    arrayBinder.ColumnMappings.Add("FirstName", "FName");
    arrayBinder.ColumnMappings.Add("LastName", "LName");

    var people = GetPeople(100000);
    using var reader = new DataEntityDataReader<Person>(people);
    var writtenRows = await arrayBinder.BindArrayAsync(reader);
}

BatchSize, BulkCopyTimeout and Transaction behave the same way as their equivalents on OracleBulkCopy — only the write mechanism (array-bound INSERT statements instead of a native bulk-load stream) differs.