mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-04-24 18:04:52 +08:00
Update demo
This commit is contained in:
parent
bb706ab820
commit
0c13d2413b
@ -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<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…
Reference in New Issue
Block a user