Debugging has perfect functions

This commit is contained in:
sunkaixuan 2019-01-25 21:45:15 +08:00
parent 0d89bf7caf
commit b3f7fc29d1
10 changed files with 69 additions and 12 deletions

View File

@ -7,7 +7,7 @@ using System.Text;
namespace OrmTest.Demo namespace OrmTest.Demo
{ {
public class IInsertOrUpdate : DemoBase public class InsertOrUpdate : DemoBase
{ {
public static void Init() public static void Init()
{ {

View File

@ -0,0 +1,51 @@
using OrmTest.Demo;
using OrmTest.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OrmTest.Demo
{
public class Debugger : DemoBase
{
public static void Init()
{
var db = GetInstance();
db.CurrentConnectionConfig.Debugger = new SqlSugar.SugarDebugger() { EnableThreadSecurityValidation = true };
db.Queryable<Student>().ToList();
db.Queryable<Student>().ToListAsync().Wait();
db.Insertable<Student>(new Student() { Name = "a" }).ExecuteCommandAsync();
db.Updateable<Student>(new Student() { Name = "a" }).ExecuteCommandAsync();
db.Deleteable<Student>(1111).ExecuteCommandAsync();
try
{
var task = new Task(() =>
{
try
{
//error
db.Queryable<Student>().ToList();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
});
task.Start();
task.Wait();
}
finally
{
}
}
}
}

View File

@ -60,7 +60,8 @@ namespace OrmTest
Demo.ExtEntity.Init(); Demo.ExtEntity.Init();
Demo.VersionValidation.Init(); Demo.VersionValidation.Init();
Demo.Delete.Init(); Demo.Delete.Init();
Demo.IInsertOrUpdate.Init(); Demo.InsertOrUpdate.Init();
Demo.Debugger.Init();
} }
} }
} }

View File

@ -58,7 +58,8 @@
<Compile Include="BugTest\BugModels\tLogonHistoryModel.cs" /> <Compile Include="BugTest\BugModels\tLogonHistoryModel.cs" />
<Compile Include="BugTest\BugModels\VipAccountsModel.cs" /> <Compile Include="BugTest\BugModels\VipAccountsModel.cs" />
<Compile Include="BugTest\BugModels\VipBenefitsModel.cs" /> <Compile Include="BugTest\BugModels\VipBenefitsModel.cs" />
<Compile Include="Demos\IInsertOrUpdate.cs" /> <Compile Include="Demos\I_InsertOrUpdate.cs" />
<Compile Include="Demos\J_Debugger.cs" />
<Compile Include="Models\Brand.cs" /> <Compile Include="Models\Brand.cs" />
<Compile Include="BugTest\Bug1.cs" /> <Compile Include="BugTest\Bug1.cs" />
<Compile Include="Models\VendorAndBrand.cs" /> <Compile Include="Models\VendorAndBrand.cs" />

View File

@ -675,19 +675,19 @@ namespace SqlSugar
} }
public virtual void ExecuteBefore(string sql, SugarParameter[] parameters) public virtual void ExecuteBefore(string sql, SugarParameter[] parameters)
{ {
if (this.Context.CurrentConnectionConfig.Debugger != null && this.Context.CurrentConnectionConfig.Debugger.EnableThreadSecurityValidation == true) { if (this.Context.IsAsyncMethod==false&&this.Context.CurrentConnectionConfig.Debugger != null && this.Context.CurrentConnectionConfig.Debugger.EnableThreadSecurityValidation == true) {
var processId = Process.GetCurrentProcess().Id; var contextId =this.Context.ContextID.ToString();
var contextId = this.Context.ContextID.ToString(); var processId = Process.GetCurrentProcess().Id.ToString();
var cache = new ReflectionInoCacheService(); var cache = new ReflectionInoCacheService();
if (!cache.ContainsKey<int>(contextId)) if (!cache.ContainsKey<string>(processId))
{ {
cache.Add(contextId, processId); cache.Add(processId, contextId);
} }
else { else {
var cacheValue = cache.Get<int>(contextId); var cacheValue = cache.Get<string>(processId);
if (processId != cacheValue) { if (contextId != cacheValue) {
new SqlSugarException(this.Context,ErrorMessage.GetThrowMessage("Detection of SqlSugarClient cross-threading usage,a thread needs a new one", "检测到声名的SqlSugarClient跨线程使用请检查是否静态、是否单例、或者IOC配置错误引起的保证一个线程new出一个对象 具本Sql:")+sql,parameters); throw new SqlSugarException(this.Context,ErrorMessage.GetThrowMessage("Detection of SqlSugarClient cross-threading usage,a thread needs a new one", "检测到声名的SqlSugarClient跨线程使用请检查是否静态、是否单例、或者IOC配置错误引起的保证一个线程new出一个对象 具本Sql:")+sql,parameters);
} }
} }
} }

View File

@ -378,6 +378,7 @@ namespace SqlSugar
{ {
var asyncContext = this.Context.Utilities.CopyContext(true); var asyncContext = this.Context.Utilities.CopyContext(true);
asyncContext.CurrentConnectionConfig.IsAutoCloseConnection = true; asyncContext.CurrentConnectionConfig.IsAutoCloseConnection = true;
asyncContext.IsAsyncMethod = true;
var asyncDeleteable = asyncContext.Deleteable<T>(); var asyncDeleteable = asyncContext.Deleteable<T>();
var asyncDeleteBuilder = asyncDeleteable.DeleteBuilder; var asyncDeleteBuilder = asyncDeleteable.DeleteBuilder;

View File

@ -425,7 +425,7 @@ namespace SqlSugar
{ {
var asyncContext = this.Context.Utilities.CopyContext(true); var asyncContext = this.Context.Utilities.CopyContext(true);
asyncContext.CurrentConnectionConfig.IsAutoCloseConnection = true; asyncContext.CurrentConnectionConfig.IsAutoCloseConnection = true;
asyncContext.IsAsyncMethod = true;
var asyncInsertable = asyncContext.Insertable<T>(this.InsertObjs); var asyncInsertable = asyncContext.Insertable<T>(this.InsertObjs);
var asyncInsertableBuilder = asyncInsertable.InsertBuilder; var asyncInsertableBuilder = asyncInsertable.InsertBuilder;
asyncInsertableBuilder.DbColumnInfoList = this.InsertBuilder.DbColumnInfoList; asyncInsertableBuilder.DbColumnInfoList = this.InsertBuilder.DbColumnInfoList;

View File

@ -1557,6 +1557,7 @@ namespace SqlSugar
protected ISugarQueryable<T> CopyQueryable() protected ISugarQueryable<T> CopyQueryable()
{ {
var asyncContext = this.Context.Utilities.CopyContext(true); var asyncContext = this.Context.Utilities.CopyContext(true);
asyncContext.IsAsyncMethod = true;
asyncContext.CurrentConnectionConfig.IsAutoCloseConnection = true; asyncContext.CurrentConnectionConfig.IsAutoCloseConnection = true;
var asyncQueryable = asyncContext.Queryable<ExpandoObject>().Select<T>(string.Empty).WithCacheIF(IsCache, CacheTime); var asyncQueryable = asyncContext.Queryable<ExpandoObject>().Select<T>(string.Empty).WithCacheIF(IsCache, CacheTime);
if (this.MapperAction != null) if (this.MapperAction != null)

View File

@ -526,6 +526,7 @@ namespace SqlSugar
{ {
var asyncContext = this.Context.Utilities.CopyContext(true); var asyncContext = this.Context.Utilities.CopyContext(true);
asyncContext.CurrentConnectionConfig.IsAutoCloseConnection = true; asyncContext.CurrentConnectionConfig.IsAutoCloseConnection = true;
asyncContext.IsAsyncMethod = true;
var asyncUpdateable = asyncContext.Updateable<T>(this.UpdateObjs); var asyncUpdateable = asyncContext.Updateable<T>(this.UpdateObjs);
var asyncUpdateableBuilder = asyncUpdateable.UpdateBuilder; var asyncUpdateableBuilder = asyncUpdateable.UpdateBuilder;

View File

@ -46,6 +46,7 @@ namespace SqlSugar
public Dictionary<string, object> TempItems { get; set; } public Dictionary<string, object> TempItems { get; set; }
public bool IsSystemTablesConfig { get { return this.CurrentConnectionConfig.InitKeyType == InitKeyType.SystemTable; } } public bool IsSystemTablesConfig { get { return this.CurrentConnectionConfig.InitKeyType == InitKeyType.SystemTable; } }
public Guid ContextID { get; set; } public Guid ContextID { get; set; }
internal bool IsAsyncMethod { get; set; }
public MappingTableList MappingTables = new MappingTableList(); public MappingTableList MappingTables = new MappingTableList();
public MappingColumnList MappingColumns = new MappingColumnList(); public MappingColumnList MappingColumns = new MappingColumnList();
public IgnoreColumnList IgnoreColumns = new IgnoreColumnList(); public IgnoreColumnList IgnoreColumns = new IgnoreColumnList();