From 75223a315dc81c6d81256aae9a05ac6a265358a8 Mon Sep 17 00:00:00 2001 From: Valentin Kononov Date: Sat, 19 May 2018 09:54:21 +0300 Subject: [PATCH] feat(QueryFutureEnumerable) : add FirstOrDefaultAsync implementation --- .../QueryFutureEnumerable.cs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/shared/Z.EF.Plus.QueryFuture.Shared/QueryFutureEnumerable.cs b/src/shared/Z.EF.Plus.QueryFuture.Shared/QueryFutureEnumerable.cs index e1cba051..497c73b3 100644 --- a/src/shared/Z.EF.Plus.QueryFuture.Shared/QueryFutureEnumerable.cs +++ b/src/shared/Z.EF.Plus.QueryFuture.Shared/QueryFutureEnumerable.cs @@ -121,6 +121,25 @@ public async Task ToArrayAsync() return list.ToArray(); } } + + public async Task FirstOrDefaultAsync() + { + if (!HasValue) + { + await OwnerBatch.ExecuteQueriesAsync().ConfigureAwait(false); + } + + if (_result == null) + { + return default(T); + } + + using (var enumerator = _result.GetEnumerator()) + { + enumerator.MoveNext(); + return enumerator.Current; + } + } #endif /// Sets the result of the query deferred.