Give SqlBulkCopy._rowsCopied a public getter
See original GitHub issueIs your feature request related to a problem? Please describe.
SqlBulkCopy has a private member field for the number of rows copied (_rowsCopied), which is incremented with each record copy operation. Currently, to make use of this in client code, the solution is either to use the SqlRowsCopiedEventHandler (cumbersome and potentially expensive); or use reflection to get the value out of the private member field (hacky).
Describe the solution you’d like
Create a public property backed by _rowsCopied with a public getter - SqlBulkCopy.RowsCopied { get { return _rowsCopied; } }.
Or replace _rowsCopied with a public property with a public getter - SqlBulkCopy.RowsCopied { get; }
Describe alternatives you’ve considered
The SqlRowsCopiedEventHandler; using reflection to get the value out of the private member field; doing a SQL COUNT() before and after copying.
Additional context
Doesn’t make sense to me to have a setter method for this property, but open to anyone’s justification for it they think there should be!
Class in question: https://github.com/dotnet/SqlClient/blob/master/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlBulkCopy.cs
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:6 (3 by maintainers)

Top Related StackOverflow Question
@cheenamalhotra - thank you for pushing this fix on v2.0. This is quite an important property exposure for
SqlBulkCopyclass that I mainly used on RepoDb.@cheenamalhotra Chances are, if they’re using BulkCopy it’s because they want to get the most performance possible for copying data. Attaching and handling an Event definitely slows down this process depending on how many times the event is fired or evaluated – as such, it’s a performance limitation.
I’d imagine that they use reflection after the BulkCopy process rather than having to incur a performance hit of handling the events during the copy process. In other words, they don’t care about tracking the progress; they just want to know at the end of the routine how many rows were copied.
Absent of handling the event, and storing the outcome, the best way to do this is through accessing the property by way of reflection (from what I understand).