From c099ae4becf7f551d4685a32a60dc18f34ec482d Mon Sep 17 00:00:00 2001 From: sunkaixuna <610262374@qq.com> Date: Sat, 7 Aug 2021 05:14:29 +0800 Subject: [PATCH] Update demo --- .../SqlSeverTest/Demo/DemoH_Tenant.cs | 23 ++++++++----------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSeverTest/Demo/DemoH_Tenant.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSeverTest/Demo/DemoH_Tenant.cs index 7c0d71c16..9dd7d6da2 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSeverTest/Demo/DemoH_Tenant.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSeverTest/Demo/DemoH_Tenant.cs @@ -21,23 +21,16 @@ namespace OrmTest { public void Test() { - base.db.BeginTran(); + db.BeginTran(); base.GetList(); //调用内部仓储方法 base.ChangeRepository>().GetList();//调用外部仓储 - - base.db.CommitTran(); + db.CommitTran(); } } - - public class Repository : SimpleClient where T : class, new() { - public SqlSugarClient db; - public Repository(ISqlSugarClient context = null) : base(context)//注意这里要有默认值等于null - { - if (context == null) - { - var db = new SqlSugarClient(new List { + //单例实同db同上下文共享 + public static SqlSugarScope db = new SqlSugarScope(new List { new ConnectionConfig() { ConfigId="1", @@ -53,11 +46,13 @@ namespace OrmTest ConnectionString = Config.ConnectionString2 } }); - + public Repository(ISqlSugarClient context = null) : base(context)//注意这里要有默认值等于null + { + if (context == null) + { var configId = typeof(T).GetCustomAttribute().configId; Context = db.GetConnection(configId); - this.db = db; - this.db.CodeFirst.InitTables(); + Context.CodeFirst.InitTables(); } }