/// <inheritdoc /> public void UseTransaction(DbTransaction transaction) { var efTransaction = Database.UseTransaction(transaction); var curiosityTransaction = new CuriosityDbTransaction(efTransaction); _transaction = curiosityTransaction; _transaction.OnTransactionCompleted += () => OnTransactionCompleted?.Invoke(); }
/// <inheritdoc /> public async Task CommitAsync(CancellationToken cancellationToken = default) { await _efDbContextTransaction.CommitAsync(cancellationToken); OnTransactionCompleted?.Invoke(); if (OnTransactionCompletedAsync != null) { await OnTransactionCompletedAsync.Invoke(cancellationToken); } }
/// <inheritdoc /> public void Commit() { _efDbContextTransaction.Commit(); OnTransactionCompleted?.Invoke(); // this is bad but we don't have any valid ways if (OnTransactionCompletedAsync != null) { OnTransactionCompletedAsync.Invoke(CancellationToken.None).GetAwaiter().GetResult(); } }
/// <inheritdoc /> public async Task <ICuriosityDataContextTransaction> BeginTransactionAsync(IsolationLevel isolationLevel = IsolationLevel.ReadCommitted, CancellationToken cancellationToken = default) { var transaction = await base.Database.BeginTransactionAsync(isolationLevel, cancellationToken); var curiosityTransaction = new CuriosityDbTransaction(transaction); _transaction = curiosityTransaction; _transaction.OnTransactionCompleted += () => OnTransactionCompleted?.Invoke(); _transaction.OnTransactionCompletedAsync += ct => OnTransactionCompletedAsync != null ? OnTransactionCompletedAsync.Invoke(ct) : Task.CompletedTask; return(curiosityTransaction); }
/// <inheritdoc /> public ICuriosityDataContextTransaction BeginTransaction(IsolationLevel isolationLevel = IsolationLevel.ReadCommitted) { var transaction = base.Database.BeginTransaction(isolationLevel); var curiosityTransaction = new CuriosityDbTransaction(transaction); _transaction = curiosityTransaction; _transaction.OnTransactionCompleted += () => OnTransactionCompleted?.Invoke(); _transaction.OnTransactionCompletedAsync += ct => OnTransactionCompletedAsync != null ? OnTransactionCompletedAsync.Invoke(ct) : Task.CompletedTask; return(curiosityTransaction); }
/// <summary> /// Notifies subscribers about successfully completed transaction. /// </summary> private void NotifyAboutTransaction() { // if no transaction and there is AutoTransactions Enabled let's invoke event // in other cases event will be invoked on created transaction if (_transaction == null && Database.AutoTransactionsEnabled) { OnTransactionCompleted?.Invoke(); if (OnTransactionCompletedAsync != null) { OnTransactionCompletedAsync.Invoke(CancellationToken.None).GetAwaiter().GetResult(); } // reset subscribers OnTransactionCompleted = null; OnTransactionCompletedAsync = null; } }
/// <summary> /// Notifies subscribers about successfully completed transaction. /// </summary> private async ValueTask NotifyAboutTransactionAsync(CancellationToken cancellationToken = default) { // if no transaction and there is AutoTransactions Enabled let's invoke event // in other cases event will be invoked on created transaction if (_transaction == null && Database.AutoTransactionsEnabled) { OnTransactionCompleted?.Invoke(); if (OnTransactionCompletedAsync != null) { await OnTransactionCompletedAsync.Invoke(cancellationToken); } // reset subscribers OnTransactionCompleted = null; OnTransactionCompletedAsync = null; } }
private void BtnOk_Click(object sender, EventArgs e) { OnTransactionCompleted?.Invoke(this, EventArgs.Empty); }