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.
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).
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.
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.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-07 UTC."],[[["\u003cp\u003eThis document provides reference information for the \u003ccode\u003eAsyncLazyDatastoreQuery\u003c/code\u003e class within the Google Cloud Datastore V1 API for .NET.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eAsyncLazyDatastoreQuery\u003c/code\u003e class allows for lazy execution of Datastore queries, meaning that the query is executed each time the results are iterated over.\u003c/p\u003e\n"],["\u003cp\u003eUsers can retrieve query results as a sequence of \u003ccode\u003eEntity\u003c/code\u003e values through asynchronous iteration, or fetch all results at once via the \u003ccode\u003eGetAllResultsAsync()\u003c/code\u003e method.\u003c/p\u003e\n"],["\u003cp\u003eFor advanced use cases, the \u003ccode\u003eAsResponses()\u003c/code\u003e method allows retrieving results directly as a sequence of \u003ccode\u003eRunQueryResponse\u003c/code\u003e values from the Datastore API.\u003c/p\u003e\n"],["\u003cp\u003eThe document provides access to various versions of this class, from \u003ccode\u003e3.2.0\u003c/code\u003e to the latest \u003ccode\u003e4.15.0\u003c/code\u003e, including links for each version.\u003c/p\u003e\n"]]],[],null,["# Google Cloud Datastore v1 API - Class AsyncLazyDatastoreQuery (4.15.0)\n\nVersion latestkeyboard_arrow_down\n\n- [4.15.0 (latest)](/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.AsyncLazyDatastoreQuery)\n- [4.14.0](/dotnet/docs/reference/Google.Cloud.Datastore.V1/4.14.0/Google.Cloud.Datastore.V1.AsyncLazyDatastoreQuery)\n- [4.13.0](/dotnet/docs/reference/Google.Cloud.Datastore.V1/4.13.0/Google.Cloud.Datastore.V1.AsyncLazyDatastoreQuery)\n- [4.12.0](/dotnet/docs/reference/Google.Cloud.Datastore.V1/4.12.0/Google.Cloud.Datastore.V1.AsyncLazyDatastoreQuery)\n- [4.11.0](/dotnet/docs/reference/Google.Cloud.Datastore.V1/4.11.0/Google.Cloud.Datastore.V1.AsyncLazyDatastoreQuery)\n- [4.10.0](/dotnet/docs/reference/Google.Cloud.Datastore.V1/4.10.0/Google.Cloud.Datastore.V1.AsyncLazyDatastoreQuery)\n- [4.9.0](/dotnet/docs/reference/Google.Cloud.Datastore.V1/4.9.0/Google.Cloud.Datastore.V1.AsyncLazyDatastoreQuery)\n- [4.8.0](/dotnet/docs/reference/Google.Cloud.Datastore.V1/4.8.0/Google.Cloud.Datastore.V1.AsyncLazyDatastoreQuery)\n- [4.7.0](/dotnet/docs/reference/Google.Cloud.Datastore.V1/4.7.0/Google.Cloud.Datastore.V1.AsyncLazyDatastoreQuery)\n- [4.6.0](/dotnet/docs/reference/Google.Cloud.Datastore.V1/4.6.0/Google.Cloud.Datastore.V1.AsyncLazyDatastoreQuery)\n- [4.5.0](/dotnet/docs/reference/Google.Cloud.Datastore.V1/4.5.0/Google.Cloud.Datastore.V1.AsyncLazyDatastoreQuery)\n- [4.4.0](/dotnet/docs/reference/Google.Cloud.Datastore.V1/4.4.0/Google.Cloud.Datastore.V1.AsyncLazyDatastoreQuery)\n- [4.3.0](/dotnet/docs/reference/Google.Cloud.Datastore.V1/4.3.0/Google.Cloud.Datastore.V1.AsyncLazyDatastoreQuery)\n- [4.2.0](/dotnet/docs/reference/Google.Cloud.Datastore.V1/4.2.0/Google.Cloud.Datastore.V1.AsyncLazyDatastoreQuery)\n- [4.1.0](/dotnet/docs/reference/Google.Cloud.Datastore.V1/4.1.0/Google.Cloud.Datastore.V1.AsyncLazyDatastoreQuery)\n- [4.0.0](/dotnet/docs/reference/Google.Cloud.Datastore.V1/4.0.0/Google.Cloud.Datastore.V1.AsyncLazyDatastoreQuery)\n- [3.5.0](/dotnet/docs/reference/Google.Cloud.Datastore.V1/3.5.0/Google.Cloud.Datastore.V1.AsyncLazyDatastoreQuery)\n- [3.4.0](/dotnet/docs/reference/Google.Cloud.Datastore.V1/3.4.0/Google.Cloud.Datastore.V1.AsyncLazyDatastoreQuery)\n- [3.3.0](/dotnet/docs/reference/Google.Cloud.Datastore.V1/3.3.0/Google.Cloud.Datastore.V1.AsyncLazyDatastoreQuery)\n- [3.2.0](/dotnet/docs/reference/Google.Cloud.Datastore.V1/3.2.0/Google.Cloud.Datastore.V1.AsyncLazyDatastoreQuery) \n\n public sealed class AsyncLazyDatastoreQuery : IAsyncEnumerable\u003cEntity\u003e\n\nReference documentation and code samples for the Google Cloud Datastore v1 API class AsyncLazyDatastoreQuery.\n\nA Datastore query which is executed lazily. Iterating over this object will provide a sequence\nof entities; alternatively, all the results can be fetched using [GetAllResultsAsync()](/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.AsyncLazyDatastoreQuery#Google_Cloud_Datastore_V1_AsyncLazyDatastoreQuery_GetAllResultsAsync),\nor for diagnostic use cases the RPC responses can be viewed using [AsResponses()](/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.AsyncLazyDatastoreQuery#Google_Cloud_Datastore_V1_AsyncLazyDatastoreQuery_AsResponses).\nThe lazy evaluation is important: if you iterate over the query multiple times, it will execute\nmultiple times, potentially returning different results each time. \n\nInheritance\n-----------\n\n[object](https://learn.microsoft.com/dotnet/api/system.object) \\\u003e AsyncLazyDatastoreQuery \n\nImplements\n----------\n\n[IAsyncEnumerable](https://learn.microsoft.com/dotnet/api/system.collections.generic.iasyncenumerable-1)[Entity](/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.Entity) \n\nInherited Members\n-----------------\n\n[object.GetHashCode()](https://learn.microsoft.com/dotnet/api/system.object.gethashcode) \n[object.GetType()](https://learn.microsoft.com/dotnet/api/system.object.gettype) \n[object.ToString()](https://learn.microsoft.com/dotnet/api/system.object.tostring)\n\nNamespace\n---------\n\n[Google.Cloud.Datastore.V1](/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1)\n\nAssembly\n--------\n\nGoogle.Cloud.Datastore.V1.dll\n\nConstructors\n------------\n\n### AsyncLazyDatastoreQuery(IAsyncEnumerable\\\u003cRunQueryResponse\\\u003e)\n\n public AsyncLazyDatastoreQuery(IAsyncEnumerable\u003cRunQueryResponse\u003e responses)\n\nConstructs a new instance from the given sequence of responses. This constructor\nis only present to facilitate testing; application code will normally obtain instances\nof this class by calling [RunQueryLazilyAsync(Query, ReadConsistency?, CallSettings)](/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.DatastoreDb#Google_Cloud_Datastore_V1_DatastoreDb_RunQueryLazilyAsync_Google_Cloud_Datastore_V1_Query_System_Nullable_Google_Cloud_Datastore_V1_ReadOptions_Types_ReadConsistency__Google_Api_Gax_Grpc_CallSettings_).\n\n**Remarks** \nThe sequence of responses will be returned directly from [AsResponses()](/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.AsyncLazyDatastoreQuery#Google_Cloud_Datastore_V1_AsyncLazyDatastoreQuery_AsResponses), and\nused to lazily construct the other sequences returned by this class. It should not\ncontain any null references.\n\nMethods\n-------\n\n### AsResponses()\n\n public IAsyncEnumerable\u003cRunQueryResponse\u003e AsResponses()\n\nThis method is for advanced use cases only, where more diagnostic information is required;\nmost application code should merely iterate over the query results as [Entity](/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.Entity)\nvalues, or call [GetAllResultsAsync()](/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.AsyncLazyDatastoreQuery#Google_Cloud_Datastore_V1_AsyncLazyDatastoreQuery_GetAllResultsAsync).\nThe results of this query are returned as a sequence of [RunQueryResponse](/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.RunQueryResponse) values\nexactly as returned by the Datastore API.\n\n### GetAllResultsAsync()\n\n public Task\u003cDatastoreQueryResults\u003e GetAllResultsAsync()\n\nReads all the results from this query, until either the query-specified limit or end cursor\nis reached, or there is no more data to read. Note that all the entities are read into memory,\nso this method is not appropriate for use cases where a query could return a very large number\nof results. However, it is the simplest approach to use cases where the query is bounded, such\nas displaying a page of results at a time in a web application.\n\n### GetAsyncEnumerator(CancellationToken)\n\n public IAsyncEnumerator\u003cEntity\u003e GetAsyncEnumerator(CancellationToken cancellationToken)\n\nReturns an enumerator that iterates asynchronously through the collection."]]