public async Task <T> AddAsync(T entity) { _dbContext.Set <T>().Add(entity); await _dbContext.SaveChangesAsync(); return(entity); }
public static async Task SeedProductCategoriesAsync(ProductCategoryContext dbContext, ILoggerFactory loggerFactory, int?retry = 0) { int retryForAvailability = retry.Value; try { if (!dbContext.Categories.Any()) { await dbContext.Categories.AddRangeAsync(SampleProductCategoryData.Instance.Categories); await dbContext.SaveChangesAsync(); } } catch (Exception ex) { if (retryForAvailability < 3) { retryForAvailability++; var log = loggerFactory.CreateLogger <ProductCategoryContextSeed>(); log.LogError(ex.Message); await SeedProductCategoriesAsync(dbContext, loggerFactory, retryForAvailability); } } }