Skip to content

Commit 947b55f

Browse files
committed
Update DBSeed.cs
1 parent 2af9bd6 commit 947b55f

1 file changed

Lines changed: 60 additions & 12 deletions

File tree

Blog.Core.Model/Seed/DBSeed.cs

Lines changed: 60 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,87 +43,135 @@ public static async Task SeedAsync(MyContext myContext)
4343
//myContext.Db.CodeFirst.InitTables(typeof(Permission));
4444
//myContext.Db.CodeFirst.InitTables(typeof(Advertisement));
4545

46+
Console.WriteLine("Database:WMBlog created success!");
47+
Console.WriteLine();
4648

47-
49+
Console.WriteLine("Seeding database...");
4850

4951
#region BlogArticle
5052
if (!await myContext.Db.Queryable<BlogArticle>().AnyAsync())
5153
{
52-
myContext.GetEntityDB<BlogArticle>().InsertRange(JsonHelper.ParseFormByJson<List<BlogArticle>>(GetNetData.Get(string.Format(GitJsonFileFormat,"BlogArticle"))));
54+
myContext.GetEntityDB<BlogArticle>().InsertRange(JsonHelper.ParseFormByJson<List<BlogArticle>>(GetNetData.Get(string.Format(GitJsonFileFormat, "BlogArticle"))));
55+
Console.WriteLine("Table:BlogArticle created success!");
56+
}
57+
else
58+
{
59+
Console.WriteLine("Table:BlogArticle already exists...");
5360
}
5461
#endregion
5562

5663

5764
#region Module
5865
if (!await myContext.Db.Queryable<Module>().AnyAsync())
5966
{
60-
myContext.GetEntityDB<Module>().InsertRange(JsonHelper.ParseFormByJson<List<Module>>(GetNetData.Get(string.Format(GitJsonFileFormat,"Module"))));
67+
myContext.GetEntityDB<Module>().InsertRange(JsonHelper.ParseFormByJson<List<Module>>(GetNetData.Get(string.Format(GitJsonFileFormat, "Module"))));
68+
Console.WriteLine("Table:Module created success!");
69+
}
70+
else
71+
{
72+
Console.WriteLine("Table:Module already exists...");
6173
}
6274
#endregion
6375

6476

6577
#region Permission
6678
if (!await myContext.Db.Queryable<Permission>().AnyAsync())
6779
{
68-
myContext.GetEntityDB<Permission>().InsertRange(JsonHelper.ParseFormByJson<List<Permission>>(GetNetData.Get(string.Format(GitJsonFileFormat,"Permission"))));
80+
myContext.GetEntityDB<Permission>().InsertRange(JsonHelper.ParseFormByJson<List<Permission>>(GetNetData.Get(string.Format(GitJsonFileFormat, "Permission"))));
81+
Console.WriteLine("Table:Permission created success!");
82+
}
83+
else
84+
{
85+
Console.WriteLine("Table:Permission already exists...");
6986
}
7087
#endregion
7188

7289

7390
#region Role
7491
if (!await myContext.Db.Queryable<Role>().AnyAsync())
7592
{
76-
myContext.GetEntityDB<Role>().InsertRange(JsonHelper.ParseFormByJson<List<Role>>(GetNetData.Get(string.Format(GitJsonFileFormat,"Role"))));
93+
myContext.GetEntityDB<Role>().InsertRange(JsonHelper.ParseFormByJson<List<Role>>(GetNetData.Get(string.Format(GitJsonFileFormat, "Role"))));
94+
Console.WriteLine("Table:Role created success!");
95+
}
96+
else
97+
{
98+
Console.WriteLine("Table:Role already exists...");
7799
}
78100
#endregion
79101

80102

81103
#region RoleModulePermission
82104
if (!await myContext.Db.Queryable<RoleModulePermission>().AnyAsync())
83105
{
84-
myContext.GetEntityDB<RoleModulePermission>().InsertRange(JsonHelper.ParseFormByJson<List<RoleModulePermission>>(GetNetData.Get(string.Format(GitJsonFileFormat,"RoleModulePermission"))));
106+
myContext.GetEntityDB<RoleModulePermission>().InsertRange(JsonHelper.ParseFormByJson<List<RoleModulePermission>>(GetNetData.Get(string.Format(GitJsonFileFormat, "RoleModulePermission"))));
107+
Console.WriteLine("Table:RoleModulePermission created success!");
108+
}
109+
else
110+
{
111+
Console.WriteLine("Table:RoleModulePermission already exists...");
85112
}
86113
#endregion
87114

88115

89116
#region Topic
90117
if (!await myContext.Db.Queryable<Topic>().AnyAsync())
91118
{
92-
myContext.GetEntityDB<Topic>().InsertRange(JsonHelper.ParseFormByJson<List<Topic>>(GetNetData.Get(string.Format(GitJsonFileFormat,"Topic"))));
119+
myContext.GetEntityDB<Topic>().InsertRange(JsonHelper.ParseFormByJson<List<Topic>>(GetNetData.Get(string.Format(GitJsonFileFormat, "Topic"))));
120+
Console.WriteLine("Table:Topic created success!");
121+
}
122+
else
123+
{
124+
Console.WriteLine("Table:Topic already exists...");
93125
}
94126
#endregion
95127

96128

97129
#region TopicDetail
98130
if (!await myContext.Db.Queryable<TopicDetail>().AnyAsync())
99131
{
100-
myContext.GetEntityDB<TopicDetail>().InsertRange(JsonHelper.ParseFormByJson<List<TopicDetail>>(GetNetData.Get(string.Format(GitJsonFileFormat,"TopicDetail"))));
132+
myContext.GetEntityDB<TopicDetail>().InsertRange(JsonHelper.ParseFormByJson<List<TopicDetail>>(GetNetData.Get(string.Format(GitJsonFileFormat, "TopicDetail"))));
133+
Console.WriteLine("Table:TopicDetail created success!");
134+
}
135+
else
136+
{
137+
Console.WriteLine("Table:TopicDetail already exists...");
101138
}
102139
#endregion
103140

104141

105142
#region UserRole
106143
if (!await myContext.Db.Queryable<UserRole>().AnyAsync())
107144
{
108-
myContext.GetEntityDB<UserRole>().InsertRange(JsonHelper.ParseFormByJson<List<UserRole>>(GetNetData.Get(string.Format(GitJsonFileFormat,"UserRole"))));
145+
myContext.GetEntityDB<UserRole>().InsertRange(JsonHelper.ParseFormByJson<List<UserRole>>(GetNetData.Get(string.Format(GitJsonFileFormat, "UserRole"))));
146+
Console.WriteLine("Table:UserRole created success!");
147+
}
148+
else
149+
{
150+
Console.WriteLine("Table:UserRole already exists...");
109151
}
110152
#endregion
111153

112154

113155
#region sysUserInfo
114156
if (!await myContext.Db.Queryable<sysUserInfo>().AnyAsync())
115157
{
116-
myContext.GetEntityDB<sysUserInfo>().InsertRange(JsonHelper.ParseFormByJson<List<sysUserInfo>>(GetNetData.Get(string.Format(GitJsonFileFormat,"sysUserInfo"))));
158+
myContext.GetEntityDB<sysUserInfo>().InsertRange(JsonHelper.ParseFormByJson<List<sysUserInfo>>(GetNetData.Get(string.Format(GitJsonFileFormat, "sysUserInfo"))));
159+
Console.WriteLine("Table:sysUserInfo created success!");
160+
}
161+
else
162+
{
163+
Console.WriteLine("Table:sysUserInfo already exists...");
117164
}
118165
#endregion
119166

120167

121-
168+
Console.WriteLine("Done seeding database.");
169+
Console.WriteLine();
122170

123171
}
124172
catch (Exception ex)
125173
{
126-
throw new Exception("1、注意要先创建空的数据库\n2、"+ex.Message);
174+
throw new Exception("1、注意要先创建空的数据库\n2、" + ex.Message);
127175
}
128176
}
129177
}

0 commit comments

Comments
 (0)