Class AsyncLazyDatastoreQuery (4.1.0)

public sealed class AsyncLazyDatastoreQuery : IAsyncEnumerable<Entity>

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

Implements

IAsyncEnumerable<Entity>

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, Nullable<ReadOptions.Types.ReadConsistency>, CallSettings).

Parameter
NameDescription
responsesIAsyncEnumerable<RunQueryResponse>

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
TypeDescription
IAsyncEnumerable<RunQueryResponse>

A sequence of RunQueryResponse values.

GetAllResultsAsync()

public async 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
TypeDescription
Task<DatastoreQueryResults>

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)
Parameter
NameDescription
cancellationTokenCancellationToken
Returns
TypeDescription
IAsyncEnumerator<Entity>