internal async Task <bool> AnyOrNoneAsync(bool any)
        {
            // Optimized code path for Any/None where we can be smart and only ask for 1 from the db

            // we can use the EXACT streaming mode with Limit = 1, and it will work if TargetBytes is 0
            if ((this.TargetBytes ?? 0) != 0 || (this.Mode != FdbStreamingMode.Iterator && this.Mode != FdbStreamingMode.Exact))
            {             // fallback to the default implementation
                // ReSharper disable InvokeAsExtensionMethod
                if (any)
                {
                    return(await AsyncEnumerable.AnyAsync(this, this.Transaction.Cancellation));
                }
                else
                {
                    return(await AsyncEnumerable.NoneAsync(this, this.Transaction.Cancellation));
                }
                // ReSharper restore InvokeAsExtensionMethod
            }

            //BUGBUG: do we need special handling if OriginalRange != Range ? (weird combinations of Take/Skip and Reverse)

            var options = new FdbRangeOptions()
            {
                Limit       = 1,
                TargetBytes = 0,
                Mode        = FdbStreamingMode.Exact,
                Reverse     = this.Reversed
            };

            var tr      = this.Snapshot ? this.Transaction.Snapshot : this.Transaction;
            var results = await tr.GetRangeAsync(this.Begin, this.End, options, 0).ConfigureAwait(false);

            return(any ? !results.IsEmpty : results.IsEmpty);
        }
Пример #2
0
 public ValueTask <bool> Linq_AsyncEnumerable_Reference()
 => AsyncEnumerable.AnyAsync(asyncEnumerableReference, _ => false);
Пример #3
0
 public ValueTask <bool> Linq_AsyncEnumerable_Value()
 => AsyncEnumerable.AnyAsync(asyncEnumerableValue, _ => false);
Пример #4
0
 public async Task <bool> NoteExistsAsync(string groupName, string noteName) =>
 await AsyncEnumerable.AnyAsync(_db.Notes,
                                x => x.NoteGroup.Name.Equals(groupName) && x.Name.Equals(noteName));
Пример #5
0
 public async Task <bool> GroupNoteExistsAsync(string noteName) =>
 await AsyncEnumerable.AnyAsync(_db.NoteGroups,
                                x => x.Name.Equals(noteName, StringComparison.OrdinalIgnoreCase));
 public static Task <bool> AnyAsync <TSource>(this IAsyncEnumerable <TSource> source, Func <TSource, bool> predicate, CancellationToken cancellationToken = default)
 => AsyncEnumerable.AnyAsync(source, predicate, cancellationToken).AsTask();