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

Allow parameters passed by ICustomQueryParameter/IDynamicParameters to be reused #952

Merged
merged 2 commits into from
May 9, 2021

Conversation

jamescrowley
Copy link
Contributor

@jamescrowley jamescrowley commented Feb 20, 2018

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?

…ve them

from any commands that are created prior to calling Dispose (as that is not
sufficient). This will allow use cases where queries are retried (using Polly)
for instance, and the parameters are being passed via IDynamicParameters
or ICustomQueryParameter
@jamescrowley jamescrowley changed the title Allow parameters passed by ICustomParameters to be reused Allow parameters passed by ICustomQueryParameter/IDynamicParameters to be reused Feb 20, 2018
@NickCraver NickCraver changed the base branch from master to main June 20, 2020 13:25
Copy link
Member

@NickCraver NickCraver left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good here - thanks for the fix and the pointers at EF!

@NickCraver NickCraver merged commit 956dafe into DapperLib:main May 9, 2021
NickCraver pushed a commit that referenced this pull request May 9, 2021
@mkjeff
Copy link

mkjeff commented Aug 30, 2023

is it possible to fix the asynchronous version as well

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

Successfully merging this pull request may close these issues.

None yet

3 participants