public sealed class LazyDatastoreQuery : IEnumerable<Entity>, IEnumerable
Reference documentation and code samples for the Google Cloud Datastore v1 API class LazyDatastoreQuery.
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 GetAllResults(),
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 LazyDatastoreQuery(IEnumerable<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 RunQueryLazily(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 IEnumerable<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 GetAllResults().
The results of this query are returned as a sequence of RunQueryResponse values
exactly as returned by the Datastore API.
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"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-07 UTC."],[[["\u003cp\u003eThe latest version of the \u003ccode\u003eLazyDatastoreQuery\u003c/code\u003e class is 4.15.0, and the documentation lists versions back to 3.2.0 for reference.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eLazyDatastoreQuery\u003c/code\u003e is a class for executing Datastore queries lazily, allowing iteration over entities or fetching all results at once using \u003ccode\u003eGetAllResults()\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eMultiple iterations over a \u003ccode\u003eLazyDatastoreQuery\u003c/code\u003e can result in different data sets as it reruns each time.\u003c/p\u003e\n"],["\u003cp\u003eThe class has a constructor \u003ccode\u003eLazyDatastoreQuery(IEnumerable<RunQueryResponse>)\u003c/code\u003e to build a new instance from a sequence of responses for testing purposes, and it can also be used for more diagnostic information with the method \u003ccode\u003eAsResponses()\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eGetAllResults()\u003c/code\u003e retrieves all results into memory, making it suitable for bounded queries but not for very large datasets.\u003c/p\u003e\n"]]],[],null,["# Google Cloud Datastore v1 API - Class LazyDatastoreQuery (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.LazyDatastoreQuery)\n- [4.14.0](/dotnet/docs/reference/Google.Cloud.Datastore.V1/4.14.0/Google.Cloud.Datastore.V1.LazyDatastoreQuery)\n- [4.13.0](/dotnet/docs/reference/Google.Cloud.Datastore.V1/4.13.0/Google.Cloud.Datastore.V1.LazyDatastoreQuery)\n- [4.12.0](/dotnet/docs/reference/Google.Cloud.Datastore.V1/4.12.0/Google.Cloud.Datastore.V1.LazyDatastoreQuery)\n- [4.11.0](/dotnet/docs/reference/Google.Cloud.Datastore.V1/4.11.0/Google.Cloud.Datastore.V1.LazyDatastoreQuery)\n- [4.10.0](/dotnet/docs/reference/Google.Cloud.Datastore.V1/4.10.0/Google.Cloud.Datastore.V1.LazyDatastoreQuery)\n- [4.9.0](/dotnet/docs/reference/Google.Cloud.Datastore.V1/4.9.0/Google.Cloud.Datastore.V1.LazyDatastoreQuery)\n- [4.8.0](/dotnet/docs/reference/Google.Cloud.Datastore.V1/4.8.0/Google.Cloud.Datastore.V1.LazyDatastoreQuery)\n- [4.7.0](/dotnet/docs/reference/Google.Cloud.Datastore.V1/4.7.0/Google.Cloud.Datastore.V1.LazyDatastoreQuery)\n- [4.6.0](/dotnet/docs/reference/Google.Cloud.Datastore.V1/4.6.0/Google.Cloud.Datastore.V1.LazyDatastoreQuery)\n- [4.5.0](/dotnet/docs/reference/Google.Cloud.Datastore.V1/4.5.0/Google.Cloud.Datastore.V1.LazyDatastoreQuery)\n- [4.4.0](/dotnet/docs/reference/Google.Cloud.Datastore.V1/4.4.0/Google.Cloud.Datastore.V1.LazyDatastoreQuery)\n- [4.3.0](/dotnet/docs/reference/Google.Cloud.Datastore.V1/4.3.0/Google.Cloud.Datastore.V1.LazyDatastoreQuery)\n- [4.2.0](/dotnet/docs/reference/Google.Cloud.Datastore.V1/4.2.0/Google.Cloud.Datastore.V1.LazyDatastoreQuery)\n- [4.1.0](/dotnet/docs/reference/Google.Cloud.Datastore.V1/4.1.0/Google.Cloud.Datastore.V1.LazyDatastoreQuery)\n- [4.0.0](/dotnet/docs/reference/Google.Cloud.Datastore.V1/4.0.0/Google.Cloud.Datastore.V1.LazyDatastoreQuery)\n- [3.5.0](/dotnet/docs/reference/Google.Cloud.Datastore.V1/3.5.0/Google.Cloud.Datastore.V1.LazyDatastoreQuery)\n- [3.4.0](/dotnet/docs/reference/Google.Cloud.Datastore.V1/3.4.0/Google.Cloud.Datastore.V1.LazyDatastoreQuery)\n- [3.3.0](/dotnet/docs/reference/Google.Cloud.Datastore.V1/3.3.0/Google.Cloud.Datastore.V1.LazyDatastoreQuery)\n- [3.2.0](/dotnet/docs/reference/Google.Cloud.Datastore.V1/3.2.0/Google.Cloud.Datastore.V1.LazyDatastoreQuery) \n\n public sealed class LazyDatastoreQuery : IEnumerable\u003cEntity\u003e, IEnumerable\n\nReference documentation and code samples for the Google Cloud Datastore v1 API class LazyDatastoreQuery.\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 [GetAllResults()](/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.LazyDatastoreQuery#Google_Cloud_Datastore_V1_LazyDatastoreQuery_GetAllResults),\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.LazyDatastoreQuery#Google_Cloud_Datastore_V1_LazyDatastoreQuery_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 LazyDatastoreQuery \n\nImplements\n----------\n\n[IEnumerable](https://learn.microsoft.com/dotnet/api/system.collections.generic.ienumerable-1)[Entity](/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.Entity), [IEnumerable](https://learn.microsoft.com/dotnet/api/system.collections.ienumerable) \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### LazyDatastoreQuery(IEnumerable\\\u003cRunQueryResponse\\\u003e)\n\n public LazyDatastoreQuery(IEnumerable\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 [RunQueryLazily(Query, ReadConsistency?, CallSettings)](/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.DatastoreDb#Google_Cloud_Datastore_V1_DatastoreDb_RunQueryLazily_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.LazyDatastoreQuery#Google_Cloud_Datastore_V1_LazyDatastoreQuery_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 IEnumerable\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 [GetAllResults()](/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest/Google.Cloud.Datastore.V1.LazyDatastoreQuery#Google_Cloud_Datastore_V1_LazyDatastoreQuery_GetAllResults).\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### GetAllResults()\n\n public DatastoreQueryResults GetAllResults()\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### GetEnumerator()\n\n public IEnumerator\u003cEntity\u003e GetEnumerator()"]]