mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-09-18 17:48:11 +08:00
Add Async Tran
This commit is contained in:
@@ -194,6 +194,27 @@ namespace OrmTest.Demo
|
|||||||
db.Ado.RollbackTran();
|
db.Ado.RollbackTran();
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//async tran
|
||||||
|
var asyncResult = db.Ado.UseTranAsync(() =>
|
||||||
|
{
|
||||||
|
|
||||||
|
var beginCount = db.Queryable<Student>().ToList();
|
||||||
|
db.Ado.ExecuteCommand("delete student");
|
||||||
|
var endCount = db.Queryable<Student>().Count();
|
||||||
|
throw new Exception("error haha");
|
||||||
|
});
|
||||||
|
asyncResult.Wait();
|
||||||
|
var asyncCount = db.Queryable<Student>().Count();
|
||||||
|
|
||||||
|
//async
|
||||||
|
var asyncResult2 = db.Ado.UseTranAsync<List<Student>>(() =>
|
||||||
|
{
|
||||||
|
return db.Queryable<Student>().ToList();
|
||||||
|
});
|
||||||
|
asyncResult2.Wait();
|
||||||
}
|
}
|
||||||
private static void Group()
|
private static void Group()
|
||||||
{
|
{
|
||||||
|
@@ -194,6 +194,17 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Task<DbResult<bool>> UseTranAsync(Action action)
|
||||||
|
{
|
||||||
|
Task<DbResult<bool>> result = new Task<DbResult<bool>>(() =>
|
||||||
|
{
|
||||||
|
return UseTran(action);
|
||||||
|
});
|
||||||
|
TaskStart(result);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
public DbResult<T> UseTran<T>(Func<T> action)
|
public DbResult<T> UseTran<T>(Func<T> action)
|
||||||
{
|
{
|
||||||
var result = new DbResult<T>();
|
var result = new DbResult<T>();
|
||||||
@@ -214,6 +225,17 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Task<DbResult<T>> UseTranAsync<T>(Func<T> action)
|
||||||
|
{
|
||||||
|
Task<DbResult<T>> result = new Task<DbResult<T>>(() =>
|
||||||
|
{
|
||||||
|
return UseTran(action);
|
||||||
|
});
|
||||||
|
TaskStart(result);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
public void UseStoredProcedure(Action action)
|
public void UseStoredProcedure(Action action)
|
||||||
{
|
{
|
||||||
var oldCommandType = this.CommandType;
|
var oldCommandType = this.CommandType;
|
||||||
@@ -624,6 +646,14 @@ namespace SqlSugar
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Helper
|
#region Helper
|
||||||
|
private void TaskStart<Type>(Task<Type> result)
|
||||||
|
{
|
||||||
|
if (this.Context.CurrentConnectionConfig.IsShardSameThread)
|
||||||
|
{
|
||||||
|
Check.Exception(true, "IsShardSameThread=true can't be used async method");
|
||||||
|
}
|
||||||
|
result.Start();
|
||||||
|
}
|
||||||
private void ExecuteProcessingSQL(ref string sql, SugarParameter[] parameters)
|
private void ExecuteProcessingSQL(ref string sql, SugarParameter[] parameters)
|
||||||
{
|
{
|
||||||
var result = this.ProcessingEventStartingSQL(sql, parameters);
|
var result = this.ProcessingEventStartingSQL(sql, parameters);
|
||||||
|
@@ -86,6 +86,9 @@ namespace SqlSugar
|
|||||||
|
|
||||||
DbResult<bool> UseTran(Action action);
|
DbResult<bool> UseTran(Action action);
|
||||||
DbResult<T> UseTran<T>(Func<T> action);
|
DbResult<T> UseTran<T>(Func<T> action);
|
||||||
|
Task<DbResult<bool>> UseTranAsync(Action action);
|
||||||
|
Task<DbResult<T>> UseTranAsync<T>(Func<T> action);
|
||||||
|
|
||||||
void UseStoredProcedure(Action action);
|
void UseStoredProcedure(Action action);
|
||||||
T UseStoredProcedure<T>(Func<T> action);
|
T UseStoredProcedure<T>(Func<T> action);
|
||||||
IAdo UseStoredProcedure();
|
IAdo UseStoredProcedure();
|
||||||
|
Reference in New Issue
Block a user