public static async Task SeedAsync(CatalogContext catalogContext, ILoggerFactory loggerFactory, int?retry = 0) { int retryForAvailability = retry.Value; try { // TODO: Only run this if using a real database // context.Database.Migrate(); if (!catalogContext.Set <CatalogBrand>().Any()) { catalogContext.Set <CatalogBrand>().AddRange( GetPreconfiguredCatalogBrands()); await catalogContext.SaveChangesAsync(); } if (!catalogContext.Set <CatalogType>().Any()) { catalogContext.Set <CatalogType>().AddRange( GetPreconfiguredCatalogTypes()); await catalogContext.SaveChangesAsync(); } if (!catalogContext.Set <CatalogItem>().Any()) { catalogContext.Set <CatalogItem>().AddRange( GetPreconfiguredItems()); await catalogContext.SaveChangesAsync(); } } catch (Exception ex) { if (retryForAvailability < 10) { retryForAvailability++; var log = loggerFactory.CreateLogger <CatalogContextSeed>(); log.LogError(ex.Message); await SeedAsync(catalogContext, loggerFactory, retryForAvailability); } } }
public virtual async Task <T> GetByIdAsync(int id, CancellationToken cancellationToken = default) { var keyValues = new object[] { id }; return(await _dbContext.Set <T>().FindAsync(keyValues, cancellationToken)); }
public virtual async Task <T> GetByIdAsync(int id) { return(await _dbContext.Set <T>().FindAsync(id)); }
public virtual T GetById(int id) { return(_dbContext.Set <T>().Find(id)); }
private IQueryable <T> ApplySpecification(ISpecification <T> spec) { return(SpecificationEvaluator <T> .GetQuery(_dbContext.Set <T>().AsQueryable(), spec)); }
public virtual T GetById(int id) // @issue@I02 { return(_dbContext.Set <T>().Find(id)); // @issue@I02 }