-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
Copy pathPasswordLibServices.cs
90 lines (80 loc) · 2.81 KB
/
PasswordLibServices.cs
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
using System;
using System.Threading.Tasks;
using Blog.Core.Common;
using Blog.Core.Common.DB;
using Blog.Core.Common.Utility;
using Blog.Core.IRepository.Base;
using Blog.Core.IServices;
using Blog.Core.Model.Models;
using Blog.Core.Repository.UnitOfWorks;
using Blog.Core.Services.BASE;
using SqlSugar;
namespace Blog.Core.Services
{
public partial class PasswordLibServices : BaseServices<PasswordLib>, IPasswordLibServices
{
IBaseRepository<PasswordLib> _dal;
private readonly IUnitOfWorkManage _unitOfWorkManage;
private readonly ISqlSugarClient _db;
private SqlSugarScope db => _db as SqlSugarScope;
public PasswordLibServices(IBaseRepository<PasswordLib> dal, IUnitOfWorkManage unitOfWorkManage, ISqlSugarClient db)
{
this._dal = dal;
_unitOfWorkManage = unitOfWorkManage;
_db = db;
base.BaseDal = dal;
}
[UseTran(Propagation = Propagation.Required)]
public async Task<bool> TestTranPropagation2()
{
await _dal.Add(new PasswordLib()
{
PLID = IdGeneratorUtility.NextId(),
IsDeleted = false,
plAccountName = "aaa",
plCreateTime = DateTime.Now
});
return true;
}
[UseTran(Propagation = Propagation.Mandatory)]
public async Task<bool> TestTranPropagationNoTranError()
{
await _dal.Add(new PasswordLib()
{
IsDeleted = false,
plAccountName = "aaa",
plCreateTime = DateTime.Now
});
return true;
}
[UseTran(Propagation = Propagation.Nested)]
public async Task<bool> TestTranPropagationTran2()
{
await db.Insertable(new PasswordLib()
{
PLID = IdGeneratorUtility.NextId(),
IsDeleted = false,
plAccountName = "aaa",
plCreateTime = DateTime.Now
}).ExecuteReturnSnowflakeIdAsync();
//throw new Exception("测试嵌套事务异常回滚");
return true;
}
public async Task<bool> TestTranPropagationTran3()
{
Console.WriteLine("Begin Transaction Before:" + db.ContextID);
db.BeginTran();
Console.WriteLine("Begin Transaction After:" + db.ContextID);
Console.WriteLine("");
await db.Insertable(new PasswordLib()
{
PLID = IdGeneratorUtility.NextId(),
IsDeleted = false,
plAccountName = "aaa",
plCreateTime = DateTime.Now
}).ExecuteReturnSnowflakeIdAsync();
//throw new Exception("测试嵌套事务异常回滚");
return true;
}
}
}