mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-08-24 07:22:57 +08:00
Update README.md
This commit is contained in:
parent
834e82ffd0
commit
a65d13ef7c
30
README.md
30
README.md
@ -102,3 +102,33 @@ db.BeginTran();
|
|||||||
|
|
||||||
db.CommitTran();
|
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…
Reference in New Issue
Block a user