mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-04-05 17:37:58 +08:00
Update README.md
This commit is contained in:
parent
46c9bf8ba3
commit
a7c2252d33
32
README.md
32
README.md
@ -288,3 +288,35 @@ db.Queryable<T>().As("tableName").ToList();
|
||||
public int TestId { get; set; }
|
||||
```
|
||||
|
||||
## 6. Use Tran
|
||||
```c
|
||||
var db = GetInstance();
|
||||
//1. no result
|
||||
var result = db.UseTran(() =>
|
||||
{
|
||||
var beginCount = db.Queryable<Student>().Count();
|
||||
db.Ado.ExecuteCommand("delete student");
|
||||
var endCount = db.Queryable<Student>().Count();
|
||||
throw new Exception("error haha");
|
||||
});
|
||||
var count = db.Queryable<Student>().Count();
|
||||
|
||||
//2 has result
|
||||
var result2 = db.UseTran<List<Student>>(() =>
|
||||
{
|
||||
return db.Queryable<Student>().ToList();
|
||||
});
|
||||
|
||||
//3 use try
|
||||
try
|
||||
{
|
||||
db.Ado.BeginTran();
|
||||
|
||||
db.Ado.CommitTran();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
db.Ado.RollbackTran();
|
||||
throw;
|
||||
}
|
||||
```
|
||||
|
Loading…
Reference in New Issue
Block a user