@@ -30,7 +30,7 @@ public static void AddSqlSugarSetup(this IServiceCollection services, Configs co
30
30
if ( services . IsNull ( ) )
31
31
throw new ArgumentNullException ( nameof ( services ) ) ;
32
32
var dataConnection = configs . DataConnection ;
33
- if ( ! dataConnection . ConnectionItem . Any ( ) )
33
+ if ( dataConnection . ConnectionItem . Count == 0 )
34
34
{
35
35
throw new Exception ( "请确保配置数据库配置DataConnection无误;" ) ;
36
36
}
@@ -39,18 +39,24 @@ public static void AddSqlSugarSetup(this IServiceCollection services, Configs co
39
39
// dataConnection.ConnectionItem.Where(x => x.ConnId == configs.DefaultDataBase && x.Enabled).ToList();
40
40
var allConnectionItem =
41
41
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 ) )
43
43
{
44
44
throw new Exception ( $ "请确保主库ID:{ configs . DefaultDataBase } 的Enabled为true;") ;
45
45
}
46
46
47
- if ( ! allConnectionItem . Any ( ) || allConnectionItem . All ( x => x . ConnId != configs . DefaultDataBase ) )
47
+ if ( allConnectionItem . All ( x => x . ConnId != configs . LogDataBase ) )
48
48
{
49
49
throw new Exception ( $ "请确保日志库ID:{ configs . LogDataBase } 的Enabled为true;") ;
50
50
}
51
51
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
+
52
59
List < ConnectionConfig > allConnectionConfig = new List < ConnectionConfig > ( ) ;
53
- ConnectionConfig masterDb = null ; //主库
54
60
List < SlaveConnectionConfig > slaveDbs = null ; //从库列表
55
61
56
62
foreach ( var connectionItem in allConnectionItem )
@@ -86,7 +92,7 @@ public static void AddSqlSugarSetup(this IServiceCollection services, Configs co
86
92
} ) ;
87
93
}
88
94
89
- masterDb = new ConnectionConfig
95
+ var masterDb = new ConnectionConfig
90
96
{
91
97
ConfigId = connectionItem . ConnId ,
92
98
ConnectionString = connectionItem . ConnectionString ,
@@ -128,7 +134,7 @@ public static void AddSqlSugarSetup(this IServiceCollection services, Configs co
128
134
} ,
129
135
// 从库
130
136
SlaveConnectionConfigs = slaveDbs
131
- } ;
137
+ } ; //主库
132
138
allConnectionConfig . Add ( masterDb ) ;
133
139
}
134
140
0 commit comments