public async Task <IApiResult> CommitAsync(IApiResult result, CancellationToken cancellationToken = default) { result = await SaveAsync(result, cancellationToken); if (result.Success) { _contextTransaction?.CommitAsync(cancellationToken); } HasOpenTransaction = false; return(result); }
public async Task CommitAsync(CancellationToken cancellationToken = default) { await _dbContextTransaction?.CommitAsync(cancellationToken); if (_dbTransaction is DbTransaction transaction) { await transaction.CommitAsync(cancellationToken); } else { _dbTransaction?.Commit(); } }
public async Task CommitAsync(CancellationToken cancellationToken = default) { if (IsCommit) { return; } IsCommit = true; await _dbContext.SaveChangesAsync(); await _dbContextTransaction?.CommitAsync(cancellationToken); }
public async Task CompletedAsync() { if (_readOnly) { return; } _dataModelContext.ChangeTracker.DetectChanges(); await _dataModelContext.SaveChangesAsync(); if (_transaction != null) { await _transaction?.CommitAsync(); } }
public async Task <int> CommitAsync(CancellationToken cancellationToken = default) { try { await SaveAsync(cancellationToken); if (_changes > 0) { _contextTransaction?.CommitAsync(cancellationToken); } return(_changes); } catch (Exception dbUpdateException) { await RollbackTransactionAsync(cancellationToken); throw new DbUpdateException( "Data constraint violation. Register is invalid or Already exists.", dbUpdateException); } }
public async Task CommitTransactionAsync() { try { //await SaveChangesAsync(); await _currentTransaction?.CommitAsync(); } catch { RollbackTransaction(); throw; } finally { if (_currentTransaction != null) { _currentTransaction.Dispose(); _currentTransaction = null; } } }
public async Task CommitTransactionAsync() { try{ await SaveChangesAsync().ConfigureAwait(false); await(_currentTransaction?.CommitAsync() ?? Task.CompletedTask); } catch { RollbackTransaction(); throw; } finally { if (_currentTransaction != null) { _currentTransaction.Dispose(); _currentTransaction = null; } } }
public Task Commit() => m_transaction.CommitAsync();
public async ValueTask Commit(CancellationToken cancellationToken = default) { await _transaction.CommitAsync(cancellationToken); }
static async Task Main(string[] args) { using (Context context = new Context()) { //context.Database.EnsureDeleted(); context.Database.EnsureCreated(); Console.Write("Enter fullname: "); string fullname = Console.ReadLine(); Console.Write("Enter Country: "); string country = Console.ReadLine(); Console.Write("Enter City: "); string city = Console.ReadLine(); using (HttpClient client = new HttpClient()) { client.DefaultRequestHeaders.Add("User-Agent", "C# App"); HttpResponseMessage pointsResponse = await client.GetAsync("https://nominatim.openstreetmap.org/search?country=" + country + "&city=" + city + "&format=jsonv2"); if (pointsResponse.IsSuccessStatusCode) { if (pointsResponse.Content.Headers.ContentLength != 2) { List <SearchJson> roots = await pointsResponse.Content.ReadFromJsonAsync <List <SearchJson> >(); if (roots.Count() > 0 && roots.First().type == "city") { IQueryable <UserData> users = from user in context.Users where (user.FullName == fullname) select user; if (users.Count() > 0) { Console.WriteLine("User is exists"); } else { IDbContextTransaction transaction = await context.Database.BeginTransactionAsync(); try { Console.WriteLine($"Registering user"); UserData newUser = new UserData() { FullName = fullname, Country = country, City = city }; context.Users.Add(newUser); await transaction.CommitAsync(); await context.SaveChangesAsync(); Console.WriteLine("SUCCESS"); } catch { Console.WriteLine("FAILED"); } } } else { Console.WriteLine("Bad city"); } } else { Console.WriteLine("Bad country"); } } else { string resp = await pointsResponse.Content.ReadAsStringAsync(); Console.WriteLine(resp); } } } }
public async Task <IActionResult> UpdateStudentPersonalInfo(StudentPersonalInfoVM studentPersonalInfo) { try { if (ModelState.IsValid) { using (IDbContextTransaction transaction = _context.Database.BeginTransaction()) { try { //check if email or phone already exist in the DB bool duplicateEmail = await _context.Users.AnyAsync(u => u.Id != studentPersonalInfo.userId && u.Email == studentPersonalInfo.email); bool duplicatePhone = await _context.Users.AnyAsync(u => u.Id != studentPersonalInfo.userId && u.PhoneNumber == studentPersonalInfo.phoneNumber); if (duplicateEmail && duplicatePhone) { throw new Exception("Ëmail address and Phone number both already exist!"); } else if (duplicateEmail) { throw new Exception("Ëmail address already exist!"); } else if (duplicatePhone) { throw new Exception("Phone number both already exist!"); } var user = await _context.Users.FirstOrDefaultAsync(u => u.Id == studentPersonalInfo.userId); user.Email = studentPersonalInfo.email; user.PhoneNumber = studentPersonalInfo.phoneNumber; await _context.SaveChangesAsync(); var userInfo = await _context.UserInformation.FirstOrDefaultAsync(u => u.UserId == studentPersonalInfo.userId); userInfo.Firstname = studentPersonalInfo.firstName; userInfo.Lastname = studentPersonalInfo.lastName; userInfo.DateOfBirth = studentPersonalInfo.dateOfBirth; userInfo.Gender = studentPersonalInfo.gender; userInfo.Address = studentPersonalInfo.address; await _context.SaveChangesAsync(); await transaction.CommitAsync(); return(Ok()); } catch (Exception ex) { await transaction.RollbackAsync(); return(StatusCode(500, ex.Message)); } } } else { return(StatusCode(500, "Invalid data!")); } } catch (Exception) { throw; } }
public async Task <IActionResult> UpdateStudentPI(StudentPIVM studentPIVM) { try { if (ModelState.IsValid) { using (IDbContextTransaction transaction = _context.Database.BeginTransaction()) { try { var userInfo = await _context.UserInformation.FirstOrDefaultAsync(u => u.UserId == studentPIVM.userId); userInfo.FatherName = studentPIVM.fatherName; userInfo.MotherName = studentPIVM.motherName; userInfo.FatherQualification = studentPIVM.fatherQualification; userInfo.MotherQualification = studentPIVM.motherQualification; userInfo.FatherProfession = studentPIVM.fatherProfession; userInfo.MotherProfession = studentPIVM.motherProfession; userInfo.Siblings = studentPIVM.siblings; userInfo.ElderorYounger = studentPIVM.elderYounger; userInfo.FamilyIncome = studentPIVM.familyIncome; userInfo.FamilyType = studentPIVM.familyType; userInfo.Grades = studentPIVM.grades; userInfo.FavoriteSubject = studentPIVM.favouriteSubject; userInfo.Achievements = studentPIVM.achievements; userInfo.PositionOfResponsibility = studentPIVM.positionOfResponsibility; userInfo.Facebook = studentPIVM.facebook; userInfo.Instagram = studentPIVM.instagram; userInfo.Linkedin = studentPIVM.linkedIn; userInfo.Twitter = studentPIVM.twitter; userInfo.HowManyFriends = studentPIVM.numberofFriends; userInfo.BestVacation = studentPIVM.bestVacation; userInfo.DreamCareer1 = studentPIVM.dreamCareer1; userInfo.DreamCareer2 = studentPIVM.dreamCareer2; userInfo.WhatMotivatesYou = studentPIVM.motivation; userInfo.WhyThisCareer = studentPIVM.whyThisCareer; userInfo.DifferentlyAbled = studentPIVM.differentlyAbled; userInfo.ExpectationsFromUpclass = studentPIVM.expectationFromUpclass; userInfo.HowYourFriendsDescribeYou = studentPIVM.howYourFriendsDescribeYou; userInfo.HowYourParentsDecribeYou = studentPIVM.howYourParentsDescribeYou; await _context.SaveChangesAsync(); await transaction.CommitAsync(); return(Ok()); } catch (Exception ex) { await transaction.RollbackAsync(); return(StatusCode(500, ex.Message)); } } } else { return(StatusCode(500, "Invalid data!")); } } catch (Exception ex) { return(StatusCode(500, ex.Message)); } }
public virtual Task CommitAsync(CancellationToken cancellationToken = default) { DbContextTransaction?.CommitAsync(cancellationToken); return(Task.CompletedTask); }
/// <summary> /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to /// the same compatibility standards as public APIs. It may be changed or removed without notice in /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// </summary> public virtual async Task ExecuteNonQueryAsync( IEnumerable <MigrationCommand> migrationCommands, IRelationalConnection connection, CancellationToken cancellationToken = default) { Check.NotNull(migrationCommands, nameof(migrationCommands)); Check.NotNull(connection, nameof(connection)); var transactionScope = new TransactionScope(TransactionScopeOption.Suppress, TransactionScopeAsyncFlowOption.Enabled); try { await connection.OpenAsync(cancellationToken); try { IDbContextTransaction transaction = null; try { foreach (var command in migrationCommands) { if (transaction == null && !command.TransactionSuppressed) { transaction = await connection.BeginTransactionAsync(cancellationToken); } if (transaction != null && command.TransactionSuppressed) { await transaction.CommitAsync(cancellationToken); await transaction.DisposeAsync(); transaction = null; } await command.ExecuteNonQueryAsync(connection, cancellationToken : cancellationToken); } if (transaction != null) { await transaction.CommitAsync(cancellationToken); } } finally { if (transaction != null) { await transaction.DisposeAsync(); } } } finally { await connection.CloseAsync(); } } finally { await transactionScope.DisposeAsyncIfAvailable(); } }
public Task CommitAsync(CancellationToken cancellationToken = default) { return(_transaction.CommitAsync(cancellationToken)); }
public Task?CommitAsync(CancellationToken cancellationToken = default) { return(_dbContextTransaction?.CommitAsync(cancellationToken)); }
public async Task CommitAsync() { await _transaction?.CommitAsync(); await _transaction.DisposeAsync(); }
public async Task CommitTransactionAsync(CancellationToken cancellationToken = default) { await _dbContextTransaction.CommitAsync(cancellationToken); }
public async Task Commit(IDbContextTransaction transaction) { await this.dbContext.SaveChangesAsync().ConfigureAwait(false); await transaction.CommitAsync().ConfigureAwait(false); }
public void CommitTransaction(IDbContextTransaction transaction) { transaction.CommitAsync(); }
public async Task CompleteAsync() { await _dbContextTransaction.CommitAsync(); }
public Task CommitAsync(IDbContextTransaction transaction, CancellationToken cancellationToken) => transaction.CommitAsync(cancellationToken);
public async Task CommitAsync(IDbContextTransaction transaction) { await transaction?.CommitAsync(); }
/// <summary> /// 提交当前工作单元事务 /// </summary> /// <returns></returns> public async Task CommitAsync() { await _dbContextTransaction.CommitAsync(); await _dbContextTransaction.DisposeAsync(); }
public async Task?CommitAsync(CancellationToken cancellationToken = default) { await _dbContext?.SaveChangesAsync(cancellationToken) !; await _dbContextTransaction?.CommitAsync(cancellationToken) !; }
public Task Commit() { return(_transaction.CommitAsync()); }
public Task Commit(CancellationToken cancellationToken = default) { return(_objTran?.CommitAsync(cancellationToken)); }
public async Task ExplicitAndImplicitTransactionIsRetried(bool disableInternalRetries, bool useExplicitTransaction) { // Abort the next statement that is executed on the mock server. _fixture.SpannerMock.AbortNextStatement(); using var db = new MockServerSampleDbContextUsingMutations(ConnectionString); IDbContextTransaction transaction = null; if (useExplicitTransaction) { // Note that using explicit transactions in combination with mutations has a couple of side-effects: // 1. Read-your-writes does not work. // 2. Computed columns are not propagated to the current context. transaction = await db.Database.BeginTransactionAsync(); if (disableInternalRetries) { transaction.DisableInternalRetries(); } } db.Venues.Add(new Venues { Code = "C1", Name = "Concert Hall", }); // We can only disable internal retries when using explicit transactions. Otherwise internal retries // are always used. if (disableInternalRetries && useExplicitTransaction) { await db.SaveChangesAsync(); var e = await Assert.ThrowsAsync <SpannerException>(() => transaction.CommitAsync()); Assert.Equal(ErrorCode.Aborted, e.ErrorCode); } else { var updateCount = await db.SaveChangesAsync(); Assert.Equal(1L, updateCount); if (useExplicitTransaction) { await transaction.CommitAsync(); } Assert.Empty(_fixture.SpannerMock.Requests.Where(request => request is ExecuteBatchDmlRequest)); Assert.Collection( _fixture.SpannerMock.Requests.Where(request => request is CommitRequest).Select(request => (CommitRequest)request), // The commit request is sent twice to the server, as the statement is aborted during the first attempt. request => { Assert.Single(request.Mutations); Assert.Equal("Venues", request.Mutations.First().Insert.Table); Assert.NotNull(request.TransactionId); }, request => { Assert.Single(request.Mutations); Assert.Equal("Venues", request.Mutations.First().Insert.Table); Assert.NotNull(request.TransactionId); } ); } }
public async Task Commit() { await _transaction.CommitAsync(); }
private static async Task <Tuple <bool, string> > TransactionAsync(this IDbContextTransaction trans, bool success, string message) { await(success ? trans.CommitAsync() : trans.RollbackAsync()); return(new Tuple <bool, string>(success, message)); }