Browse Source

Update demo

pull/12/MERGE
sunkaixuan 6 years ago
parent
commit
0c13d2413b
  1. 27
      Src/Asp.Net/SqlServerTest/Demo/Demo0_SqlSugarClient.cs

27
Src/Asp.Net/SqlServerTest/Demo/Demo0_SqlSugarClient.cs

@ -17,9 +17,36 @@ namespace OrmTest
DbContext();//Optimizing SqlSugarClient usage
SingletonPattern();//Singleten Pattern
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<SlaveConnectionConfig>() {
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<Order>().First();
Console.WriteLine("#### MasterSlave End ####");
}
private static void SqlSugarClient()
{
//Create db

Loading…
Cancel
Save