Allow schema of destination table to be specified in CsvDataReader constructor #1435
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
IDataReader maps between the input source and the destination table using the schema details provided by GetSchemaTable(). Currently in CsvDataReader all columns are defaulted to strings which causes conversion issues when using as a source for SqlBulkCopy.
To remedy this I have added an additional constructor that accepts a DataTable along with the required CsvReader, this DataTable should contain the schema of the destination table and can be generated like so.
This will ensure that the correctly typed Get method will be used within the CsvDataReader.
A complete example can be seen here.