What are the advantages/disadvantages of using TransactionScope in comparison to IDbTransaction? I will suggest some - please correct/complete the list.
Advantages of TransactionScope:
- TransactionScope supports distributed transactions - you can access several datasources or use several connections to one datasource inside one transaction.
- TransactionScope is more declarative: we can nest TransactionScopes and it is more pleasant to use it services layer (we do not have to handle IDbConnection and IDbTransaction by ourselves).
- I'm not sure about the third point, but here it is. IDbTransaction is specific to connection - you have to keep connection open during the whole transaction. I'm not sure whether connection/connections should be opened during the whole TransactionScope (please clarify it). If not, the following workflow is possible: start transaction, open connection - query - retrieve - close connection, execute resource-intensive computation (keeping connections closed), open connection - query - retrieve - close connection, ..., commit transaction. But I guess it is impossible an TransactionScope keeps connections open till commit.
Disadvantages of TransactionScope:
- It doesn't support IsolationLevel change during transaction.