I know that, if I execute a single SQL statement that UPDATEs or DELETEs some data, that it will return the number of rows affected.
But if I have multiple SQL statements in a sql script, and I want to know the number of rows affected from the last statement executed, will it still return that automatically, or do I need a
var numberOfRowsAffected = context.ExecuteStoreCommand<int>(mySqlScript, parameters);
It depends on the
NOCOUNT setting when executing your quer(y/ies).
ON then no
DONE_IN_PROC messages will NOT be returned.
OFF, the default setting, then
DONE_IN_PROC messages will be returned, (eg. counts).
Both of these situations are different to executing,
which will return a result set with a single scalar value, different from a DONE_IN_PROC message. This will occur, regardless of the setting of
I believe that
SELECT @@ROWCOUNT is sometimes used to make Entity Framework "play" with more complex TSQL statements because EF both requires
Its important that
SELECT @@ROWCOUNT; is executed immediately after the last query statement because many statements will reset
@@ROWCOUNT and therefore yield an unexpected result.