From a65d13ef7c4b80fbfcd9128c590d80759859dea1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9E=9C=E7=B3=96=E7=BD=91?= <610262374@qq.com> Date: Sun, 10 Oct 2021 22:37:27 +0800 Subject: [PATCH] Update README.md --- README.md | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/README.md b/README.md index 1dbaf0581..24abca4ed 100644 --- a/README.md +++ b/README.md @@ -102,3 +102,33 @@ db.BeginTran(); db.CommitTran(); ``` +### Singleton Pattern +Implement transactions across methods +```CS +public static SqlSugarScope Db = new SqlSugarScope(new ConnectionConfig() + { + DbType = SqlSugar.DbType.SqlServer, + ConnectionString = Config.ConnectionString, + IsAutoCloseConnection = true + }, + db=> { + //单例参数配置,所有上下文生效 + db.Aop.OnLogExecuting = (s, p) => + { + Console.WriteLine(s); + }; + }); + + + using (var tran = Db.UseTran()) + { + + //业务代码 + new Test2().Insert(XX); + new Test1().Insert(XX); + .....出错会自动回滚 + .... + + tran.CommitTran();//这个提交不能漏掉 + } +```