public static async Task EnsureSeedDataAsync(RmsDbContext rmsDbContext, ILoggerFactory loggerFactory, int?retry = 0) { int retryForAvailability = retry.Value; try { if (!rmsDbContext.Users.Any()) { var user = new User() { }; rmsDbContext.Add(user); await rmsDbContext.SaveChangesAsync(); } var dataText = System.IO.File.ReadAllText(@"docs\Countries.json"); if (!rmsDbContext.Countries.Any()) { var countries = JsonConvert.DeserializeObject(dataText); } } catch (Exception ex) { if (retryForAvailability < 10) { retryForAvailability++; var log = loggerFactory.CreateLogger <RmsDbContextSeedData>(); log.LogError(ex.Message); await EnsureSeedDataAsync(rmsDbContext, loggerFactory, retryForAvailability); } } }
public static bool AllMigrationsApplied(this RmsDbContext rmsDbContext) { var applied = rmsDbContext.GetService <IHistoryRepository>().GetAppliedMigrations() .Select(m => m.MigrationId); var total = rmsDbContext.GetService <IMigrationsAssembly>().Migrations.Select(m => m.Key); return(!total.Except(applied).Any()); }
public EfRepository(RmsDbContext dbContext) { DbContext = dbContext; }
public static void EnsureSeeded(this RmsDbContext rmsDbContext) { }