private static void Migrate(IHost webHost) { using (IServiceScope scope = webHost.Services.CreateScope()) { var db = scope.ServiceProvider.GetRequiredService <ApplicationContext>(); Microsoft.EntityFrameworkCore.Infrastructure.DatabaseFacade database = db.Database; database.Migrate(); } }
public void Initialize() { Microsoft.EntityFrameworkCore.Infrastructure.DatabaseFacade db = _db.Database; if (db.GetPendingMigrations().Any()) { _logger.LogInformation("Has pending migrations.."); db.Migrate(); _logger.LogInformation("Success"); } else { _logger.LogInformation("No pending migrations."); } try { InitializeProducts(); } catch (Exception ex) { _logger.LogInformation("Initialize products data exception.\n" + ex.ToString()); } }