This commit is contained in:
sunkaixuan
2017-10-24 17:00:21 +08:00
parent f0fa2c5a14
commit 5f1166a404
4 changed files with 6 additions and 6 deletions

View File

@@ -28,8 +28,8 @@ namespace OrmTest.Demo
ConnectionString = Config.ConnectionString, ConnectionString = Config.ConnectionString,
DbType = DbType.MySql, DbType = DbType.MySql,
IsAutoCloseConnection = true, IsAutoCloseConnection = true,
SlaveConnectionStrings = new List<SlaveConnectionConfig>() { SlaveConnectionConfigs = new List<SlaveConnectionConfig>() {
new SlaveConnectionConfig() { HitRate=10, ConnectionString=Config.ConnectionString2 }, new SlaveConnectionConfig() { HitRate=0, ConnectionString=Config.ConnectionString2 },
new SlaveConnectionConfig() { HitRate=30, ConnectionString=Config.ConnectionString3 } new SlaveConnectionConfig() { HitRate=30, ConnectionString=Config.ConnectionString3 }
} }
}); });

View File

@@ -28,7 +28,7 @@ namespace OrmTest.Demo
ConnectionString = Config.ConnectionString, ConnectionString = Config.ConnectionString,
DbType = DbType.SqlServer, DbType = DbType.SqlServer,
IsAutoCloseConnection = true, IsAutoCloseConnection = true,
SlaveConnectionStrings = 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=30, ConnectionString=Config.ConnectionString3 }
} }

View File

@@ -686,7 +686,7 @@ namespace SqlSugar
{ {
get get
{ {
return this.Context.CurrentConnectionConfig.SlaveConnectionStrings.HasValue(); return this.Context.CurrentConnectionConfig.SlaveConnectionConfigs.HasValue();
} }
} }
private void SetConnectionStart(string sql) private void SetConnectionStart(string sql)
@@ -697,7 +697,7 @@ namespace SqlSugar
{ {
this.MasterConnection = this.Connection; this.MasterConnection = this.Connection;
} }
var saves = this.Context.CurrentConnectionConfig.SlaveConnectionStrings.Where(it => it.HitRate > 0).ToList(); var saves = this.Context.CurrentConnectionConfig.SlaveConnectionConfigs.Where(it => it.HitRate > 0).ToList();
var currentIndex = UtilRandom.GetRandomIndex(saves.ToDictionary(it => saves.ToList().IndexOf(it), it => it.HitRate)); var currentIndex = UtilRandom.GetRandomIndex(saves.ToDictionary(it => saves.ToList().IndexOf(it), it => it.HitRate));
var currentSaveConnection = saves[currentIndex]; var currentSaveConnection = saves[currentIndex];
this.Connection = null; this.Connection = null;

View File

@@ -32,7 +32,7 @@ namespace SqlSugar
/// If SlaveConnectionStrings has value,ConnectionString is write operation, SlaveConnectionStrings is read operation. /// If SlaveConnectionStrings has value,ConnectionString is write operation, SlaveConnectionStrings is read operation.
/// All operations within a transaction is ConnectionString /// All operations within a transaction is ConnectionString
/// </summary> /// </summary>
public List<SlaveConnectionConfig> SlaveConnectionStrings { get; set; } public List<SlaveConnectionConfig> SlaveConnectionConfigs { get; set; }
} }
public class ConfigureExternalServices public class ConfigureExternalServices