Update Demo

This commit is contained in:
sunkaixuan 2019-05-05 16:56:03 +08:00
parent 56996fc04d
commit 621f42725f
4 changed files with 59 additions and 6 deletions

View File

@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SqlSugar;
namespace OrmTest
{
@ -10,9 +11,50 @@ namespace OrmTest
public static void Init()
{
DistributedTransactionExample();
SingletonPattern();//单例
DistributedTransactionExample();//分布式事务
}
private static void SingletonPattern()
{
Console.WriteLine("");
Console.WriteLine("#### Singleton Pattern Start ####");
Console.WriteLine("Db_Id:" + singleDb.ContextID);
Console.WriteLine("Db_Id:" + singleDb.ContextID);
var task = new Task(() =>
{
Console.WriteLine("Task DbId:" + singleDb.ContextID);
new Task(() =>
{
Console.WriteLine("_Task_Task DbId:" + singleDb.ContextID);
Console.WriteLine("_Task_Task DbId:" + singleDb.ContextID);
}).Start();
Console.WriteLine("Task DbId:" + singleDb.ContextID);
});
task.Start();
task.Wait();
System.Threading.Thread.Sleep(500);
Console.WriteLine(string.Join(",", singleDb.TempItems.Keys));
Console.WriteLine("#### Singleton Pattern end ####");
}
static SqlSugarClient singleDb = new SqlSugarClient(
new ConnectionConfig()
{
ConfigId = 1,
DbType = DbType.SqlServer,
ConnectionString = Config.ConnectionString,
InitKeyType = InitKeyType.Attribute,
IsAutoCloseConnection=true,
AopEvents = new AopEvents()
{
OnLogExecuting = (sql, p) => { Console.WriteLine(sql); }
}
});
private static void DistributedTransactionExample()
{
Console.WriteLine("");
@ -68,5 +110,8 @@ namespace OrmTest
Console.WriteLine("#### Distributed TransactionExample End ####");
}
}
}

View File

@ -51,9 +51,9 @@ namespace SqlSugar
/// Used for debugging errors or BUG,Used for debugging, which has an impact on Performance
/// </summary>
public SugarDebugger Debugger { get; set; }
[JsonIgnore]
public AopEvents AopEvents = new AopEvents();
public AopEvents AopEvents { get;set; }
}
public class AopEvents
{

View File

@ -24,7 +24,7 @@ namespace SqlSugar
}
public ConnectionConfig CurrentConnectionConfig { get; set; }
public Dictionary<string, object> TempItems { get; set; }
public Dictionary<string, object> TempItems { get { if (_TempItems == null) { _TempItems = new Dictionary<string, object>(); } return _TempItems; } set=>_TempItems=value; }
public bool IsSystemTablesConfig { get { return this.CurrentConnectionConfig.InitKeyType == InitKeyType.SystemTable; } }
public Guid ContextID { get; set; }
internal bool IsAsyncMethod { get; set; }
@ -36,7 +36,8 @@ namespace SqlSugar
#endregion
#region Fields
#region Fields
public Dictionary<string, object> _TempItems;
public QueueList _Queues;
protected ISqlBuilder _SqlBuilder;
protected ISqlSugarClient _Context { get; set; }

View File

@ -71,7 +71,7 @@ namespace SqlSugar
public QueueList Queues { get => this.Context.Queues; set => this.Context.Queues = value; }
public Dictionary<string, object> TempItems { get => this.Context.TempItems??new Dictionary<string, object>(); set => this.Context.TempItems = value; }
public Dictionary<string, object> TempItems { get => this.Context.TempItems; set => this.Context.TempItems = value; }
public IContextMethods Utilities { get => this.Context.Utilities; set => this.Context.Utilities = value; }
public IAdo Ado => this.Context.Ado;
@ -672,7 +672,14 @@ namespace SqlSugar
private void InitContext(ConnectionConfig config)
{
var aopIsNull = config.AopEvents == null;
if (aopIsNull)
{
config.AopEvents = new AopEvents();
}
_Context = new SqlSugarContext(config);
if (!aopIsNull)
_Context.Ado.IsEnableLogEvent = true;
this.CurrentConnectionConfig = config;
_ThreadId = Thread.CurrentThread.ManagedThreadId.ToString();
if (_MappingColumns == null)