Skip to content
Merged
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
3 changes: 2 additions & 1 deletion Src/Couchbase.Linq.IntegrationTests/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"couchbase": {
"connectionString": "couchbase://localhost",
"username": "Administrator",
"password": "password"
"password": "password",
"enableDnsSrvResolution": false
}
}
8 changes: 4 additions & 4 deletions Src/Couchbase.Linq.UnitTests/Couchbase.Linq.UnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.2" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="10.0.3" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="10.0.3" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="10.0.3" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="10.0.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
<PackageReference Include="Moq" Version="4.20.72" />
Expand Down
5 changes: 3 additions & 2 deletions Src/Couchbase.Linq/Couchbase.Linq.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<TargetFrameworks>netstandard2.0;net6.0;net8.0</TargetFrameworks>
<RootNamespace>Couchbase.Linq</RootNamespace>
<AssemblyName>Couchbase.Linq</AssemblyName>
<SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings>

<GenerateDocumentationFile>true</GenerateDocumentationFile>
<IncludeSymbols>true</IncludeSymbols>
Expand All @@ -33,8 +34,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CouchbaseNetClient" Version="3.6.4" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="CouchbaseNetClient" Version="3.9.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.4" />
<PackageReference Include="Remotion.Linq" Version="2.2.0" />
</ItemGroup>

Expand Down
41 changes: 40 additions & 1 deletion Src/Couchbase.Linq/Execution/ClusterQueryExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,46 @@ public IEnumerable<T> ExecuteCollection<T>(QueryModel queryModel)
/// <returns>List of objects returned by the request.</returns>
public IEnumerable<T> ExecuteCollection<T>(string statement, LinqQueryOptions queryOptions)
{
return ExecuteCollectionAsync<T>(statement, queryOptions).ToEnumerable();
// This sync-over-async pattern is not ideal, but necessary for compatibility
var asyncEnumerable = ExecuteCollectionAsync<T>(statement, queryOptions);

var enumerator = asyncEnumerable.GetAsyncEnumerator();
try
{
while (BlockingWait(enumerator.MoveNextAsync()))
{
yield return enumerator.Current;
}
}
finally
{
BlockingWait(enumerator.DisposeAsync());
}
}

private static void BlockingWait(ValueTask task)
{
if (task.IsCompleted)
{
// Avoid allocating a Task unnecessarily if the ValueTask is already completed
task.GetAwaiter().GetResult();
return;
}

// ValueTask must be converted to Task to safely await the result if it is not completed
task.AsTask().GetAwaiter().GetResult();
}

private static T BlockingWait<T>(ValueTask<T> task)
{
if (task.IsCompleted)
{
// Avoid allocating a Task unnecessarily if the ValueTask is already completed
return task.GetAwaiter().GetResult();
}

// ValueTask must be converted to Task to safely await the result if it is not completed
return task.AsTask().GetAwaiter().GetResult();
}

public IAsyncEnumerable<T> ExecuteCollectionAsync<T>(QueryModel queryModel, CancellationToken cancellationToken = default)
Expand Down
Loading