MySqlConnector
MySqlConnector copied to clipboard
MySqlBulkCopy Column Mappings Set
Unable to pass in custom order of column in DataTable to bulkcopy. https://github.com/mysql-net/MySqlConnector/blob/d9e59c7995592c9ea11300382a6aa8914b5a60ab/src/MySqlConnector/MySqlBulkCopy.cs#L46
Describe the solution you'd like
Change public List<MySqlBulkCopyColumnMapping> ColumnMappings { get; } to public List<MySqlBulkCopyColumnMapping> ColumnMappings { get; set;}
It sounds like you're asking for bulkCopy.ColumnMappings = myList;.
Instead of doing that, can you use bulkCopy.ColumnMappings.AddRange(myList);?
(The reason for the current design is that it allows object + collection initialization syntax.)
I have tried that syntax as well. This is the error i see
AddRange worked. But may be you can default to column mapping in DataTable instead of defaulting to mapping from table in db!?
With something like this
var mappings = (from DataColumn col in dt.Columns select new MySqlBulkCopyColumnMapping(col.Ordinal, col.ColumnName)).ToList();
But may be you can default to column mapping in DataTable instead of defaulting to mapping from table in db!?
This may be a duplicate of https://github.com/mysql-net/MySqlConnector/issues/1375?
Closing since its duplicate