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

Add an overload of SqlBulkCopy.WriteToServer that takes an IEnumerable<object[]> #142

Open
mburbea opened this issue Jul 29, 2019 · 2 comments
Labels
💡 Enhancement Issues that are feature requests for the drivers we maintain.

Comments

@mburbea
Copy link

mburbea commented Jul 29, 2019

Is your feature request related to a problem? Please describe.

Often I find myself needing to dump some content quickly into sql server, and map the columns sequentially. While I can create a DataRow[], or populate a DataTable, those remove the ability for me to stream data. Requiring me to buffer the entire dataset before sending it to the server.

The only solution that works that retains streaming is to create a DbDataReader and I often end up writing a simple adapter to do just that.

Which means I end writing something like::

await bulkCopy.WriteToServerAsync(new DbDataReaderAdapter(myData.Select(x=> new[]{
x.Field1,
...
x.ComplicatedThingy();
}, NumberOfColumns)), cancellationToken);

Describe the solution you'd like

I think adding the following methods would be ideal.

public class SqlBulkCopy
{
      public Task WriteToServerAsync(IEnumerable<object[]> rows, CancellationToken cancellationToken = default);
      public void WriteToServer(IEnumerable<object[]> rows);
}

This would save writing the adapter into my code base and get the desired result.
Ultimately, SqlBulkCopy only currently calls the following methods on a non SqlDataReader

bool Read();
int FieldCount {get;}
object GetValue(int ordinal);
bool IsDbNull(int ordinal);

Describe alternatives you've considered

There are obviously tools like SSIS and Import/Export wizard, but if I need to do this programatically (e.g. calling a webapi and dump the content), there's no easier way than sql bulk copy.

@cheenamalhotra
Copy link
Member

Hi @mburbea

We will definitely look into the enhancement sometime in future. Thanks for the suggestion!

@cheenamalhotra cheenamalhotra added the 💡 Enhancement Issues that are feature requests for the drivers we maintain. label Jul 31, 2019
@cheenamalhotra cheenamalhotra added this to the Future milestone Jul 31, 2019
@airbreather
Copy link

Another alternative: our team uses IEnumerable<SqlDataRecord> all the time for our TVPs. Perhaps SqlBulkCopy could take in one of those instead of IEnumerable<object[]>?

@cheenamalhotra cheenamalhotra removed this from the Future milestone Oct 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💡 Enhancement Issues that are feature requests for the drivers we maintain.
Projects
None yet
Development

No branches or pull requests

3 participants