mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-07-17 19:37:34 +08:00
4.5.9.6
This commit is contained in:
parent
39a8bbc0dc
commit
e4828f2e84
@ -13,12 +13,13 @@ namespace OrmTest.Demo
|
|||||||
|
|
||||||
public static void Init()
|
public static void Init()
|
||||||
{
|
{
|
||||||
var db = GetMasterSlaveInstance();
|
|
||||||
for (int i = 0; i < 10; i++)
|
for (int i = 0; i < 1000; i++)
|
||||||
{
|
{
|
||||||
var list = db.Queryable<Student>().ToList(); // ConnectionString2 or ConnectionString3
|
var db = GetMasterSlaveInstance();
|
||||||
|
var list = db.Insertable(new Student() { Name="aa" }).ExecuteCommand(); // ConnectionString2 or ConnectionString3
|
||||||
}
|
}
|
||||||
db.Insertable(new Student() { Name = "masterTest" }).ExecuteCommand();// Config.ConnectionString
|
//db.Insertable(new Student() { Name = "masterTest" }).ExecuteCommand();// Config.ConnectionString
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SqlSugarClient GetMasterSlaveInstance()
|
public static SqlSugarClient GetMasterSlaveInstance()
|
||||||
@ -29,8 +30,8 @@ namespace OrmTest.Demo
|
|||||||
DbType = DbType.SqlServer,
|
DbType = DbType.SqlServer,
|
||||||
IsAutoCloseConnection = true,
|
IsAutoCloseConnection = true,
|
||||||
SlaveConnectionConfigs = new List<SlaveConnectionConfig>() {
|
SlaveConnectionConfigs = new List<SlaveConnectionConfig>() {
|
||||||
new SlaveConnectionConfig() { HitRate=10, ConnectionString=Config.ConnectionString2 },
|
new SlaveConnectionConfig() { HitRate=10, ConnectionString=Config.ConnectionString2 } ,
|
||||||
new SlaveConnectionConfig() { HitRate=30, ConnectionString=Config.ConnectionString3 }
|
new SlaveConnectionConfig() { HitRate=10, ConnectionString=Config.ConnectionString2 }
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
db.Aop.OnLogExecuting = (sql, pars) =>
|
db.Aop.OnLogExecuting = (sql, pars) =>
|
||||||
|
@ -75,7 +75,7 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
this.Connection.Close();
|
this.Connection.Close();
|
||||||
}
|
}
|
||||||
if (this.IsMasterSlaveSeparation)
|
if (this.IsMasterSlaveSeparation && this.SlaveConnections.HasValue())
|
||||||
{
|
{
|
||||||
foreach (var slaveConnection in this.SlaveConnections)
|
foreach (var slaveConnection in this.SlaveConnections)
|
||||||
{
|
{
|
||||||
@ -263,7 +263,7 @@ namespace SqlSugar
|
|||||||
if (this.IsClearParameters)
|
if (this.IsClearParameters)
|
||||||
sqlCommand.Parameters.Clear();
|
sqlCommand.Parameters.Clear();
|
||||||
ExecuteAfter(sql, parameters);
|
ExecuteAfter(sql, parameters);
|
||||||
SetConnectionEnd();
|
SetConnectionEnd(sql);
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@ -293,7 +293,7 @@ namespace SqlSugar
|
|||||||
if (this.IsClearParameters)
|
if (this.IsClearParameters)
|
||||||
sqlCommand.Parameters.Clear();
|
sqlCommand.Parameters.Clear();
|
||||||
ExecuteAfter(sql, parameters);
|
ExecuteAfter(sql, parameters);
|
||||||
SetConnectionEnd();
|
SetConnectionEnd(sql);
|
||||||
return sqlDataReader;
|
return sqlDataReader;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@ -319,7 +319,7 @@ namespace SqlSugar
|
|||||||
if (this.IsClearParameters)
|
if (this.IsClearParameters)
|
||||||
sqlCommand.Parameters.Clear();
|
sqlCommand.Parameters.Clear();
|
||||||
ExecuteAfter(sql, parameters);
|
ExecuteAfter(sql, parameters);
|
||||||
SetConnectionEnd();
|
SetConnectionEnd(sql);
|
||||||
return ds;
|
return ds;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@ -347,7 +347,7 @@ namespace SqlSugar
|
|||||||
if (this.IsClearParameters)
|
if (this.IsClearParameters)
|
||||||
sqlCommand.Parameters.Clear();
|
sqlCommand.Parameters.Clear();
|
||||||
ExecuteAfter(sql, parameters);
|
ExecuteAfter(sql, parameters);
|
||||||
SetConnectionEnd();
|
SetConnectionEnd(sql);
|
||||||
return scalar;
|
return scalar;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@ -719,9 +719,9 @@ namespace SqlSugar
|
|||||||
return result.Count() == 0;
|
return result.Count() == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SetConnectionEnd()
|
private void SetConnectionEnd(string sql)
|
||||||
{
|
{
|
||||||
if (this.IsMasterSlaveSeparation)
|
if (this.IsMasterSlaveSeparation && IsRead(sql))
|
||||||
{
|
{
|
||||||
this.Connection = this.MasterConnection;
|
this.Connection = this.MasterConnection;
|
||||||
this.Context.CurrentConnectionConfig.ConnectionString = this.MasterConnection.ConnectionString;
|
this.Context.CurrentConnectionConfig.ConnectionString = this.MasterConnection.ConnectionString;
|
||||||
|
@ -31,5 +31,5 @@ using System.Runtime.InteropServices;
|
|||||||
// You can specify all the values or you can default the Build and Revision Numbers
|
// You can specify all the values or you can default the Build and Revision Numbers
|
||||||
// by using the '*' as shown below:
|
// by using the '*' as shown below:
|
||||||
// [assembly: AssemblyVersion("1.0.*")]
|
// [assembly: AssemblyVersion("1.0.*")]
|
||||||
[assembly: AssemblyVersion("4.5.9.5")]
|
[assembly: AssemblyVersion("4.5.9.6")]
|
||||||
[assembly: AssemblyFileVersion("4.5.9.5")]
|
[assembly: AssemblyFileVersion("4.5.9.6")]
|
||||||
|
Loading…
Reference in New Issue
Block a user