11using Blog . Core . Common ;
2+ using Blog . Core . Common . DB ;
23using Blog . Core . Common . Helper ;
34using System ;
45using System . Collections . Generic ;
56using System . IO ;
7+ using System . Linq ;
68using System . Text ;
79using System . Threading . Tasks ;
810
@@ -41,12 +43,34 @@ public static async Task SeedAsync(MyContext myContext, string WebRootPath)
4143 SeedDataFolderMini = Path . Combine ( WebRootPath , SeedDataFolderMini ) ;
4244
4345 Console . WriteLine ( "Config data init..." ) ;
44- Console . WriteLine ( "DB Type: " + MyContext . DbType ) ;
45- Console . WriteLine ( "DB ConnectString: " + MyContext . ConnectionString ) ;
46+ Console . WriteLine ( $ "Is multi-DataBase: { Appsettings . app ( new string [ ] { "MutiDBEnabled" } ) } ") ;
47+ if ( Appsettings . app ( new string [ ] { "MutiDBEnabled" } ) . ObjToBool ( ) )
48+ {
49+ Console . WriteLine ( $ "Master DB Type: { MyContext . DbType } ") ;
50+ Console . WriteLine ( $ "Master DB ConnectString: { MyContext . ConnectionString } ") ;
51+ Console . WriteLine ( ) ;
52+
53+ var slaveIndex = 0 ;
54+ BaseDBConfig . MutiConnectionString . Where ( x => x . ConnId != MainDb . CurrentDbConnId ) . ToList ( ) . ForEach ( m =>
55+ {
56+ slaveIndex ++ ;
57+ Console . WriteLine ( $ "Slave{ slaveIndex } DB ID: { m . ConnId } ") ;
58+ Console . WriteLine ( $ "Slave{ slaveIndex } DB Type: { m . DbType } ") ;
59+ Console . WriteLine ( $ "Slave{ slaveIndex } DB ConnectString: { m . Conn } ") ;
60+ } ) ;
61+
62+ }
63+ else
64+ {
65+ Console . WriteLine ( "DB Type: " + MyContext . DbType ) ;
66+ Console . WriteLine ( "DB ConnectString: " + MyContext . ConnectionString ) ;
67+ }
4668
69+ Console . WriteLine ( "Create Database..." ) ;
4770 // 创建数据库
4871 myContext . Db . DbMaintenance . CreateDatabase ( ) ;
4972
73+ Console . WriteLine ( "Create Tables..." ) ;
5074 // 创建表
5175 myContext . CreateTableByEntity ( false ,
5276 typeof ( Advertisement ) ,
@@ -67,7 +91,7 @@ public static async Task SeedAsync(MyContext myContext, string WebRootPath)
6791 // 后期单独处理某些表
6892 // myContext.Db.CodeFirst.InitTables(typeof(sysUserInfo));
6993
70- Console . WriteLine ( "Database:WMBlog created success!" ) ;
94+ Console . WriteLine ( "Database is created success!" ) ;
7195 Console . WriteLine ( ) ;
7296
7397 if ( Appsettings . app ( new string [ ] { "AppSettings" , "SeedDBDataEnabled" } ) . ObjToBool ( ) )
0 commit comments