mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-08-23 21:53:35 +08:00
Update MySqlDemo
This commit is contained in:
parent
5283302913
commit
f0fa2c5a14
@ -9,5 +9,7 @@ namespace OrmTest
|
||||
public class Config
|
||||
{
|
||||
public static string ConnectionString = "server=localhost;Database=SqlSugar4xTest;Uid=root;Pwd=root";
|
||||
public static string ConnectionString2 = "server=localhost;Database=SQLSUGAR4XTEST;Uid=root;Pwd=root";
|
||||
public static string ConnectionString3 = "server=localhost;Database=sqlsugar4xtest;Uid=root;Pwd=root";
|
||||
}
|
||||
}
|
||||
|
43
Src/Asp.Net/MySqlTest/Demos/A_MasterSlave.cs
Normal file
43
Src/Asp.Net/MySqlTest/Demos/A_MasterSlave.cs
Normal file
@ -0,0 +1,43 @@
|
||||
using OrmTest.Demo;
|
||||
using OrmTest.Models;
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace OrmTest.Demo
|
||||
{
|
||||
public class MasterSlave : DemoBase
|
||||
{
|
||||
|
||||
public static void Init()
|
||||
{
|
||||
var db = GetMasterSlaveInstance();
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
var list = db.Queryable<Student>().ToList(); // ConnectionString2 or ConnectionString3
|
||||
}
|
||||
db.Insertable(new Student() { Name = "masterTest" }).ExecuteCommand();// Config.ConnectionString
|
||||
}
|
||||
|
||||
public static SqlSugarClient GetMasterSlaveInstance()
|
||||
{
|
||||
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
|
||||
{
|
||||
ConnectionString = Config.ConnectionString,
|
||||
DbType = DbType.MySql,
|
||||
IsAutoCloseConnection = true,
|
||||
SlaveConnectionStrings = new List<SlaveConnectionConfig>() {
|
||||
new SlaveConnectionConfig() { HitRate=10, ConnectionString=Config.ConnectionString2 },
|
||||
new SlaveConnectionConfig() { HitRate=30, ConnectionString=Config.ConnectionString3 }
|
||||
}
|
||||
});
|
||||
db.Aop.OnLogExecuting = (sql, pars) =>
|
||||
{
|
||||
Console.WriteLine(db.Ado.Connection.ConnectionString);
|
||||
};
|
||||
return db;
|
||||
}
|
||||
}
|
||||
}
|
@ -57,6 +57,7 @@
|
||||
<Compile Include="Demos\6_ComplexModel.cs" />
|
||||
<Compile Include="Demos\7_Filter.cs" />
|
||||
<Compile Include="Demos\8_JoinSql.cs" />
|
||||
<Compile Include="Demos\A_MasterSlave.cs" />
|
||||
<Compile Include="Demos\DemoBase.cs" />
|
||||
<Compile Include="Models\DataTestInfo.cs" />
|
||||
<Compile Include="Models\DataTestInfo2.cs" />
|
||||
|
@ -44,6 +44,7 @@ namespace OrmTest
|
||||
OrmTest.Demo.Filter.Init();
|
||||
OrmTest.Demo.ComplexModel.Init();
|
||||
OrmTest.Demo.CodeFirst.Init();;
|
||||
OrmTest.Demo.MasterSlave.Init(); ;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user