|
@ -307,32 +307,12 @@ public int TestId { get; set; } |
|
|
## 6. Use Tran |
|
|
## 6. Use Tran |
|
|
```c |
|
|
```c |
|
|
|
|
|
|
|
|
//1. no result |
|
|
var dt2 = db.Ado.UseStoredProcedure().GetDataTable("sp_school",new{p1=1,p2=null}); |
|
|
var result = db.UseTran(() => |
|
|
|
|
|
{ |
|
|
|
|
|
db.Ado.ExecuteCommand("delete student"); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//2 has result |
|
|
|
|
|
var result2 = db.UseTran<List<Student>>(() => |
|
|
|
|
|
{ |
|
|
|
|
|
return db.Queryable<Student>().ToList(); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//3 use try |
|
|
//支持output |
|
|
try |
|
|
var p11 = new SugarParameter("@p1", "1"); |
|
|
{ |
|
|
var p22 = new SugarParameter("@p2", null, true);//isOutput=true |
|
|
db.Ado.BeginTran(); |
|
|
var dt2 = db.Ado.UseStoredProcedure().GetDataTable("sp_school",p11,p22); |
|
|
xxxx |
|
|
|
|
|
db.Ado.CommitTran(); |
|
|
|
|
|
} |
|
|
|
|
|
catch (Exception) |
|
|
|
|
|
{ |
|
|
|
|
|
db.Ado.RollbackTran(); |
|
|
|
|
|
throw; |
|
|
|
|
|
} |
|
|
|
|
|
``` |
|
|
``` |
|
|
## 7. Use Store Procedure |
|
|
## 7. Use Store Procedure |
|
|
```c |
|
|
```c |
|
|