'Dapper transactions throwing errors before commit
I'm executing some statements like this using Dapper (the connection is an NpgsqlConnection):
using var transaction = connection.BeginTransaction();
connection.Execute("INSERT INTO table1(id) VALUES (0);", transaction);
connection.Execute("invalid sql command", transaction);
transaction.Commit();
My understanding, based on various Dapper tutorials, was that all the statements should be committed at once when .Commit() is called, but I'm getting an NpgsqlException immediately when the second statement is executed. When I look at the database, the table is empty so the first statement is not committed either. Does Dapper automatically commit and rollback transactions for you and is it therefore unnecessary to manually call .Commit() and Rollback() when using Dapper?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
