自动部署相关问题
遇到需要更新数据时(加了表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的东西到数据库