Why does Dapper's .Execute(...) return an int?

C#Sql ServerDapper

C# Problem Overview


Anyone know why Dapper returns an int from .Execute(...) ?

I can't find this documented anywhere.

C# Solutions


Solution 1 - C#

The integer represents the number of rows that were affected by your query.

It returns an integer so you know if your query has worked. If zero is returned and you expected something to have changed then you know there is a problem.

Solution 2 - C#

Because DbCommand.ExecuteNonQuery (which Dapper uses internally, no doubt) returns an int for the number of rows affected. Why? Because it's more or less free, and is about the only thing that you can reasonably return for a generic INSERT or UPDATE.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionDrew RView Question on Stackoverflow
Solution 1 - C#CathalMFView Answer on Stackoverflow
Solution 2 - C#Mark BrackettView Answer on Stackoverflow