public async Task PostprocessAsync(DbDataReader reader, IList<Exception> exceptions, CancellationToken token)
        {
            await reader.ReadAsync(token).ConfigureAwait(false);

            var values = await reader.GetFieldValueAsync<int[]>(0, token).ConfigureAwait(false);

            applyDataFromSproc(values);
        }
Пример #2
0
    /// <summary>
    /// 使用指定范围内的行异步填充 DataTable 并返回。
    /// </summary>
    /// <param name="dataReader">用来读取数据的 DataReader</param>
    /// <param name="startRecord">要填充的起始记录位置</param>
    /// <param name="maxRecords">最多填充的记录条数</param>
    /// <returns>填充好的 DataTable</returns>
    public async Task<DataTable> FillDataTableAsync( DbDataReader dataReader, int startRecord, int maxRecords )
    {

      var dataTable = new DataTable();

      base.FillSchema( dataTable, SchemaType.Source, dataReader );

      var array = new object[dataReader.FieldCount];

      while ( await dataReader.ReadAsync() )
      {
        dataReader.GetValues( array );
        dataTable.LoadDataRow( array, true );
      }

      return dataTable;
    }
        protected virtual async Task<int> ConsumeResultSetWithoutPropagationAsync(int commandIndex, DbDataReader reader, DbContext context, CancellationToken cancellationToken)
        {
            var expectedRowsAffected = 1;
            while (++commandIndex < ResultSetEnds.Count
                   && !ResultSetEnds[commandIndex - 1])
            {
                Debug.Assert(!ModificationCommands[commandIndex].RequiresResultPropagation);

                expectedRowsAffected++;
            }

            if (await reader.ReadAsync(cancellationToken))
            {
                var rowsAffected = reader.GetInt32(0);
                if (rowsAffected != expectedRowsAffected)
                {
                    ThrowAggregateUpdateConcurrencyException(commandIndex, expectedRowsAffected, rowsAffected);
                }
            }
            else
            {
                ThrowAggregateUpdateConcurrencyException(commandIndex, 1, 0);
            }

            return commandIndex;
        }
        protected virtual async Task<int> ConsumeResultSetWithPropagationAsync(int commandIndex, DbDataReader reader, DbContext context, CancellationToken cancellationToken)
        {
            var rowsAffected = 0;
            do
            {
                var tableModification = ModificationCommands[commandIndex];
                Debug.Assert(tableModification.RequiresResultPropagation);

                if (!await reader.ReadAsync(cancellationToken))
                {
                    var expectedRowsAffected = rowsAffected + 1;
                    while (++commandIndex < ResultSetEnds.Count
                           && !ResultSetEnds[commandIndex - 1])
                    {
                        expectedRowsAffected++;
                    }

                    ThrowAggregateUpdateConcurrencyException(commandIndex, expectedRowsAffected, rowsAffected);
                }

                tableModification.PropagateResults(tableModification.ValueBufferFactory.Create(reader));
                rowsAffected++;
            }
            while (++commandIndex < ResultSetEnds.Count
                   && !ResultSetEnds[commandIndex - 1]);

            return commandIndex;
        }
Пример #5
0
        private async Task<long> getLong(DbDataReader reader)
        {
            await reader.NextResultAsync(_token).ConfigureAwait(false);
            bool isAny = await reader.ReadAsync(_token).ConfigureAwait(false);

            if (!isAny) return 0;

            if (await reader.IsDBNullAsync(0, _token).ConfigureAwait(false))
            {
                return 0;
            }

            return await reader.GetFieldValueAsync<long>(0, _token).ConfigureAwait(false);
        }
        private async Task<int> ConsumeResultSetWithoutPropagationAsync(int commandIndex, DbDataReader reader, DbContext context, CancellationToken cancellationToken)
        {
            var expectedRowsAffected = 1;
            while (++commandIndex < ResultSetEnds.Count
                   && !ResultSetEnds[commandIndex - 1])
            {
                Debug.Assert(!ModificationCommands[commandIndex].RequiresResultPropagation);

                expectedRowsAffected++;
            }

            if (await reader.ReadAsync(cancellationToken).WithCurrentCulture())
            {
                var rowsAffected = reader.GetInt32(0);
                if (rowsAffected != expectedRowsAffected)
                {
                    throw new DbUpdateConcurrencyException(
                        Strings.UpdateConcurrencyException(expectedRowsAffected, rowsAffected),
                        context,
                        AggregateEntries(commandIndex, expectedRowsAffected));
                }
            }
            else
            {
                throw new DbUpdateConcurrencyException(
                    Strings.UpdateConcurrencyException(1, 0),
                    context,
                    AggregateEntries(commandIndex, expectedRowsAffected));
            }

            return commandIndex;
        }
        private async Task<int> ConsumeResultSetWithPropagationAsync(int commandIndex, DbDataReader reader, DbContext context, CancellationToken cancellationToken)
        {
            var rowsAffected = 0;
            var valueReader = new RelationalTypedValueReader(reader);
            do
            {
                var tableModification = ModificationCommands[commandIndex];
                Debug.Assert(tableModification.RequiresResultPropagation);

                if (!await reader.ReadAsync(cancellationToken).WithCurrentCulture())
                {
                    var expectedRowsAffected = rowsAffected + 1;
                    while (++commandIndex < ResultSetEnds.Count
                           && !ResultSetEnds[commandIndex - 1])
                    {
                        expectedRowsAffected++;
                    }

                    throw new DbUpdateConcurrencyException(
                        Strings.UpdateConcurrencyException(expectedRowsAffected, rowsAffected),
                        context,
                        AggregateEntries(commandIndex, expectedRowsAffected));
                }

                tableModification.PropagateResults(valueReader);
                rowsAffected++;
            }
            while (++commandIndex < ResultSetEnds.Count
                   && !ResultSetEnds[commandIndex - 1]);

            return commandIndex;
        }
        private async Task<IEnumerable<Scope>> ParseReader(DbDataReader reader)
        {
            var resultList = new List<Scope>();

            var hasMoreRows = reader.ReadAsync();

            while (await hasMoreRows)
            {
                int scopeOrdinal = reader.GetOrdinal("model");
                string model = reader.GetString(scopeOrdinal);

                hasMoreRows = reader.ReadAsync();

                var scope = _serializer.Deserialize<Scope>(model);

                resultList.Add(scope);
            }

            return resultList;
        }