Link Search Menu Expand Document

MariaDbBulkImportIdentityBehavior


This enum defines the behavior of the identity property/column when an entity is bulk-imported into a target table. It applies only to RepoDb.MariaDbConnector.BulkOperations (the MySqlConnector-based driver).

Enum Values

NameDescription
KeepIdentityThe identity column is left out of the write, so the target table’s own AUTO_INCREMENT generates it as usual. (This is the default value)
ReturnIdentityThe newly generated (or, for BulkMerge, matched) identity value is set back on the entity.

Usability

This enum is used by both the BulkInsert and BulkMerge operations. Pass the value to the identityBehavior argument when calling the operation.

For BulkInsert:

using (var connection = new MariaDbConnection(connectionString))
{
    var people = GetPeople(1000);
    var insertedRows = connection.BulkInsert(people,
        identityBehavior: MariaDbBulkImportIdentityBehavior.ReturnIdentity);
}

For BulkMerge:

using (var connection = new MariaDbConnection(connectionString))
{
    var people = GetPeople(1000);
    var mergedRows = connection.BulkMerge(people,
        identityBehavior: MariaDbBulkImportIdentityBehavior.ReturnIdentity);
}

Requesting ReturnIdentity requires AllowUserVariables=True on your MariaDbConnector connection string, since the underlying implementation relies on session user variables to pre-assign and read back the generated values. See Identity Setting Alignment for details.