public async Task UpdateGenreAndGames(int removeId, int moveToId) { using (_ctx = new RetroDbContext(conString)) { var transaction = await _ctx.Database.BeginTransactionAsync(); try { //games to change var games = _ctx.Games.Where(x => x.GenreId == removeId); foreach (var game in games) { game.GenreId = moveToId; } //Genre to keep var genre = _ctx.Genres.FirstOrDefault(x => x.Id == removeId); if (genre != null) { _ctx.Genres.Remove(genre); } _ctx.UpdateRange(games); await _ctx.SaveChangesAsync(); transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); throw; } } }
public BaseRepo(RetroDbContext retroDbContext) { _ctx = retroDbContext; _ctx.ChangeTracker.AutoDetectChangesEnabled = false; _ctx.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking; dbSet = retroDbContext.Set <TEntity>(); }
public InsertUniqueTests() { if (!_created) { using (_ctx = new RetroDbContext(conString)) { _ctx.Database.EnsureCreated(); _created = true; } } }
public UnitOfWork(string connstring) { _ctx = new RetroDbContext(connstring); _constring = connstring; }