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(); } }