Browse Source

4.5.9.6

pull/12/MERGE
sunkaixuan 7 years ago
parent
commit
e4828f2e84
  1. 13
      Src/Asp.Net/SqlServerTest/Demos/A_MasterSlave.cs
  2. 14
      Src/Asp.Net/SqlSugar/Abstract/AdoProvider/AdoProvider.cs
  3. 4
      Src/Asp.Net/SqlSugar/Properties/AssemblyInfo.cs

13
Src/Asp.Net/SqlServerTest/Demos/A_MasterSlave.cs

@ -13,12 +13,13 @@ namespace OrmTest.Demo
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()
@ -29,8 +30,8 @@ namespace OrmTest.Demo
DbType = DbType.SqlServer,
IsAutoCloseConnection = true,
SlaveConnectionConfigs = new List<SlaveConnectionConfig>() {
new SlaveConnectionConfig() { HitRate=10, ConnectionString=Config.ConnectionString2 },
new SlaveConnectionConfig() { HitRate=30, ConnectionString=Config.ConnectionString3 }
new SlaveConnectionConfig() { HitRate=10, ConnectionString=Config.ConnectionString2 } ,
new SlaveConnectionConfig() { HitRate=10, ConnectionString=Config.ConnectionString2 }
}
});
db.Aop.OnLogExecuting = (sql, pars) =>

14
Src/Asp.Net/SqlSugar/Abstract/AdoProvider/AdoProvider.cs

@ -75,7 +75,7 @@ namespace SqlSugar
{
this.Connection.Close();
}
if (this.IsMasterSlaveSeparation)
if (this.IsMasterSlaveSeparation && this.SlaveConnections.HasValue())
{
foreach (var slaveConnection in this.SlaveConnections)
{
@ -263,7 +263,7 @@ namespace SqlSugar
if (this.IsClearParameters)
sqlCommand.Parameters.Clear();
ExecuteAfter(sql, parameters);
SetConnectionEnd();
SetConnectionEnd(sql);
return count;
}
catch (Exception ex)
@ -293,7 +293,7 @@ namespace SqlSugar
if (this.IsClearParameters)
sqlCommand.Parameters.Clear();
ExecuteAfter(sql, parameters);
SetConnectionEnd();
SetConnectionEnd(sql);
return sqlDataReader;
}
catch (Exception ex)
@ -319,7 +319,7 @@ namespace SqlSugar
if (this.IsClearParameters)
sqlCommand.Parameters.Clear();
ExecuteAfter(sql, parameters);
SetConnectionEnd();
SetConnectionEnd(sql);
return ds;
}
catch (Exception ex)
@ -347,7 +347,7 @@ namespace SqlSugar
if (this.IsClearParameters)
sqlCommand.Parameters.Clear();
ExecuteAfter(sql, parameters);
SetConnectionEnd();
SetConnectionEnd(sql);
return scalar;
}
catch (Exception ex)
@ -719,9 +719,9 @@ namespace SqlSugar
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.Context.CurrentConnectionConfig.ConnectionString = this.MasterConnection.ConnectionString;

4
Src/Asp.Net/SqlSugar/Properties/AssemblyInfo.cs

@ -31,5 +31,5 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("4.5.9.5")]
[assembly: AssemblyFileVersion("4.5.9.5")]
[assembly: AssemblyVersion("4.5.9.6")]
[assembly: AssemblyFileVersion("4.5.9.6")]

Loading…
Cancel
Save