Retrieving records affected by statement #17445
Labels
api-needs-work
API needs work before it is approved, it is NOT ready for implementation
area-System.Data
help wanted
[up-for-grabs] Good issue for external contributors
Milestone
DbDataRecord has a RecordsAffected property, which allows users to know how many rows were inserted/updated/deleted. However, when executing a multi-statement command (e.g.
UPDATE xxx; UPDATE xxx
), this property provides an aggregation of all rows across statements. There's no programmatic way to get records affected per statement.For an example of why this might be useful, see EFCore's modification command batch. One of EFCore's major new features are command batching (i.e. the use of multi-statement commands), but in order to implement optimistic concurrency it needs to know, for each command, how many records were affected. For SqlServer this is implemented by sending
SELECT @@ROWCOUNT
after each update, and parsing the results.PostgreSQL has no equivalent SQL query, so in Npgsql I actually developed a statement-by-statement RecordsAffected mechanism to support this. In a nutshell, a collection of NpgsqlStatements is exposed by NpgsqlDataReader, and each object has its own RecordsAffected. Let me know if you want more detail.
Note that this is somewhat related to #15375, where the possibility of a better API for command batching is discussed (the latter may/could also depend on multiple DbStatement instances being managed within a single DbCommand).
The text was updated successfully, but these errors were encountered: