Skip to content

Commit 74447c1

Browse files
committed
[fix] 主库与日志库类型必须相同
1 parent 92dbe3a commit 74447c1

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

Ape.Volo.Api/Extensions/SqlSugarSetup.cs

+12-6
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public static void AddSqlSugarSetup(this IServiceCollection services, Configs co
3030
if (services.IsNull())
3131
throw new ArgumentNullException(nameof(services));
3232
var dataConnection = configs.DataConnection;
33-
if (!dataConnection.ConnectionItem.Any())
33+
if (dataConnection.ConnectionItem.Count == 0)
3434
{
3535
throw new Exception("请确保配置数据库配置DataConnection无误;");
3636
}
@@ -39,18 +39,24 @@ public static void AddSqlSugarSetup(this IServiceCollection services, Configs co
3939
// dataConnection.ConnectionItem.Where(x => x.ConnId == configs.DefaultDataBase && x.Enabled).ToList();
4040
var allConnectionItem =
4141
dataConnection.ConnectionItem.Where(x => x.Enabled).ToList();
42-
if (!allConnectionItem.Any() || allConnectionItem.All(x => x.ConnId != configs.DefaultDataBase))
42+
if (allConnectionItem.Count == 0 || allConnectionItem.All(x => x.ConnId != configs.DefaultDataBase))
4343
{
4444
throw new Exception($"请确保主库ID:{configs.DefaultDataBase}的Enabled为true;");
4545
}
4646

47-
if (!allConnectionItem.Any() || allConnectionItem.All(x => x.ConnId != configs.DefaultDataBase))
47+
if (allConnectionItem.All(x => x.ConnId != configs.LogDataBase))
4848
{
4949
throw new Exception($"请确保日志库ID:{configs.LogDataBase}的Enabled为true;");
5050
}
5151

52+
if (allConnectionItem.FirstOrDefault(x => x.ConnId == configs.DefaultDataBase)?.DbType !=
53+
allConnectionItem.FirstOrDefault(x => x.ConnId == configs.LogDataBase)?.DbType)
54+
{
55+
throw new Exception($"请确保主库与日志库得DbType相同;");
56+
}
57+
58+
5259
List<ConnectionConfig> allConnectionConfig = new List<ConnectionConfig>();
53-
ConnectionConfig masterDb = null; //主库
5460
List<SlaveConnectionConfig> slaveDbs = null; //从库列表
5561

5662
foreach (var connectionItem in allConnectionItem)
@@ -86,7 +92,7 @@ public static void AddSqlSugarSetup(this IServiceCollection services, Configs co
8692
});
8793
}
8894

89-
masterDb = new ConnectionConfig
95+
var masterDb = new ConnectionConfig
9096
{
9197
ConfigId = connectionItem.ConnId,
9298
ConnectionString = connectionItem.ConnectionString,
@@ -128,7 +134,7 @@ public static void AddSqlSugarSetup(this IServiceCollection services, Configs co
128134
},
129135
// 从库
130136
SlaveConnectionConfigs = slaveDbs
131-
};
137+
}; //主库
132138
allConnectionConfig.Add(masterDb);
133139
}
134140

0 commit comments

Comments
 (0)