-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Remarks for ExecuteNonQuery additional reasons to return -1 #1876
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
Conversation
Added a remark to ExecuteNonQuery for an additional reason for it to return -1 (the connection's NO COUNT is ON).
@divega, can you review this PR, please? |
Copying the proposed change (text added in bold) here to make the review easier :
I suggest to tweak it some something like this:
cc @David-Engel this is for SqlClient specifically, so you may want to review or ask someone in your team to review. cc @roji in case this is interesting for him. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@joelpaula, I'm sorry that it's taken so long for me to respond. Would you like to make the changes suggested by @divega?
Applying the changes suggested by @divega, to make it super clear how the NOCOUNT and other circumstances may affect the number of affected rows return by ExecuteNonQuery.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Content looks good to me.
Missed this back in February... It's definitely great to have this level of documentation on what actually happens in SqlClient. Just out of curiosity @divega: do the extra rows updated by triggers interfere with our optimistic concurrency in any way, or we are checking for zero vs. one or more rows updated? |
IIRC EF6 and EF Core check for exactly 1 record affected per intended change, but @AndriySvyryd may remember better than I 😄 Generally SET NOCOUNT ON as the first line of a trigger is considered the best practice. |
@roji We check for exactly 1 currently, but we could relax this. dotnet/efcore#12064 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you so much, @joelpaula, for contributing to the dotnet/dotnet-api-docs repo and enriching the documentation. I've left one minor suggestion for you to consider. Once you address it, I'll merge.
@AndriySvyryd it's just a thought, relaxing it seems like it would allow optimistic concurrency and rowcount-enabled triggers to work together. |
We could, but I think the recommendation to use SET NOCOUNT ON o triggers is reasonable and well-know (at least I remember learning about it since my RDO days), there is a risk that for UPDATE or DELETE statements to actually affect more than one row if you lie about the primary keys, plus I don't remember right now customers asking for it 😄 |
Co-Authored-By: joelpaula <joelpaula@hotmail.com>
@divega makes sense. |
Thanks, @joelpaula, for making the additional changes. I'll approve and merge your PR now. The changes should be live on docs.microsoft.com in the next day or two. |
Summary
Added a remark to ExecuteNonQuery for an additional reason for it to return -1 - the connection's NO COUNT is ON.