Browse Source

Update README.md

pull/8/head
果糖网 3 years ago
committed by GitHub
parent
commit
a65d13ef7c
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 30
      README.md

30
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();//这个提交不能漏掉
}
```

Loading…
Cancel
Save