MySqlConnector icon indicating copy to clipboard operation
MySqlConnector copied to clipboard

MySqlBulkCopy Column Mappings Set

Open InvincibleDRT opened this issue 1 year ago • 5 comments
trafficstars

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;}

InvincibleDRT avatar Mar 15 '24 00:03 InvincibleDRT

It sounds like you're asking for bulkCopy.ColumnMappings = myList;.

Instead of doing that, can you use bulkCopy.ColumnMappings.AddRange(myList);?

bgrainger avatar Mar 15 '24 12:03 bgrainger

(The reason for the current design is that it allows object + collection initialization syntax.)

bgrainger avatar Mar 15 '24 12:03 bgrainger

I have tried that syntax as well. This is the error i see image

AddRange worked. But may be you can default to column mapping in DataTable instead of defaulting to mapping from table in db!?

InvincibleDRT avatar Mar 15 '24 13:03 InvincibleDRT

With something like this var mappings = (from DataColumn col in dt.Columns select new MySqlBulkCopyColumnMapping(col.Ordinal, col.ColumnName)).ToList();

InvincibleDRT avatar Mar 15 '24 13:03 InvincibleDRT

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?

bgrainger avatar Mar 17 '24 23:03 bgrainger

Closing since its duplicate

InvincibleDRT avatar Apr 30 '24 21:04 InvincibleDRT