Link Search Menu Expand Document

MySqlConnectorBulkInsertMapItem


This class extends BulkInsertMapItem with an optional, explicit MySqlDbType to bind with for the mapped column. When not provided, the type is inferred from the entity property’s [MySqlDbType]/[MySqlConnectorDbTypeEx] attribute (if present) or, failing that, from the .NET CLR value itself.

Used by the BulkInsert, BulkMerge and BulkUpdate operations of RepoDb.MySqlConnector.BulkOperations.

Create a new Instance

var mapItem = new MySqlConnectorBulkInsertMapItem("SourceId", "DestinationId");

Or with an explicit MySqlDbType:

var mapItem = new MySqlConnectorBulkInsertMapItem("SourceName", "DestinationName", MySqlDbType.VarChar);

Usage for BulkOperations

var mappings = new []
{
    new MySqlConnectorBulkInsertMapItem("FirstName", "FName"),
    new MySqlConnectorBulkInsertMapItem("LastName", "LName"),
    new MySqlConnectorBulkInsertMapItem("Age", "Age", MySqlDbType.Int32)
};

using (var connection = new MySqlConnection(connectionString))
{
    var people = GetPeople(100000);
    connection.BulkInsert(people, mappings: mappings);
}

The same approach applies to BulkMerge and BulkUpdate. The mappings argument is optional — omitting it causes the library to auto-map columns by name (case-insensitive).