Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MySqlBulkCopy Column Mappings Set #1461

Closed
InvincibleDRT opened this issue Mar 15, 2024 · 6 comments
Closed

MySqlBulkCopy Column Mappings Set #1461

InvincibleDRT opened this issue Mar 15, 2024 · 6 comments

Comments

@InvincibleDRT
Copy link

Unable to pass in custom order of column in DataTable to bulkcopy.

public sealed class MySqlBulkCopy

Describe the solution you'd like
Change public List<MySqlBulkCopyColumnMapping> ColumnMappings { get; } to public List<MySqlBulkCopyColumnMapping> ColumnMappings { get; set;}

@bgrainger
Copy link
Member

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

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

@bgrainger
Copy link
Member

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

@InvincibleDRT
Copy link
Author

InvincibleDRT commented Mar 15, 2024

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
Copy link
Author

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

@bgrainger
Copy link
Member

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 #1375?

@InvincibleDRT
Copy link
Author

Closing since its duplicate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants