I was wondering if its possible to run a TSQL query like Truncate Table x using Dapper?
What I've tried:
using (var con = DB.Connection)
{
    con.Open();
    var ret = con.Execute("Truncate Table [Y].[X]");
}
PS. I do not want to create a SP for it.
You seem to think that returning -1 indicates a problem. But according to the documentation Truncate:
Removes all rows from a table or specified partitions of a table, without logging the individual row deletions.
And Dapper's Execute method returns the rows affected.
So -1 seems reasonable to me.
Edit to add
After further investigation of the source code in GitHub, Dapper's Execute extension under-the-hood calls SqlMapper's ExecuteImpl, which (due to the way it's called can only go two ways; but basically both) ends up returning the result of IDbCommand's ExecuteNonQuery. So with that piece of the puzzle in place, Martin Smith's information from MSDN's ExecuteNonQuery applies:
For UPDATE, INSERT, and DELETE statements, the return value is the number of rows affected by the command. For all other types of statements, the return value is -1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With