自動部署相關問題
遇到需要更新數(shù)據(jù)時(加了表or家了字段這些),只要starup中有
using (var serviceScope = app.ApplicationServices.GetRequiredService<IServiceScopeFactory>().CreateScope())
? ? ? ? ? ? {
? ? ? ? ? ? ? ?if (serviceScope.ServiceProvider.GetService<CctvDbContext>() != null)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? try
? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? var ctx = serviceScope.ServiceProvider.GetService<CctvDbContext>();
? ? ? ? ? ? ? ? ? ? ? ? ctx.Database.Migrate();
? ? ? ? ? ? ? ? ? ? ? ? LogUtils.Info("Data Migration", "Data Migration Processing Success");
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? catch (Exception ex)
? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? LogUtils.Error("Data Migration",ex.Message );
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
就會幫我們自動進行更新migration的東西到數(shù)據(jù)庫