Container.GetItemQueryIterator Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Overloads
GetItemQueryIterator<T>(String, String, QueryRequestOptions) |
This method creates a query for items under a container in an Azure Cosmos database using a SQL statement. It returns a FeedIterator. |
GetItemQueryIterator<T>(FeedRange, 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>(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)
- Source:
- Container.cs
This method creates a query for items under a container in an Azure Cosmos database using a SQL statement. It returns a FeedIterator.
public abstract Microsoft.Azure.Cosmos.FeedIterator<T> GetItemQueryIterator<T> (string queryText = default, string continuationToken = default, Microsoft.Azure.Cosmos.QueryRequestOptions requestOptions = default);
abstract member GetItemQueryIterator : string * string * Microsoft.Azure.Cosmos.QueryRequestOptions -> Microsoft.Azure.Cosmos.FeedIterator<'T>
Public MustOverride Function GetItemQueryIterator(Of T) (Optional queryText As String = Nothing, Optional continuationToken As String = Nothing, Optional requestOptions As QueryRequestOptions = Nothing) 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.
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;}
}
using (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);
}
}
}
- 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;}
}
using (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
GetItemQueryIterator<T>(FeedRange, QueryDefinition, String, QueryRequestOptions)
- Source:
- Container.cs
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.FeedRange feedRange, Microsoft.Azure.Cosmos.QueryDefinition queryDefinition, string continuationToken = default, Microsoft.Azure.Cosmos.QueryRequestOptions requestOptions = default);
abstract member GetItemQueryIterator : Microsoft.Azure.Cosmos.FeedRange * Microsoft.Azure.Cosmos.QueryDefinition * string * Microsoft.Azure.Cosmos.QueryRequestOptions -> Microsoft.Azure.Cosmos.FeedIterator<'T>
Public MustOverride Function GetItemQueryIterator(Of T) (feedRange As FeedRange, queryDefinition As QueryDefinition, Optional continuationToken As String = Nothing, Optional requestOptions As QueryRequestOptions = Nothing) As FeedIterator(Of T)
Type Parameters
- T
Parameters
- feedRange
- FeedRange
A FeedRange obtained from GetFeedRangesAsync(CancellationToken).
- 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.
Returns
An iterator to go through the items.
Examples
Create a query to get all the ToDoActivity that have a cost greater than 9000 for the specified partition
public class ToDoActivity{
public string id {get; set;}
public string status {get; set;}
public int cost {get; set;}
}
IReadOnlyList<FeedRange> feedRanges = await this.Container.GetFeedRangesAsync();
// Distribute feedRanges across multiple compute units and pass each one to a different iterator
QueryDefinition queryDefinition = new QueryDefinition("select * from ToDos t where t.cost > @expensive")
.WithParameter("@expensive", 9000);
using (FeedIterator<ToDoActivity> feedIterator = this.Container.GetItemQueryIterator<ToDoActivity>(
feedRanges[0],
queryDefinition,
null,
new QueryRequestOptions() { }))
{
while (feedIterator.HasMoreResults)
{
foreach(var item in await feedIterator.ReadNextAsync())
{
Console.WriteLine(item.cost);
}
}
}
Remarks
Query as a stream only supports single partition queries
Applies to
GetItemQueryIterator<T>(QueryDefinition, String, QueryRequestOptions)
- Source:
- Container.cs
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 = default, Microsoft.Azure.Cosmos.QueryRequestOptions requestOptions = default);
abstract member GetItemQueryIterator : Microsoft.Azure.Cosmos.QueryDefinition * string * Microsoft.Azure.Cosmos.QueryRequestOptions -> Microsoft.Azure.Cosmos.FeedIterator<'T>
Public MustOverride Function GetItemQueryIterator(Of T) (queryDefinition As QueryDefinition, Optional continuationToken As String = Nothing, Optional requestOptions As QueryRequestOptions = Nothing) As FeedIterator(Of 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.
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 queryDefinition = new QueryDefinition("select * from ToDos t where t.cost > @expensive")
.WithParameter("@expensive", 9000);
using (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);
}
}
}