public static async Task SeedAsync(WebAppContext webAppContext, ILoggerFactory loggerFactory, int?retry = 0) { int retryForAvailability = retry.Value; try { // INFO: Run this if using a real database. Used to automaticly migrate docker image of sql server db. webAppContext.Database.Migrate(); //orderContext.Database.EnsureCreated(); if (!webAppContext.Employees.Any()) { webAppContext.Employees.AddRange(GetPreconfiguredOrders()); await webAppContext.SaveChangesAsync(); } } catch (Exception exception) { if (retryForAvailability < 50) { retryForAvailability++; var log = loggerFactory.CreateLogger <WebAppContextSeed>(); log.LogError(exception.Message); System.Threading.Thread.Sleep(2000); await SeedAsync(webAppContext, loggerFactory, retryForAvailability); } throw; } }
public static async Task SeedAsync(WebAppContext webAppContext, ILoggerFactory loggerFactory, int?retry = 0) { int retryForAvailability = retry.Value; try { webAppContext.Database.Migrate(); if (!webAppContext.AppUsers.Any()) { webAppContext.AppUsers.AddRange(GetPreconfiguredOrders()); await webAppContext.SaveChangesAsync(); } } catch (Exception ex) { if (retryForAvailability < 50) { retryForAvailability++; var log = loggerFactory.CreateLogger <WebAppContextSeed>(); log.LogError(ex.Message); Thread.Sleep(2000); await SeedAsync(webAppContext, loggerFactory, retryForAvailability); } } }