Exemplo n.º 1
0
 private object GetNestedObjectValue(object result)
 {
     if (result != DBNull.Value)
     {
         RecordState newSource = result as RecordState;
         if (newSource != null)
         {
             if (newSource.IsNull)
             {
                 result = (object)DBNull.Value;
             }
             else
             {
                 BridgeDataRecord bridgeDataRecord = new BridgeDataRecord(this._shaper, this.Depth + 1);
                 bridgeDataRecord.SetRecordSource(newSource, true);
                 result = (object)bridgeDataRecord;
                 this._currentNestedRecord = bridgeDataRecord;
                 this._currentNestedReader = (BridgeDataReader)null;
             }
         }
         else
         {
             Coordinator <RecordState> coordinator = result as Coordinator <RecordState>;
             if (coordinator != null)
             {
                 BridgeDataReader bridgeDataReader = new BridgeDataReader(this._shaper, coordinator.TypedCoordinatorFactory, this.Depth + 1, (IEnumerator <KeyValuePair <Shaper <RecordState>, CoordinatorFactory <RecordState> > >)null);
                 result = (object)bridgeDataReader;
                 this._currentNestedRecord = (BridgeDataRecord)null;
                 this._currentNestedReader = bridgeDataReader;
             }
         }
     }
     return(result);
 }
Exemplo n.º 2
0
        /// <inheritdoc />
        public override bool NextResult()
        {
            EnsureInitialized();
            AssertReaderIsOpen("NextResult");

            // If there is a next result set available, serve it.
            if (_nextResultShaperInfoEnumerator != null &&
                _shaper.Reader.NextResult() &&
                _nextResultShaperInfoEnumerator.MoveNext())
            {
                Debug.Assert(_dataRecord.Depth == 0, "Nested data readers should not have multiple result sets.");
                var nextResultShaperInfo = _nextResultShaperInfoEnumerator.Current;
                _dataRecord.CloseImplicitly();
                SetShaper(nextResultShaperInfo.Key, nextResultShaperInfo.Value, depth: 0);
                return(true);
            }

            if (0 == _dataRecord.Depth)
            {
                // This is required to ensure that output parameter values
                // are set in SQL Server, and other providers where they come after
                // the results.
                CommandHelper.ConsumeReader(_shaper.Reader);
            }
            else
            {
                // For nested readers, make sure we're positioned properly for
                // the following columns...
                Consume();
            }

            // Ensure we close the records that may be outstanding.
            // Do this after we consume the underlying reader
            // so we don't run result assembly through it.
            CloseImplicitly();

            // Reset any state on our attached data record, since we've now
            // gone past the end of the reader.
            _dataRecord.SetRecordSource(null, false);

            return(false);
        }
 /// <summary>
 ///     For nested objects (records/readers) we have a bit more work to do; this
 ///     method extracts it all out from the main GetValue method so it doesn't
 ///     have to be so big.
 /// </summary>
 /// <param name="result"> </param>
 /// <returns> </returns>
 private object GetNestedObjectValue(object result)
 {
     if (result != DBNull.Value)
     {
         var recordState = result as RecordState;
         if (null != recordState)
         {
             if (recordState.IsNull)
             {
                 result = DBNull.Value;
             }
             else
             {
                 var nestedRecord = new BridgeDataRecord(_shaper, Depth + 1);
                 nestedRecord.SetRecordSource(recordState, true);
                 result = nestedRecord;
                 _currentNestedRecord = nestedRecord;
                 _currentNestedReader = null;
             }
         }
         else
         {
             var coordinator = result as Coordinator <RecordState>;
             if (null != coordinator)
             {
                 var nestedReader = new BridgeDataReader(
                     _shaper, coordinator.TypedCoordinatorFactory, Depth + 1, nextResultShaperInfos: null);
                 result = nestedReader;
                 _currentNestedRecord = null;
                 _currentNestedReader = nestedReader;
             }
             else
             {
                 Debug.Fail("unexpected type of nested object result: " + result.GetType());
             }
         }
     }
     return(result);
 }