From 0c13d2413be500879855e756265f1c9ea5241262 Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Sun, 2 Jun 2019 16:36:01 +0800 Subject: [PATCH] Update demo --- .../Demo/Demo0_SqlSugarClient.cs | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/Src/Asp.Net/SqlServerTest/Demo/Demo0_SqlSugarClient.cs b/Src/Asp.Net/SqlServerTest/Demo/Demo0_SqlSugarClient.cs index ce296653d..da891e5e5 100644 --- a/Src/Asp.Net/SqlServerTest/Demo/Demo0_SqlSugarClient.cs +++ b/Src/Asp.Net/SqlServerTest/Demo/Demo0_SqlSugarClient.cs @@ -16,10 +16,37 @@ namespace OrmTest SqlSugarClient();//Create db DbContext();//Optimizing SqlSugarClient usage SingletonPattern();//Singleten Pattern - DistributedTransactionExample(); + DistributedTransactionExample(); + MasterSlave();//Read-write separation CustomAttribute(); } + private static void MasterSlave() + { + Console.WriteLine(""); + Console.WriteLine("#### MasterSlave Start ####"); + SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() + { + ConnectionString = Config.ConnectionString,//Master Connection + DbType = DbType.SqlServer, + InitKeyType = InitKeyType.Attribute, + IsAutoCloseConnection = true, + SlaveConnectionConfigs = new List() { + new SlaveConnectionConfig() { HitRate=10, ConnectionString=Config.ConnectionString2 } , + new SlaveConnectionConfig() { HitRate=10, ConnectionString=Config.ConnectionString2 } + } + }); + db.Aop.OnLogExecuted = (s, p) => + { + Console.WriteLine(db.Ado.Connection.ConnectionString); + }; + Console.WriteLine("Master:"); + db.Insertable(new Order() { Name = "abc", CustomId = 1, CreateTime = DateTime.Now }).ExecuteCommand(); + Console.WriteLine("Slave:"); + db.Queryable().First(); + Console.WriteLine("#### MasterSlave End ####"); + } + private static void SqlSugarClient() { //Create db