-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathTransaction.cs
More file actions
35 lines (31 loc) · 825 Bytes
/
Transaction.cs
File metadata and controls
35 lines (31 loc) · 825 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// Copyright (c) Mondol. All rights reserved.
//
// Author: frank
// Email: frank@mondol.info
// Created: 2017-01-22
//
using System.Data;
namespace Mondol.DapperPoco
{
/// <summary>
/// Transaction object helps maintain transaction depth counts
/// </summary>
internal class Transaction : ITransaction
{
private DbContext _dbCtx;
public Transaction(DbContext dbCtx, IsolationLevel isolation = IsolationLevel.ReadCommitted)
{
_dbCtx = dbCtx;
dbCtx.BeginTransaction(isolation);
}
public void Complete()
{
_dbCtx.CommitTransaction();
_dbCtx = null;
}
public void Dispose()
{
_dbCtx?.RollbackTransaction();
}
}
}