/// <summary> /// Advances the reader to the next result when reading the results of a batch of statements. /// </summary> /// <returns> /// true if there are more result sets; otherwise false. /// </returns> public override bool NextResult() { if (this.wrappedReader.NextResult()) { this.queryResults = null; return(true); } return(false); }
/// <summary> /// Initializes a new instance of the EFCachingDataReaderCacheWriter class. /// </summary> /// <param name="wrappedReader">The wrapped reader.</param> /// <param name="addToCache">The delegate used to add the result to the cache when the reader finishes.</param> /// <param name="behavior">An instance of System.Data.CommandBehavior.</param> public EFCachingDataReaderCacheWriter(DbDataReader wrappedReader, Action <DbQueryResults> addToCache, CommandBehavior behavior) { this.wrappedReader = wrappedReader; this.addToCache = addToCache; base.behavior = behavior; this.queryResult = new DbQueryResults(this.wrappedReader) { FieldCount = this.wrappedReader.FieldCount, VisibleFieldCount = this.wrappedReader.VisibleFieldCount }; }
/// <summary> /// Advances the reader to the next record in a result set. /// </summary> /// <returns> /// true if there are more rows; otherwise false. /// </returns> public override bool Read() { if (this.wrappedReader.Read()) { var values = new object[this.wrappedReader.FieldCount]; this.wrappedReader.GetValues(values); SetValues(values); if (this.queryResults != null) { this.queryResults.Rows.Add(values); if (this.queryResults.Rows.Count > this.maxRows) { this.queryResults = null; } } return(true); } return(false); }
/// <summary> /// Closes the <see cref="T:System.Data.Common.DbDataReader"/> object. /// </summary> public override void Close() { if (this.queryResult != null && this.queryResult.RowsCount > 0) { ///Reader not yet closed if (!this.wrappedReader.IsClosed) { ///Complete result has been fetched from database. if (!this.wrappedReader.Read()) { this.addToCache(this.queryResult); this.queryResult.Dispose(); this.queryResult = null; } else ///There was still some data to be read when the reader is closed ///We shall not cache incomplete result { this.queryResult.Dispose(); this.queryResult = null; } } } this.wrappedReader.Close(); }
/// <summary> /// Initializes a new instance of the CachingDataReaderCacheReader class. /// </summary> /// <param name="item">The cached item.</param> /// <param name="behavior">An instance of System.Data.CommandBehavior.</param> public CachingDataReaderCacheReader(DbQueryResults queryResults, CommandBehavior behavior) { this.queryResults = queryResults; base.behavior = behavior; }
/// <summary> /// Initializes a new instance of the CachingDataReaderCacheReader class. /// </summary> /// <param name="queryResults">The query results.</param> public CachingDataReaderCacheReader(DbQueryResults queryResults) { this.queryResults = queryResults; }