private async Task AddIfEmpty <TModel>(List <TModel> models, bool hasIdentityKey = true) where TModel : class { if (await _db.Set <TModel>().AnyAsync()) { return; } var strategy = _db.Database.CreateExecutionStrategy(); await strategy.ExecuteAsync(async() => { await using var transaction = await _db.Database.BeginTransactionAsync(); await _db.Set <TModel>().AddRangeAsync(models); await Save <TModel>(hasIdentityKey); await transaction.CommitAsync(); }); }
private void DeleteTable <T>() where T : class { _db.RemoveRange(_db.Set <T>()); }