diff --git a/Src/Asp.Net/SqlServerTest/Demo/DemoH_Tenant.cs b/Src/Asp.Net/SqlServerTest/Demo/DemoH_Tenant.cs index f7afc9e29..4ce9745d2 100644 --- a/Src/Asp.Net/SqlServerTest/Demo/DemoH_Tenant.cs +++ b/Src/Asp.Net/SqlServerTest/Demo/DemoH_Tenant.cs @@ -6,7 +6,7 @@ using System.Reflection; using System.Text; using System.Threading.Tasks; -namespace OrmTest +namespace OrmTest { public class DemoH_Tenant { @@ -19,15 +19,15 @@ namespace OrmTest } public class C1Service : Repository { - public void Test() + public void Test() { - base.GetList(); - base.ChangeRepository().GetList(); - } - } - public class C2Service : Repository - { + base.AsTenant().BeginTran(); + base.GetList(); //调用内部仓储方法 + base.ChangeRepository>().GetList();//调用外部仓储 + + base.AsTenant().CommitTran(); + } } @@ -40,7 +40,7 @@ namespace OrmTest var db = new SqlSugarClient(new List { new ConnectionConfig() { - ConfigId=1, + ConfigId="1", DbType = SqlSugar.DbType.SqlServer, IsAutoCloseConnection = true, ConnectionString = Config.ConnectionString @@ -53,13 +53,10 @@ namespace OrmTest ConnectionString = Config.ConnectionString2 } }); + base.Context = db; var configId = typeof(T).GetCustomAttribute().configId; - base.Context = db.GetConnection(configId); - base.Context.CodeFirst.InitTables(); - db.Aop.OnLogExecuting = (s, p) => - { - Console.WriteLine(s); - }; + db.ChangeDatabase(configId); + } } @@ -76,9 +73,9 @@ namespace OrmTest } [TenantAttribute("1")] - public class C1Table + public class C1Table { - public string Id { get; set; } + public string Id { get; set; } } [TenantAttribute("2")] public class C2Table