Dapper Transaction A Getting Started Tutorial to use Transaction
What's Dapper Transaction?
Dapper.Transaction is exactly like Dapper
but extend the IDbTransaction
interface instead and use Dapper
under the hood. It's a simple library to make it easier to work with a transaction.
- Dapper.Transaction is a simple and lightweight transaction management tool for Dapper.
- Everything
Dapper
support,Dapper Transaction
supports it as well (It's only a new extension method calling Dapper) - It was created to provide an easy way to manage transactions within the Dapper micro-ORM.
GitHub: https://github.com/zzzprojects/Dapper.Transaction
using (var connection = new SqlConnection(FiddleHelper.GetConnectionStringSqlServerW3Schools())) { connection.Open(); using (var transaction = connection.BeginTransaction()) { // Dapper var affectedRows1 = connection.Execute(sql, new {CustomerName = "Mark"}, transaction: transaction); // Dapper Transaction var affectedRows2 = transaction.Execute(sql, new {CustomerName = "Mark"}); transaction.Commit(); } }
NuGet Installation
Dapper.Transaction is only available through NuGet: https://www.nuget.org/packages/Dapper.Transaction/
You can easily install this library by running the following command:
PM> Install-Package Dapper-Transaction
Method Supported
- Execute
- ExecuteAsync
- ExecuteReader
- ExecuteReaderAsync
- ExecuteScalar
- ExecuteScalarAsync
- Query
- QueryAsync
- QueryFirst
- QueryFirstAsync
- QueryFirstOrDefault
- QueryFirstOrDefaultAsync
- QuerySingle
- QuerySingleAsync
- QuerySingleOrDefault
- QuerySingleOrDefaultAsync
- QueryMultiple
- QueryMultipleAsync
ZZZ Projects