Browse Source

Update MySqlDemo

pull/12/MERGE
sunkaixuan 7 years ago
parent
commit
f0fa2c5a14
  1. 2
      Src/Asp.Net/MySqlTest/Config.cs
  2. 43
      Src/Asp.Net/MySqlTest/Demos/A_MasterSlave.cs
  3. 1
      Src/Asp.Net/MySqlTest/MySqlTest.csproj
  4. 1
      Src/Asp.Net/MySqlTest/Program.cs

2
Src/Asp.Net/MySqlTest/Config.cs

@ -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

@ -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;
}
}
}

1
Src/Asp.Net/MySqlTest/MySqlTest.csproj

@ -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" />

1
Src/Asp.Net/MySqlTest/Program.cs

@ -44,6 +44,7 @@ namespace OrmTest
OrmTest.Demo.Filter.Init();
OrmTest.Demo.ComplexModel.Init();
OrmTest.Demo.CodeFirst.Init();;
OrmTest.Demo.MasterSlave.Init(); ;
}
}
}

Loading…
Cancel
Save