Link Search Menu Expand Document

MySqlConnectorBulkImportIdentityBehavior


This enum defines the behavior of the identity property/column when an entity is bulk-imported into a target table. It applies only to MySqlConnector.

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 MySqlConnection(connectionString))
{
    var people = GetPeople(1000);
    var insertedRows = connection.BulkInsert(people,
        identityBehavior: MySqlConnectorBulkImportIdentityBehavior.ReturnIdentity);
}

For BulkMerge:

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

Requesting ReturnIdentity requires AllowUserVariables=True on your MySqlConnector 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.