Skip to content

Fix ambiguity of IEnumerable/IAsyncEnumerable for DelayedQuery #172

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Orm/Xtensive.Orm.Manual/Prefetch/PrefetchTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,17 @@ public async Task DelayedQueryAsyncTest()
}
}

[Test]
public async Task DelayedQueryAmbiguityTest()
{
await using (var session = await Domain.OpenSessionAsync())// no session activation!
using (var transactionScope = session.OpenTransaction()) {
var people = session.Query.CreateDelayedQuery(q => q.All<Person>());
_ = people.Select(o => o).Count();
transactionScope.Complete();
}
}

private class QueryCounterSessionHandlerMoq : ChainingSessionHandler
{
private volatile int syncCounter;
Expand Down
1 change: 1 addition & 0 deletions Orm/Xtensive.Orm.Manual/Xtensive.Orm.Manual.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
<PackageReference Include="NUnit" Version="3.13.2" />
<PackageReference Include="NUnit3TestAdapter" Version="4.2.0" />
<PackageReference Include="System.Linq.Async" Version="6.0.1" />
</ItemGroup>
<ItemGroup>
<Content Include="EntitySets\DatabaseSchema.gif" />
Expand Down
12 changes: 5 additions & 7 deletions Orm/Xtensive.Orm/Orm/DelayedQuery{T}.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
using Xtensive.Core;
Expand All @@ -20,19 +21,17 @@ namespace Xtensive.Orm
/// </summary>
/// <typeparam name="TElement">The type of the element in a resulting sequence.</typeparam>
[Serializable]
public sealed class DelayedQuery<TElement> : DelayedQuery, IEnumerable<TElement>, IAsyncEnumerable<TElement>
public sealed class DelayedQuery<TElement> : DelayedQuery, IEnumerable<TElement>
{
/// <inheritdoc/>
public IEnumerator<TElement> GetEnumerator() => Materialize<TElement>().GetEnumerator();

/// <inheritdoc/>
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();

/// <inheritdoc/>
async IAsyncEnumerator<TElement> IAsyncEnumerable<TElement>.GetAsyncEnumerator(CancellationToken token)
public async IAsyncEnumerable<TElement> AsAsyncEnumerable([EnumeratorCancellation]CancellationToken token)
{
var elements = await ExecuteAsync(token).ConfigureAwaitFalse();
foreach (var element in elements) {
foreach (var element in await ExecuteAsync(token).ConfigureAwaitFalse()) {
yield return element;
}
}
Expand All @@ -53,6 +52,5 @@ public ValueTask<QueryResult<TElement>> ExecuteAsync(CancellationToken token = d
internal DelayedQuery(Session session, TranslatedQuery translatedQuery, ParameterContext parameterContext)
: base(session, translatedQuery, parameterContext)
{ }

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ await sessionHandler.ExecutePrefetchTasksAsync(token).ConfigureAwaitFalse())) {
currentTaskCount = sessionHandler.PrefetchTaskExecutionCount;
}

if (source is IAsyncEnumerable<TItem> asyncItemSource) {
var asyncItemSource = (source as DelayedQuery<TItem>)?.AsAsyncEnumerable(token)
?? source as IAsyncEnumerable<TItem>;
if (asyncItemSource is not null) {
await foreach (var item in asyncItemSource.WithCancellation(token).ConfigureAwaitFalse()) {
await foreach (var p in ProcessItem(item).WithCancellation(token).ConfigureAwaitFalse()) {
yield return p;
Expand Down
2 changes: 1 addition & 1 deletion Version.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<PropertyGroup>
<DoVersion>7.2.0.112</DoVersion>
<DoVersion>7.2.0.113</DoVersion>
<DoVersionSuffix>servicetitan</DoVersionSuffix>
</PropertyGroup>

Expand Down