Allow parameters passed by ICustomQueryParameter/IDynamicParameters to be reused #952
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.
Background
We wrap read-only Dapper calls in Polly to allow for retry strategies. We also use the IDynamicParameters and ICustomQueryParameter interface. Because we create our own db parameters, when re-trying, you get an exception "The SqlParameter is already contained by another SqlParameterCollection" unless you re-create the SqlParameters within the retry code block.
EF had a similar issue, and took this approach: dotnet/ef6#142, fixing dotnet/ef6#81
This PR
Prior to disposing of any command that is created, this PR now calls clear on the parameters collection. I believe this to be safe, given the library is about to dispose of the command in all these instances.
The new tests do not hit all the impacted methods, but have the basic requirement - not sure how you'd want to approach that?