mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-09-19 18:22:23 +08:00
-
This commit is contained in:
@@ -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 }
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@@ -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 }
|
||||||
}
|
}
|
||||||
|
@@ -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;
|
||||||
|
@@ -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
|
||||||
|
Reference in New Issue
Block a user