Google Cloud Datastore v1 API - Class AsyncLazyDatastoreQuery (4.11.0)

public sealed class AsyncLazyDatastoreQuery : IAsyncEnumerable<Entity>

Reference documentation and code samples for the Google Cloud Datastore v1 API class AsyncLazyDatastoreQuery.

A Datastore query which is executed lazily. Iterating over this object will provide a sequence of entities; alternatively, all the results can be fetched using GetAllResultsAsync(), or for diagnostic use cases the RPC responses can be viewed using AsResponses(). The lazy evaluation is important: if you iterate over the query multiple times, it will execute multiple times, potentially returning different results each time.

Inheritance

object > AsyncLazyDatastoreQuery

Namespace

Google.Cloud.Datastore.V1

Assembly

Google.Cloud.Datastore.V1.dll

Constructors

AsyncLazyDatastoreQuery(IAsyncEnumerable<RunQueryResponse>)

public AsyncLazyDatastoreQuery(IAsyncEnumerable<RunQueryResponse> responses)

Constructs a new instance from the given sequence of responses. This constructor is only present to facilitate testing; application code will normally obtain instances of this class by calling RunQueryLazilyAsync(Query, ReadConsistency?, CallSettings).

Parameter
Name Description
responses IAsyncEnumerableRunQueryResponse

The responses to return.

Remarks

The sequence of responses will be returned directly from AsResponses(), and used to lazily construct the other sequences returned by this class. It should not contain any null references.

Methods

AsResponses()

public IAsyncEnumerable<RunQueryResponse> AsResponses()

This method is for advanced use cases only, where more diagnostic information is required; most application code should merely iterate over the query results as Entity values, or call GetAllResultsAsync(). The results of this query are returned as a sequence of RunQueryResponse values exactly as returned by the Datastore API.

Returns
Type Description
IAsyncEnumerableRunQueryResponse

A sequence of RunQueryResponse values.

GetAllResultsAsync()

public Task<DatastoreQueryResults> GetAllResultsAsync()

Reads all the results from this query, until either the query-specified limit or end cursor is reached, or there is no more data to read. Note that all the entities are read into memory, so this method is not appropriate for use cases where a query could return a very large number of results. However, it is the simplest approach to use cases where the query is bounded, such as displaying a page of results at a time in a web application.

Returns
Type Description
TaskDatastoreQueryResults

A task representing the asynchronous operation. When completed, the result of the task is the complete set of query results.

GetAsyncEnumerator(CancellationToken)

public IAsyncEnumerator<Entity> GetAsyncEnumerator(CancellationToken cancellationToken)

Returns an enumerator that iterates asynchronously through the collection.

Parameter
Name Description
cancellationToken CancellationToken

A CancellationToken that may be used to cancel the asynchronous iteration.

Returns
Type Description
IAsyncEnumeratorEntity

An enumerator that can be used to iterate asynchronously through the collection.