Container.GetItemQueryIterator Method

Definition

Overloads

GetItemQueryIterator<T>(QueryDefinition, String, QueryRequestOptions)

This method creates a query for items under a container in an Azure Cosmos database using a SQL statement with parameterized values. It returns a FeedIterator. For more information on preparing SQL statements with parameterized values, please see QueryDefinition.

GetItemQueryIterator<T>(String, String, QueryRequestOptions)

This method creates a query for items under a container in an Azure Cosmos database using a SQL statement with parameterized values. It returns a FeedIterator. For more information on preparing SQL statements with parameterized values, please see QueryDefinition.

GetItemQueryIterator<T>(QueryDefinition, String, QueryRequestOptions)

This method creates a query for items under a container in an Azure Cosmos database using a SQL statement with parameterized values. It returns a FeedIterator. For more information on preparing SQL statements with parameterized values, please see QueryDefinition.

public abstract Microsoft.Azure.Cosmos.FeedIterator<T> GetItemQueryIterator<T> (Microsoft.Azure.Cosmos.QueryDefinition queryDefinition, string continuationToken = null, Microsoft.Azure.Cosmos.QueryRequestOptions requestOptions = null);
abstract member GetItemQueryIterator : Microsoft.Azure.Cosmos.QueryDefinition * string * Microsoft.Azure.Cosmos.QueryRequestOptions -> Microsoft.Azure.Cosmos.FeedIterator<'T>

Type Parameters

T

Parameters

queryDefinition
QueryDefinition

The cosmos SQL query definition.

continuationToken
String

(Optional) The continuation token in the Azure Cosmos DB service.

requestOptions
QueryRequestOptions

(Optional) The options for the item query request QueryRequestOptions

Returns

An iterator to go through the items.

Examples

Create a query to get all the ToDoActivity that have a cost greater than 9000


public class ToDoActivity{
    public string id {get; set;}
    public string status {get; set;}
    public int cost {get; set;}
}

QueryDefinition sqlQuery = new QueryDefinition("select * from ToDos t where t.cost > @expensive").WithParameter("@expensive", 9000);
FeedIterator<ToDoActivity> feedIterator = this.Container.GetItemQueryIterator<ToDoActivity>(
    sqlQueryDefinition: sqlQuery, 
    requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey("Error")});
    
while (feedIterator.HasMoreResults)
{
    foreach(var item in await feedIterator.ReadNextAsync()){
    {
        Console.WriteLine(item.cost); 
    }
}

Create a query to get all the ToDoActivity that have a cost greater than 9000


 public class ToDoActivity{
     public string id {get; set;}
     public string status {get; set;}
     public int cost {get; set;}
 }
 
 QueryDefinition queryDefinition = new QueryDefinition("select * from ToDos t where t.cost > @expensive")
     .WithParameter("@expensive", 9000);
 FeedIterator<ToDoActivity> feedIterator = this.Container.GetItemQueryIterator<ToDoActivity>(
     queryDefinition,
     null,
     new QueryRequestOptions() { PartitionKey = new PartitionKey("Error")});

 while (feedIterator.HasMoreResults)
 {
     foreach(var item in await feedIterator.ReadNextAsync()){
     {
         Console.WriteLine(item.cost); 
     }
 }
 

GetItemQueryIterator<T>(String, String, QueryRequestOptions)

This method creates a query for items under a container in an Azure Cosmos database using a SQL statement with parameterized values. It returns a FeedIterator. For more information on preparing SQL statements with parameterized values, please see QueryDefinition.

public abstract Microsoft.Azure.Cosmos.FeedIterator<T> GetItemQueryIterator<T> (string queryText = null, string continuationToken = null, Microsoft.Azure.Cosmos.QueryRequestOptions requestOptions = null);
abstract member GetItemQueryIterator : string * string * Microsoft.Azure.Cosmos.QueryRequestOptions -> Microsoft.Azure.Cosmos.FeedIterator<'T>
Public MustOverride Function GetItemQueryIterator(Of T) (Optional queryText As String = null, Optional continuationToken As String = null, Optional requestOptions As QueryRequestOptions = null) As FeedIterator(Of T)

Type Parameters

T

Parameters

queryText
String

The cosmos SQL query text.

continuationToken
String

(Optional) The continuation token in the Azure Cosmos DB service.

requestOptions
QueryRequestOptions

(Optional) The options for the item query request QueryRequestOptions

Returns

An iterator to go through the items.

Examples

Create a query to get all the ToDoActivity that have a cost greater than 9000


public class ToDoActivity{
    public string id {get; set;}
    public string status {get; set;}
    public int cost {get; set;}
}

FeedIterator<ToDoActivity> feedIterator = this.Container.GetItemQueryIterator<ToDoActivity>(
    queryText: "select * from ToDos t where t.cost > 9000", 
    requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey("Error")});
    
while (feedIterator.HasMoreResults)
{
    foreach(var item in await feedIterator.ReadNextAsync()){
    {
        Console.WriteLine(item.cost); 
    }
}
  1. Create a query to get all the ToDoActivity that have a cost greater than 9000

 public class ToDoActivity{
     public string id {get; set;}
     public string status {get; set;}
     public int cost {get; set;}
 }
 
 FeedIterator<ToDoActivity> feedIterator = this.Container.GetItemQueryIterator<ToDoActivity>(
     "select * from ToDos t where t.cost > 9000",
     null,
     new QueryRequestOptions() { PartitionKey = new PartitionKey("Error")});

 while (feedIterator.HasMoreResults)
 {
     foreach(var item in await feedIterator.ReadNextAsync()){
     {
         Console.WriteLine(item.cost);
     }
 }
 
  1. Create a FeedIterator to get all the ToDoActivity.

 public class ToDoActivity{
     public string id {get; set;}
     public string status {get; set;}
     public int cost {get; set;}
 }

 FeedIterator<ToDoActivity> feedIterator = this.Container.GetItemQueryIterator<ToDoActivity>(
     null,
     null,
     new QueryRequestOptions() { PartitionKey = new PartitionKey("Error")});

 while (feedIterator.HasMoreResults)
 {
     foreach(var item in await feedIterator.ReadNextAsync()){
     {
         Console.WriteLine(item.cost); 
     }
 }
 

Applies to