internal FdbRangeQuery <KeyValuePair <Slice, Slice> > GetRangeCore(KeySelector begin, KeySelector end, FdbRangeOptions options, bool snapshot)
        {
            this.Database.EnsureKeyIsValid(begin.Key);
            this.Database.EnsureKeyIsValid(end.Key, endExclusive: true);

            options = FdbRangeOptions.EnsureDefaults(options, null, null, FdbStreamingMode.Iterator, false);
            options.EnsureLegalValues();

#if DEBUG
            if (Logging.On && Logging.IsVerbose)
            {
                Logging.Verbose(this, "GetRangeCore", String.Format("Getting range '{0} <= x < {1}'", begin.ToString(), end.ToString()));
            }
#endif

            return(new FdbRangeQuery <KeyValuePair <Slice, Slice> >(this, begin, end, (kv) => kv, snapshot, options));
        }
        /// <summary>
        /// Reads all key-value pairs in the database snapshot represented by transaction (potentially limited by limit, target_bytes, or mode)
        /// which have a key lexicographically greater than or equal to the key resolved by the begin key selector
        /// and lexicographically less than the key resolved by the end key selector.
        /// </summary>
        /// <param name="beginInclusive">key selector defining the beginning of the range</param>
        /// <param name="endExclusive">key selector defining the end of the range</param>
        /// <param name="options">Optionnal query options (Limit, TargetBytes, StreamingMode, Reverse, ...)</param>
        /// <param name="iteration">If streaming mode is FdbStreamingMode.Iterator, this parameter should start at 1 and be incremented by 1 for each successive call while reading this range. In all other cases it is ignored.</param>
        /// <returns></returns>
        public Task <FdbRangeChunk> GetRangeAsync(KeySelector beginInclusive, KeySelector endExclusive, FdbRangeOptions options = null, int iteration = 0)
        {
            EnsureCanRead();

            m_database.EnsureKeyIsValid(beginInclusive.Key);
            m_database.EnsureKeyIsValid(endExclusive.Key, endExclusive: true);

            options = FdbRangeOptions.EnsureDefaults(options, null, null, FdbStreamingMode.Iterator, false);
            options.EnsureLegalValues();

            // The iteration value is only needed when in iterator mode, but then it should start from 1
            if (iteration == 0)
            {
                iteration = 1;
            }

            return(m_handler.GetRangeAsync(beginInclusive, endExclusive, options, iteration, snapshot: false, cancellationToken: m_cancellation));
        }