MySqlBulkCopyColumnMapping class
Use MySqlBulkCopyColumnMapping
to specify how to map columns in the source data to columns in the destination table when using MySqlBulkCopy
.
Set SourceOrdinal
to the zero-based index of the source column to map. Set DestinationColumn
to either the name of a column in the destination table, or the name of a user-defined variable. If a user-defined variable, you can use Expression
to specify a MySQL expression that assigns its value to destination column.
Source columns that don’t have an entry in ColumnMappings
will be ignored (unless the ColumnMappings
collection is empty, in which case all columns will be mapped one-to-one).
MySqlConnector will transmit all binary data as hex, so any expression that operates on it must decode it with the UNHEX
function first. (This will be performed automatically if no Expression
is specified, but will be necessary to specify manually for more complex expressions.)
Example code:
new MySqlBulkCopyColumnMapping
{
SourceOrdinal = 2,
DestinationColumn = "user_name",
},
new MySqlBulkCopyColumnMapping
{
SourceOrdinal = 0,
DestinationColumn = "@tmp",
Expression = "column_value = @tmp * 2",
},
public sealed class MySqlBulkCopyColumnMapping
parameter | description |
---|---|
sourceOrdinal | The zero-based ordinal position of the source column. |
destinationColumn | The name of the destination column. |
expression | The optional expression to be used to set the destination column. |
Public Members
name | description |
---|---|
MySqlBulkCopyColumnMapping() | Initializes MySqlBulkCopyColumnMapping with the default values. |
MySqlBulkCopyColumnMapping(…) | Use MySqlBulkCopyColumnMapping to specify how to map columns in the source data to columns in the destination table when using MySqlBulkCopy . |
DestinationColumn { get; set; } | The name of the destination column to copy to. To use an expression, this should be the name of a unique user-defined variable. |
Expression { get; set; } | An optional expression for setting a destination column. To use an expression, the DestinationColumn should be set to the name of a user-defined variable and this expression should set a column using that variable. |
SourceOrdinal { get; set; } | The zero-based ordinal position of the source column to map from. |
See Also
- namespace MySqlConnector
- assembly MySqlConnector