public async Task GqlQueryAsync() { string projectId = _fixture.ProjectId; string namespaceId = _fixture.NamespaceId; // Snippet: RunQueryAsync(GqlQuery,*,*) DatastoreDb db = DatastoreDb.Create(projectId, namespaceId); GqlQuery gqlQuery = new GqlQuery { QueryString = "SELECT * FROM book WHERE author = @author", NamedBindings = { { "author", new GqlQueryParameter { Value = "Jane Austen" } } }, }; DatastoreAsyncQueryResults results = db.RunQueryAsync(gqlQuery); // DatastoreAsyncQueryResults implements IAsyncEnumerable<Entity>, but you can // call AsEntityResults(), AsBatches() or AsResponses() to see the query // results in whatever way makes most sense for your application. await results.ForEachAsync(entity => { Console.WriteLine(entity); }); // End snippet // This will run the query again, admittedly... List <Entity> entities = await results.ToList(); Assert.Equal(1, entities.Count); Entity book = entities[0]; Assert.Equal("Jane Austen", (string)book["author"]); Assert.Equal("Pride and Prejudice", (string)book["title"]); }
public async Task StructuredQueryAsync() { string projectId = _fixture.ProjectId; string namespaceId = _fixture.NamespaceId; // Snippet: RunQueryAsync(Query,*,*) DatastoreDb db = DatastoreDb.Create(projectId, namespaceId); Query query = new Query("book") { Filter = Filter.Equal("author", "Jane Austen") }; DatastoreAsyncQueryResults results = db.RunQueryAsync(query); // DatastoreAsyncQueryResults implements IAsyncEnumerable<Entity>, but you can // call AsEntityResults(), AsBatches() or AsResponses() to see the query // results in whatever way makes most sense for your application. await results.ForEachAsync(entity => { Console.WriteLine(entity); }); // End snippet // This will run the query again, admittedly... List <Entity> entities = await results.ToList(); Assert.Equal(1, entities.Count); Entity book = entities[0]; Assert.Equal("Jane Austen", (string)book["author"]); Assert.Equal("Pride and Prejudice", (string)book["title"]); }