using System; using System.Threading.Tasks; using DouyinApi.Common; using DouyinApi.Common.DB; using DouyinApi.Common.Utility; using DouyinApi.IRepository.Base; using DouyinApi.IServices; using DouyinApi.Model.Models; using DouyinApi.Repository.UnitOfWorks; using DouyinApi.Services.BASE; using SqlSugar; namespace DouyinApi.Services { public partial class PasswordLibServices : BaseServices, IPasswordLibServices { IBaseRepository _dal; private readonly IUnitOfWorkManage _unitOfWorkManage; private readonly ISqlSugarClient _db; private SqlSugarScope db => _db as SqlSugarScope; public PasswordLibServices(IBaseRepository dal, IUnitOfWorkManage unitOfWorkManage, ISqlSugarClient db) { this._dal = dal; _unitOfWorkManage = unitOfWorkManage; _db = db; base.BaseDal = dal; } [UseTran(Propagation = Propagation.Required)] public async Task 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 TestTranPropagationNoTranError() { await _dal.Add(new PasswordLib() { IsDeleted = false, plAccountName = "aaa", plCreateTime = DateTime.Now }); return true; } [UseTran(Propagation = Propagation.Nested)] public async Task 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 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; } } }