Ejemplo n.º 1
0
        internal async Task InitializeAsync(
            string providerManifestToken, DbProviderServices providerSerivces, Type[] columnTypes, bool[] nullableColumns,
            CancellationToken cancellationToken)
        {
            if (_underlyingReader == null)
            {
                return;
            }

            cancellationToken.ThrowIfCancellationRequested();

            var reader = _underlyingReader;

            _underlyingReader = null;

            try
            {
                if (columnTypes != null && reader.GetType().Name != "SqlDataReader")
                {
                    _bufferedDataRecords.Add(await
                                             ShapedBufferedDataRecord.InitializeAsync(
                                                 providerManifestToken, providerSerivces, reader, columnTypes, nullableColumns, cancellationToken)
                                             .WithCurrentCulture());
                }
                else
                {
                    _bufferedDataRecords.Add(await
                                             ShapelessBufferedDataRecord.InitializeAsync(providerManifestToken, providerSerivces, reader, cancellationToken)
                                             .WithCurrentCulture());
                }

                while (await reader.NextResultAsync(cancellationToken).WithCurrentCulture())
                {
                    _bufferedDataRecords.Add(await
                                             ShapelessBufferedDataRecord.InitializeAsync(providerManifestToken, providerSerivces, reader, cancellationToken)
                                             .WithCurrentCulture());
                }

                _recordsAffected  = reader.RecordsAffected;
                _currentResultSet = _bufferedDataRecords[_currentResultSetNumber];
            }
            finally
            {
                reader.Dispose();
            }
        }
        internal void Initialize(
            string providerManifestToken, DbProviderServices providerServices, Type[] columnTypes, bool[] nullableColumns)
        {
            var reader = _underlyingReader;

            if (reader == null)
            {
                return;
            }
            _underlyingReader = null;

            try
            {
                if (columnTypes != null && reader.GetType().Name != "SqlDataReader")
                {
                    _bufferedDataRecords.Add(
                        ShapedBufferedDataRecord.Initialize(providerManifestToken, providerServices, reader, columnTypes, nullableColumns));
                }
                else
                {
                    _bufferedDataRecords.Add(ShapelessBufferedDataRecord.Initialize(providerManifestToken, providerServices, reader));
                }

                while (reader.NextResult())
                {
                    _bufferedDataRecords.Add(ShapelessBufferedDataRecord.Initialize(providerManifestToken, providerServices, reader));
                }

                _recordsAffected  = reader.RecordsAffected;
                _currentResultSet = _bufferedDataRecords[_currentResultSetNumber];
            }
            finally
            {
                reader.Dispose();
            }
        }
        internal void Initialize(string providerManifestToken, DbProviderServices providerSerivces)
        {
            var reader = _underlyingReader;

            if (reader == null)
            {
                return;
            }
            _underlyingReader = null;

            try
            {
                do
                {
                    var metadata = ReadMetadata(providerManifestToken, providerSerivces, reader);

                    var resultSet = new List <object[]>();
                    if (metadata.HasSpatialColumns)
                    {
                        while (reader.Read())
                        {
                            var row = new object[metadata.FieldCount];
                            for (var i = 0; i < metadata.FieldCount; i++)
                            {
                                if (reader.IsDBNull(i))
                                {
                                    row[i] = DBNull.Value;
                                }
                                else if (metadata.GeographyColumns[i])
                                {
                                    row[i] = metadata.SpatialDataReader.GetGeography(i);
                                }
                                else if (metadata.GeometryColumns[i])
                                {
                                    row[i] = metadata.SpatialDataReader.GetGeometry(i);
                                }
                                else
                                {
                                    row[i] = reader.GetValue(i);
                                }
                            }
                            resultSet.Add(row);
                        }
                    }
                    else
                    {
                        while (reader.Read())
                        {
                            var row = new object[metadata.FieldCount];
                            reader.GetValues(row);
                            resultSet.Add(row);
                        }
                    }

                    _bufferedDataRecords.Add(
                        new BufferedDataRecord(resultSet, metadata.DataTypeNames, metadata.ColumnTypes, metadata.ColumnNames));
                }while (reader.NextResult());

                _recordsAffected  = reader.RecordsAffected;
                _currentResultSet = _bufferedDataRecords[_currentResultSetNumber];
            }
            finally
            {
                reader.Dispose();
            }
        }