Browse Source

Delete SqlSugarClient thread safety compatibility

pull/8/head
sunkaixuna 3 years ago
parent
commit
22a38a1c66
  1. 12
      Src/Asp.Net/SqlSugar/Abstract/InsertableProvider/SubInserable.cs
  2. 47
      Src/Asp.Net/SqlSugar/SqlSugarClient.cs

12
Src/Asp.Net/SqlSugar/Abstract/InsertableProvider/SubInserable.cs

@ -72,12 +72,22 @@ namespace SqlSugar
} }
return resul; return resul;
} }
[Obsolete("use ExecuteCommand")] [Obsolete("use ExecuteCommand")]
public object ExecuteReturnPrimaryKey() public object ExecuteReturnPrimaryKey()
{ {
return ExecuteCommand(); return ExecuteCommand();
} }
public async Task<object> ExecuteCommandAsync()
{
object resut = 0;
await Task.Run(() =>
{
resut= ExecuteCommand();
});
return resut;
}
public object ExecuteCommand() public object ExecuteCommand()
{ {
var isNoTrean = this.Context.Ado.Transaction == null; var isNoTrean = this.Context.Ado.Transaction == null;
@ -126,7 +136,7 @@ namespace SqlSugar
return 0; return 0;
} }
} }
[Obsolete("use ExecuteCommandAsync")]
public Task<object> ExecuteReturnPrimaryKeyAsync() public Task<object> ExecuteReturnPrimaryKeyAsync()
{ {
return Task.FromResult(ExecuteReturnPrimaryKey()); return Task.FromResult(ExecuteReturnPrimaryKey());

47
Src/Asp.Net/SqlSugar/SqlSugarClient.cs

@ -826,32 +826,33 @@ namespace SqlSugar
{ {
result = NoSameThreadAndShard(); result = NoSameThreadAndShard();
} }
else if (IsSynchronization()) else
{ {
result = Synchronization(); result = Synchronization();
} }
else if (IsSingleInstanceAsync()) ///Because SqlSugarScope implements thread safety
{ //else if (IsSingleInstanceAsync())
result = Synchronization();//Async no support Single Instance //{
} // result = Synchronization();//Async no support Single Instance
else if (IsAsync()) //}
{ //else if (IsAsync())
result = Synchronization(); //{
} // result = Synchronization();
else //}
{ //else
StackTrace st = new StackTrace(true); //{
var methods = st.GetFrames(); // StackTrace st = new StackTrace(true);
var isAsync = UtilMethods.IsAnyAsyncMethod(methods); // var methods = st.GetFrames();
if (isAsync) // var isAsync = UtilMethods.IsAnyAsyncMethod(methods);
{ // if (isAsync)
result = Synchronization(); // {
} // result = Synchronization();
else // }
{ // else
result = NoSameThread(); // {
} // result = NoSameThread();
} // }
//}
if (result.Root == null) if (result.Root == null)
{ {
result.Root = this; result.Root = this;

Loading…
Cancel
Save