public async ValueTask <bool> MoveNextAsync() { try { using (_relationalQueryContext.ConcurrencyDetector.EnterCriticalSection()) { if (_dataReader == null) { if (_executionStrategy == null) { _executionStrategy = _relationalQueryContext.ExecutionStrategyFactory.Create(); } await _executionStrategy.ExecuteAsync(true, InitializeReaderAsync, null, _cancellationToken); } var hasNext = _resultCoordinator.HasNext ?? await _dataReader.ReadAsync(_cancellationToken); Current = default; if (hasNext) { while (true) { _resultCoordinator.ResultReady = true; _resultCoordinator.HasNext = null; Current = _shaper( _relationalQueryContext, _dataReader.DbDataReader, _resultCoordinator.ResultContext, _indexMap, _resultCoordinator); if (_resultCoordinator.ResultReady) { // We generated a result so null out previously stored values _resultCoordinator.ResultContext.Values = null; break; } if (!await _dataReader.ReadAsync(_cancellationToken)) { _resultCoordinator.HasNext = false; // Enumeration has ended, materialize last element _resultCoordinator.ResultReady = true; Current = _shaper( _relationalQueryContext, _dataReader.DbDataReader, _resultCoordinator.ResultContext, _indexMap, _resultCoordinator); break; } } } return(hasNext); } } catch (Exception exception) { _logger.QueryIterationFailed(_contextType, exception); throw; } }
private async Task <bool> BufferlessMoveNext(DbContext _, bool buffer, CancellationToken cancellationToken) { if (_dataReader == null) { await _relationalQueryContext.Connection.OpenAsync(cancellationToken); try { var relationalCommand = _shaperCommandContext .GetRelationalCommand(_relationalQueryContext.ParameterValues, _relationalQueryContext); await _relationalQueryContext.Connection .RegisterBufferableAsync(this, cancellationToken); _dataReader = await relationalCommand.ExecuteReaderAsync( _relationalQueryContext.Connection, _relationalQueryContext.ParameterValues, _relationalQueryContext.CommandLogger, cancellationToken); } catch { // If failure happens creating the data reader, then it won't be available to // handle closing the connection, so do it explicitly here to preserve ref counting. _relationalQueryContext.Connection.Close(); throw; } _dbDataReader = _dataReader.DbDataReader; _shaperCommandContext.NotifyReaderCreated(_dbDataReader); _valueBufferFactory = _shaperCommandContext.ValueBufferFactory; } var hasNext = await _dataReader.ReadAsync(cancellationToken); Current = hasNext ? _shaper.Shape(_relationalQueryContext, _valueBufferFactory.Create(_dbDataReader)) : default; if (buffer) { await BufferAllAsync(cancellationToken); } return(hasNext); }
private async Task <bool> BufferlessMoveNext(bool buffer, CancellationToken cancellationToken) { try { if (_dataReader == null) { await _relationalQueryContext.Connection.OpenAsync(cancellationToken); var relationalCommand = _shaperCommandContext .GetRelationalCommand(_relationalQueryContext.ParameterValues); await _relationalQueryContext.Connection .RegisterBufferableAsync(this, cancellationToken); _dataReader = await relationalCommand.ExecuteReaderAsync( _relationalQueryContext.Connection, _relationalQueryContext.ParameterValues, cancellationToken); _dbDataReader = _dataReader.DbDataReader; _shaperCommandContext.NotifyReaderCreated(_dbDataReader); _valueBufferFactory = _shaperCommandContext.ValueBufferFactory; } var hasNext = await _dataReader.ReadAsync(cancellationToken); Current = hasNext ? _shaper.Shape(_relationalQueryContext, _valueBufferFactory.Create(_dbDataReader)) : default(T); if (buffer) { await BufferAllAsync(cancellationToken); } return(hasNext); } catch (Exception) { _dataReader = null; _dbDataReader = null; throw; } }
public async ValueTask <bool> MoveNextAsync() { try { using (_relationalQueryContext.ConcurrencyDetector.EnterCriticalSection()) { if (_dataReader == null) { await _relationalQueryContext.ExecutionStrategyFactory.Create() .ExecuteAsync(true, InitializeReaderAsync, null, _cancellationToken).ConfigureAwait(false); } var hasNext = await _dataReader.ReadAsync(_cancellationToken).ConfigureAwait(false); Current = hasNext ? _shaper(_relationalQueryContext, _dataReader.DbDataReader, _indexMap) : default; return(hasNext); } } catch (Exception exception) { _queryLogger.QueryIterationFailed(_contextType, exception); throw; } }
/// <summary> /// Consumes the data reader created by <see cref="ReaderModificationCommandBatch.ExecuteAsync" /> /// without propagating values back into the <see cref="ModificationCommand" />. /// </summary> /// <param name="commandIndex"> The ordinal of the command being consumed. </param> /// <param name="reader"> The data reader. </param> /// <param name="cancellationToken"> A <see cref="CancellationToken" /> to observe while waiting for the task to complete. </param> /// <returns> /// A task that represents the asynchronous operation. /// The task contains the ordinal of the next command that must be consumed. /// </returns> /// <exception cref="OperationCanceledException"> If the <see cref="CancellationToken"/> is canceled. </exception> protected virtual async Task <int> ConsumeResultSetWithoutPropagationAsync( int commandIndex, RelationalDataReader reader, CancellationToken cancellationToken) { var expectedRowsAffected = 1; while (++commandIndex < CommandResultSet.Count && CommandResultSet[commandIndex - 1] == ResultSetMapping.NotLastInResultSet) { Check.DebugAssert(!ModificationCommands[commandIndex].RequiresResultPropagation, "RequiresResultPropagation is true"); expectedRowsAffected++; } if (await reader.ReadAsync(cancellationToken).ConfigureAwait(false)) { var rowsAffected = reader.DbDataReader.GetInt32(0); if (rowsAffected != expectedRowsAffected) { ThrowAggregateUpdateConcurrencyException(commandIndex, expectedRowsAffected, rowsAffected); } } else { ThrowAggregateUpdateConcurrencyException(commandIndex, 1, 0); } return(commandIndex); }
/// <summary> /// Consumes the data reader created by <see cref="ReaderModificationCommandBatch.ExecuteAsync" />, /// propagating values back into the <see cref="ModificationCommand" />. /// </summary> /// <param name="commandIndex"> The ordinal of the command being consumed. </param> /// <param name="reader"> The data reader. </param> /// <param name="cancellationToken"> A <see cref="CancellationToken" /> to observe while waiting for the task to complete. </param> /// <returns> /// A task that represents the asynchronous operation. /// The task contains the ordinal of the next command that must be consumed. /// </returns> /// <exception cref="OperationCanceledException"> If the <see cref="CancellationToken"/> is canceled. </exception> protected virtual async Task <int> ConsumeResultSetWithPropagationAsync( int commandIndex, RelationalDataReader reader, CancellationToken cancellationToken) { var rowsAffected = 0; do { var tableModification = ModificationCommands[commandIndex]; Check.DebugAssert(tableModification.RequiresResultPropagation, "RequiresResultPropagation is false"); if (!await reader.ReadAsync(cancellationToken).ConfigureAwait(false)) { var expectedRowsAffected = rowsAffected + 1; while (++commandIndex < CommandResultSet.Count && CommandResultSet[commandIndex - 1] == ResultSetMapping.NotLastInResultSet) { expectedRowsAffected++; } ThrowAggregateUpdateConcurrencyException(commandIndex, expectedRowsAffected, rowsAffected); } var valueBufferFactory = CreateValueBufferFactory(tableModification.ColumnModifications); tableModification.PropagateResults(valueBufferFactory.Create(reader.DbDataReader)); rowsAffected++; }while (++commandIndex < CommandResultSet.Count && CommandResultSet[commandIndex - 1] == ResultSetMapping.NotLastInResultSet); return(commandIndex); }
protected override async Task ConsumeAsync(RelationalDataReader reader, CancellationToken cancellationToken = new CancellationToken()) { var npgsqlReader = (ClickHouseDataReader)reader.DbDataReader; var commandIndex = 0; try { while (true) { // Find the next propagating command, if any int nextPropagating; for (nextPropagating = commandIndex; nextPropagating < ModificationCommands.Count && !ModificationCommands[nextPropagating].RequiresResultPropagation; nextPropagating++) { ; } if (nextPropagating == ModificationCommands.Count) { Debug.Assert(!(await npgsqlReader.NextResultAsync(cancellationToken)), "Expected less resultsets"); break; } // Extract result from the command and propagate it var modificationCommand = ModificationCommands[commandIndex++]; if (!(await reader.ReadAsync(cancellationToken))) { throw new DbUpdateConcurrencyException( RelationalStrings.UpdateConcurrencyException(1, 0), modificationCommand.Entries ); } var valueBufferFactory = CreateValueBufferFactory(modificationCommand.ColumnModifications); modificationCommand.PropagateResults(valueBufferFactory.Create(npgsqlReader)); await npgsqlReader.NextResultAsync(cancellationToken); } } catch (DbUpdateException) { throw; } catch (Exception ex) { throw new DbUpdateException( RelationalStrings.UpdateStoreException, ex, ModificationCommands[commandIndex].Entries); } }
public async Task <bool> MoveNext(CancellationToken cancellationToken) { try { if (_dataReader == null) { await _relationalQueryContext.Connection.OpenAsync(cancellationToken); try { var selectExpression = new ParameterValueBasedSelectExpressionOptimizer( _sqlExpressionFactory, _parameterNameGeneratorFactory) .Optimize(_selectExpression, _relationalQueryContext.ParameterValues); var relationalCommand = _querySqlGeneratorFactory.Create().GetCommand(selectExpression); _dataReader = await relationalCommand.ExecuteReaderAsync( _relationalQueryContext.Connection, _relationalQueryContext.ParameterValues, _relationalQueryContext.CommandLogger, cancellationToken); _resultCoordinator = new ResultCoordinator(); } catch (Exception) { // If failure happens creating the data reader, then it won't be available to // handle closing the connection, so do it explicitly here to preserve ref counting. _relationalQueryContext.Connection.Close(); throw; } } var hasNext = _resultCoordinator.HasNext ?? await _dataReader.ReadAsync(cancellationToken); _resultCoordinator.HasNext = null; Current = hasNext ? await _shaper(_relationalQueryContext, _dataReader.DbDataReader, _resultCoordinator) : default; return(hasNext); } catch (Exception exception) { _logger.QueryIterationFailed(_contextType, exception); throw; } }
public async Task <bool> MoveNext(CancellationToken cancellationToken) { if (_dataReader == null) { await _relationalQueryContext.Connection.OpenAsync(cancellationToken); try { var relationalCommand = _querySqlGenerator .GetCommand( _selectExpression, _relationalQueryContext.ParameterValues, _relationalQueryContext.CommandLogger); _dataReader = await relationalCommand.ExecuteReaderAsync( _relationalQueryContext.Connection, _relationalQueryContext.ParameterValues, _relationalQueryContext.CommandLogger, cancellationToken); } catch (Exception exception) { _logger.QueryIterationFailed(_contextType, exception); // If failure happens creating the data reader, then it won't be available to // handle closing the connection, so do it explicitly here to preserve ref counting. _relationalQueryContext.Connection.Close(); throw; } } try { var hasNext = await _dataReader.ReadAsync(cancellationToken); Current = hasNext ? await _shaper(_relationalQueryContext, _dataReader.DbDataReader) : default; return(hasNext); } catch (Exception exception) { _logger.QueryIterationFailed(_contextType, exception); throw; } }
public async ValueTask <bool> MoveNextAsync() { try { using (_relationalQueryContext.ConcurrencyDetector.EnterCriticalSection()) { if (_dataReader == null) { if (_executionStrategy == null) { _executionStrategy = _relationalQueryContext.ExecutionStrategyFactory.Create(); } await _executionStrategy.ExecuteAsync( true, InitializeReaderAsync, null, _relationalQueryContext.CancellationToken).ConfigureAwait(false); } var hasNext = await _dataReader.ReadAsync(_relationalQueryContext.CancellationToken).ConfigureAwait(false); Current = default; if (hasNext) { _resultCoordinator.ResultContext.Values = null; _shaper( _relationalQueryContext, _dataReader.DbDataReader, _resultCoordinator.ResultContext, _resultCoordinator); if (_relatedDataLoaders != null) { await _relatedDataLoaders(_relationalQueryContext, _executionStrategy, _resultCoordinator) .ConfigureAwait(false); } Current = _shaper( _relationalQueryContext, _dataReader.DbDataReader, _resultCoordinator.ResultContext, _resultCoordinator); } return(hasNext); } } catch (Exception exception) { _queryLogger.QueryIterationFailed(_contextType, exception); throw; } }
public async Task BufferAllAsync(CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); if (_buffer == null && _dataReader != null) { _buffer = new Queue <ValueBuffer>(); using (_dataReader) { while (await _dataReader.ReadAsync(cancellationToken)) { _buffer.Enqueue(_valueBufferFactory.Create(_dbDataReader)); } } _relationalQueryContext.Connection?.Close(); _dataReader = null; _dbDataReader = null; } }
public ValueTask <bool> MoveNextAsync() { return(new ValueTask <bool>(_dataReader.ReadAsync(_cancellationToken))); }
public async ValueTask <bool> MoveNextAsync() { try { using (_relationalQueryContext.ConcurrencyDetector.EnterCriticalSection()) { if (_dataReader == null) { var selectExpression = new ParameterValueBasedSelectExpressionOptimizer( _sqlExpressionFactory, _parameterNameGeneratorFactory) .Optimize(_selectExpression, _relationalQueryContext.ParameterValues); var relationalCommand = _querySqlGeneratorFactory.Create().GetCommand(selectExpression); _dataReader = await relationalCommand.ExecuteReaderAsync( new RelationalCommandParameterObject( _relationalQueryContext.Connection, _relationalQueryContext.ParameterValues, _relationalQueryContext.Context, _relationalQueryContext.CommandLogger), _cancellationToken); if (selectExpression.IsNonComposedFromSql()) { var projection = _selectExpression.Projection.ToList(); var readerColumns = Enumerable.Range(0, _dataReader.DbDataReader.FieldCount) .ToDictionary(i => _dataReader.DbDataReader.GetName(i), i => i, StringComparer.OrdinalIgnoreCase); _indexMap = new int[projection.Count]; for (var i = 0; i < projection.Count; i++) { if (projection[i].Expression is ColumnExpression columnExpression) { var columnName = columnExpression.Name; if (columnName != null) { if (!readerColumns.TryGetValue(columnName, out var ordinal)) { throw new InvalidOperationException(RelationalStrings.FromSqlMissingColumn(columnName)); } _indexMap[i] = ordinal; } } } } else { _indexMap = null; } _resultCoordinator = new ResultCoordinator(); } var hasNext = _resultCoordinator.HasNext ?? await _dataReader.ReadAsync(); Current = default; if (hasNext) { while (true) { _resultCoordinator.ResultReady = true; _resultCoordinator.HasNext = null; Current = _shaper( _relationalQueryContext, _dataReader.DbDataReader, _resultCoordinator.ResultContext, _indexMap, _resultCoordinator); if (_resultCoordinator.ResultReady) { // We generated a result so null out previously stored values _resultCoordinator.ResultContext.Values = null; break; } if (!await _dataReader.ReadAsync()) { _resultCoordinator.HasNext = false; // Enumeration has ended, materialize last element _resultCoordinator.ResultReady = true; Current = _shaper( _relationalQueryContext, _dataReader.DbDataReader, _resultCoordinator.ResultContext, _indexMap, _resultCoordinator); break; } } } return(hasNext); } } catch (Exception exception) { _logger.QueryIterationFailed(_contextType, exception); throw; } }
public override Task <bool> MoveNextAsync() => _dataReader.ReadAsync();
/// <summary> /// 异步恢复 /// </summary> /// <param name="relationalReader">关系DataReader</param> /// <param name="cancellationToken">取消令牌</param> /// <returns></returns> protected override async Task ConsumeAsync(RelationalDataReader relationalReader, CancellationToken cancellationToken = default(CancellationToken)) { int commandPosition = 0; try { if (Check.IsTraceEnabled(m_oracleLogger?.Logger)) { Trace <DbLoggerCategory.Update> .Write(m_oracleLogger, LogLevel.Trace, OracleTraceTag.Entry, OracleTraceClassName.OracleModificationCommandBatch, OracleTraceFuncName.ConsumeAsync); } while (true) { if (commandPosition < CommandResultSet.Count && CommandResultSet[commandPosition] == ResultSetMapping.NoResultSet) { commandPosition++; } else { if (commandPosition < CommandResultSet.Count) { if (ModificationCommands[commandPosition].RequiresResultPropagation) { int rowsAffected = 0; int num = 0; do { ModificationCommand tableModification = ModificationCommands[commandPosition]; if (!(await relationalReader.ReadAsync(cancellationToken))) { throw new DbUpdateConcurrencyException(RelationalStrings.UpdateConcurrencyException(ModificationCommands.Count((ModificationCommand m) => m.RequiresResultPropagation), rowsAffected), ModificationCommands[commandPosition].Entries); } IRelationalValueBufferFactory relationalValueBufferFactory = CreateValueBufferFactory(tableModification.ColumnModifications); tableModification.PropagateResults(relationalValueBufferFactory.Create(relationalReader.DbDataReader)); rowsAffected++; num = commandPosition + 1; commandPosition = num; }while (num < CommandResultSet.Count && CommandResultSet[commandPosition - 1] == ResultSetMapping.NotLastInResultSet); } else { int expectedRowsAffected = 1; while (true) { int num = commandPosition + 1; commandPosition = num; if (num >= CommandResultSet.Count || CommandResultSet[commandPosition - 1] != ResultSetMapping.NotLastInResultSet) { break; } expectedRowsAffected++; } if (!relationalReader.Read()) { break; } int rowsAffected = relationalReader.DbDataReader.GetInt32(0); if (rowsAffected != expectedRowsAffected) { throw new DbUpdateConcurrencyException(RelationalStrings.UpdateConcurrencyException(expectedRowsAffected, rowsAffected), ModificationCommands[commandPosition - 1].Entries); } } } bool flag = commandPosition < CommandResultSet.Count; if (flag) { flag = await relationalReader.DbDataReader.NextResultAsync(cancellationToken); } if (!flag) { return; } } } throw new DbUpdateConcurrencyException(RelationalStrings.UpdateConcurrencyException(1, 0), ModificationCommands[commandPosition - 1].Entries); } catch (DbUpdateException dbEx) { if (Check.IsErrorEnabled(m_oracleLogger?.Logger)) { Trace <DbLoggerCategory.Update> .Write(m_oracleLogger, LogLevel.Error, OracleTraceTag.Error, OracleTraceClassName.OracleModificationCommandBatch, OracleTraceFuncName.ConsumeAsync, dbEx.ToString()); } throw; } catch (Exception ex) { if (Check.IsErrorEnabled(m_oracleLogger?.Logger)) { Trace <DbLoggerCategory.Update> .Write(m_oracleLogger, LogLevel.Error, OracleTraceTag.Error, OracleTraceClassName.OracleModificationCommandBatch, OracleTraceFuncName.ConsumeAsync, ex.ToString()); } throw new DbUpdateException(RelationalStrings.UpdateStoreException, ex, ModificationCommands[commandPosition].Entries); } }
public async Task <bool> MoveNext(CancellationToken cancellationToken) { try { if (_dataReader == null) { _relationalQueryContext.Connection.Open(); try { var projection = _selectExpression.Projection.ToList(); var selectExpression = new ParameterValueBasedSelectExpressionOptimizer( _sqlExpressionFactory, _parameterNameGeneratorFactory) .Optimize(_selectExpression, _relationalQueryContext.ParameterValues); var relationalCommand = _querySqlGeneratorFactory.Create().GetCommand(selectExpression); _dataReader = await relationalCommand.ExecuteReaderAsync( _relationalQueryContext.Connection, _relationalQueryContext.ParameterValues, _relationalQueryContext.CommandLogger, cancellationToken); var readerColumns = Enumerable.Range(0, _dataReader.DbDataReader.FieldCount) .Select( i => new { Name = _dataReader.DbDataReader.GetName(i), Ordinal = i }).ToList(); _indexMap = new int[projection.Count]; for (var i = 0; i < projection.Count; i++) { if (projection[i].Expression is ColumnExpression columnExpression) { var columnName = columnExpression.Name; if (columnName != null) { var readerColumn = readerColumns.SingleOrDefault( c => string.Equals(columnName, c.Name, StringComparison.OrdinalIgnoreCase)); if (readerColumn == null) { throw new InvalidOperationException(RelationalStrings.FromSqlMissingColumn(columnName)); } _indexMap[i] = readerColumn.Ordinal; } } } } catch (Exception) { // If failure happens creating the data reader, then it won't be available to // handle closing the connection, so do it explicitly here to preserve ref counting. _relationalQueryContext.Connection.Close(); throw; } } var hasNext = await _dataReader.ReadAsync(cancellationToken); Current = hasNext ? await _shaper(_relationalQueryContext, _dataReader.DbDataReader, _indexMap) : default; return(hasNext); } catch (Exception exception) { _logger.QueryIterationFailed(_contextType, exception); throw; } }
protected override async Task ConsumeAsync( RelationalDataReader reader, CancellationToken cancellationToken = default) { var npgsqlReader = (NpgsqlDataReader)reader.DbDataReader; #pragma warning disable 618 Debug.Assert(npgsqlReader.Statements.Count == ModificationCommands.Count, $"Reader has {npgsqlReader.Statements.Count} statements, expected {ModificationCommands.Count}"); #pragma warning restore 618 var commandIndex = 0; try { while (true) { // Find the next propagating command, if any int nextPropagating; for (nextPropagating = commandIndex; nextPropagating < ModificationCommands.Count && !ModificationCommands[nextPropagating].RequiresResultPropagation; nextPropagating++) { } // Go over all non-propagating commands before the next propagating one, // make sure they executed for (; commandIndex < nextPropagating; commandIndex++) { #pragma warning disable 618 if (npgsqlReader.Statements[commandIndex].Rows == 0) { throw new DbUpdateConcurrencyException( RelationalStrings.UpdateConcurrencyException(1, 0), ModificationCommands[commandIndex].Entries ); } #pragma warning restore 618 } if (nextPropagating == ModificationCommands.Count) { Debug.Assert(!(await npgsqlReader.NextResultAsync(cancellationToken).ConfigureAwait(false)), "Expected less resultsets"); break; } // Extract result from the command and propagate it var modificationCommand = ModificationCommands[commandIndex++]; if (!(await reader.ReadAsync(cancellationToken).ConfigureAwait(false))) { throw new DbUpdateConcurrencyException( RelationalStrings.UpdateConcurrencyException(1, 0), modificationCommand.Entries ); } var valueBufferFactory = CreateValueBufferFactory(modificationCommand.ColumnModifications); modificationCommand.PropagateResults(valueBufferFactory.Create(npgsqlReader)); await npgsqlReader.NextResultAsync(cancellationToken).ConfigureAwait(false); } } catch (DbUpdateException) { throw; } catch (Exception ex) { throw new DbUpdateException( RelationalStrings.UpdateStoreException, ex, ModificationCommands[commandIndex].Entries); } }
public Task <bool> MoveNext(CancellationToken cancellationToken) { return(_dataReader.ReadAsync(cancellationToken)); }
protected override async Task ConsumeAsync( RelationalDataReader relationalReader, CancellationToken cancellationToken = default) { var commandPosition = 0; int rowsAffected; try { do { while (commandPosition < CommandResultSet.Count && CommandResultSet[commandPosition] == ResultSetMapping.NoResultSet) { commandPosition++; } if (commandPosition < CommandResultSet.Count) { if (ModificationCommands[commandPosition].RequiresResultPropagation) { rowsAffected = 0; do { var tableModification = ModificationCommands[commandPosition]; if (!await relationalReader.ReadAsync(cancellationToken)) { throw new DbUpdateConcurrencyException( RelationalStrings.UpdateConcurrencyException( ModificationCommands.Count(m => m.RequiresResultPropagation), rowsAffected), ModificationCommands[commandPosition].Entries); } var valueBufferFactory = CreateValueBufferFactory(tableModification.ColumnModifications); tableModification.PropagateResults(valueBufferFactory.Create(relationalReader.DbDataReader)); rowsAffected++; }while (++commandPosition < CommandResultSet.Count && CommandResultSet[commandPosition - 1] == ResultSetMapping.NotLastInResultSet); } else { var expectedRowsAffected = 1; while (++commandPosition < CommandResultSet.Count && CommandResultSet[commandPosition - 1] == ResultSetMapping.NotLastInResultSet) { expectedRowsAffected++; } if (relationalReader.Read()) { rowsAffected = relationalReader.DbDataReader.GetInt32(0); if (rowsAffected != expectedRowsAffected) { throw new DbUpdateConcurrencyException( RelationalStrings.UpdateConcurrencyException(expectedRowsAffected, rowsAffected), ModificationCommands[commandPosition - 1].Entries); } } else { throw new DbUpdateConcurrencyException( RelationalStrings.UpdateConcurrencyException(1, 0), ModificationCommands[commandPosition - 1].Entries); } } } }while (commandPosition < CommandResultSet.Count && await relationalReader.DbDataReader.NextResultAsync(cancellationToken)); } catch (DbUpdateException) { throw; } catch (Exception ex) { throw new DbUpdateException( RelationalStrings.UpdateStoreException, ex, ModificationCommands[commandPosition].Entries); } }
protected override async Task ConsumeAsync(RelationalDataReader relationalReader, CancellationToken cancellationToken = default(CancellationToken)) { if (relationalReader == null) { throw new ArgumentNullException(nameof(relationalReader)); } var dataReader = relationalReader.DbDataReader; var commandIndex = 0; try { while (true) { while (commandIndex < CommandResultSet.Count && CommandResultSet[commandIndex] == ResultSetMapping.NoResultSet) { commandIndex++; } var propragation = commandIndex; while (propragation < ModificationCommands.Count && !ModificationCommands[propragation].RequiresResultPropagation) { propragation++; } while (commandIndex < propragation) { commandIndex++; if (!(await relationalReader.ReadAsync())) { throw new DbUpdateConcurrencyException( RelationalStrings.UpdateConcurrencyException( ModificationCommands.Count(m => m.RequiresResultPropagation), 0), ModificationCommands[commandIndex].Entries); } } //check if you've gone through all notifications if (propragation == ModificationCommands.Count) { break; } var modifications = ModificationCommands[commandIndex]; if (!(await relationalReader.ReadAsync())) { throw new DbUpdateConcurrencyException( RelationalStrings.UpdateConcurrencyException( ModificationCommands.Count(m => m.RequiresResultPropagation), 0), ModificationCommands[commandIndex].Entries); } var bufferFactory = CreateValueBufferFactory(modifications.ColumnModifications); modifications.PropagateResults(bufferFactory.Create(dataReader)); await dataReader.NextResultAsync(); commandIndex++; } } catch (DbUpdateException) { throw; } catch (Exception ex) { throw new DbUpdateException( RelationalStrings.UpdateStoreException, ex, ModificationCommands[commandIndex].Entries); } }