Skip to content
This repository was archived by the owner on Feb 1, 2025. It is now read-only.

Commit ac9902c

Browse files
Fix #237 by using async IAsyncEnumerable<T> (#241)
This likely means, that exceptions are thrown later (i.e. when starting to actually enumerate)
1 parent 365af8a commit ac9902c

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

Source/LinqToDB.EntityFrameworkCore/Internal/LinqToDBForEFQueryProvider.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Linq;
55
using System.Linq.Expressions;
66
using System.Reflection;
7+
using System.Runtime.CompilerServices;
78
using System.Threading;
89
using System.Threading.Tasks;
910

@@ -158,8 +159,17 @@ IEnumerator IEnumerable.GetEnumerator()
158159
/// <returns>Query result as <see cref="IAsyncEnumerable{T}"/>.</returns>
159160
public IAsyncEnumerator<T> GetAsyncEnumerator(CancellationToken cancellationToken)
160161
{
161-
return Task.Run(() => QueryProvider.ExecuteAsyncEnumerable<T>(Expression, cancellationToken),
162-
cancellationToken).Result.GetAsyncEnumerator(cancellationToken);
162+
async IAsyncEnumerable<T> EnumerateAsyncEnumerable([EnumeratorCancellation] CancellationToken ct)
163+
{
164+
var asyncEnumerable = await QueryProvider.ExecuteAsyncEnumerable<T>(Expression, ct)
165+
.ConfigureAwait(false);
166+
await foreach (var item in asyncEnumerable.WithCancellation(ct))
167+
{
168+
yield return item;
169+
}
170+
}
171+
172+
return EnumerateAsyncEnumerable(cancellationToken).GetAsyncEnumerator(cancellationToken);
163173
}
164174

165175
/// <summary>

0 commit comments

Comments
 (0)