public static async Task SeedAsync(CarsContext carsContext, ILoggerFactory loggerFactory, int?retry = 0) { int retryForAvailability = retry.Value; try { // Seed Areas and Garages if (!carsContext.Areas.Any()) { IEnumerable <Area> areas = GetPreconfiguredAreas(); carsContext.Areas.AddRange(areas); foreach (Area area in areas) { carsContext.Garages.AddRange(GetPreconfiguredGarages(area)); } await carsContext.SaveChangesAsync(); } if (!carsContext.CarCategories.Any()) { carsContext.CarCategories.AddRange(GetPreconfiguredCarCategories()); await carsContext.SaveChangesAsync(); } if (!carsContext.CarImpactClasses.Any()) { carsContext.CarImpactClasses.AddRange(GetPreconfiguredCarImpactClasses()); await carsContext.SaveChangesAsync(); } if (!carsContext.CarProbabilityClasses.Any()) { carsContext.CarProbabilityClasses.AddRange(GetPreconfiguredCarProbabilityClasses()); await carsContext.SaveChangesAsync(); } } catch (Exception ex) { if (retryForAvailability < 10) { retryForAvailability++; var log = loggerFactory.CreateLogger <CarsContextSeed>(); log.LogError(ex.Message); await SeedAsync(carsContext, loggerFactory, retryForAvailability); } } }
public CarRepository(CarsContext dbContext) : base(dbContext) { }
public EfRepository(CarsContext dbContext) { _dbContext = dbContext; }