Database.GetContainerQueryIterator 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
GetContainerQueryIterator<T>(QueryDefinition, String, QueryRequestOptions) |
This method creates a query for containers under an 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 overload. |
GetContainerQueryIterator<T>(String, String, QueryRequestOptions) |
This method creates a query for containers under an database using a SQL statement. It returns a FeedIterator. |
GetContainerQueryIterator<T>(QueryDefinition, String, QueryRequestOptions)
- Source:
- Database.cs
This method creates a query for containers under an 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 overload.
public abstract Microsoft.Azure.Cosmos.FeedIterator<T> GetContainerQueryIterator<T> (Microsoft.Azure.Cosmos.QueryDefinition queryDefinition, string continuationToken = default, Microsoft.Azure.Cosmos.QueryRequestOptions requestOptions = default);
abstract member GetContainerQueryIterator : Microsoft.Azure.Cosmos.QueryDefinition * string * Microsoft.Azure.Cosmos.QueryRequestOptions -> Microsoft.Azure.Cosmos.FeedIterator<'T>
Public MustOverride Function GetContainerQueryIterator(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 containers
Examples
This create the type feed iterator for containers with queryDefinition as input.
QueryDefinition queryDefinition = new QueryDefinition("SELECT * FROM c where c.status like @status");
.WithParameter("@status", "start%");
using (FeedIterator<ContainerProperties> feedIterator = this.cosmosDatabase.GetContainerQueryIterator<ContainerProperties>(queryDefinition))
{
while (feedIterator.HasMoreResults)
{
FeedResponse<ContainerProperties> response = await feedIterator.ReadNextAsync();
foreach (var container in response)
{
Console.WriteLine(container);
}
}
}
Remarks
Refer to https://docs.microsoft.com/azure/cosmos-db/sql-query-getting-started for syntax and examples.
ReadContainerAsync(ContainerRequestOptions, CancellationToken) is recommended for single container look-up.
Applies to
GetContainerQueryIterator<T>(String, String, QueryRequestOptions)
- Source:
- Database.cs
This method creates a query for containers under an database using a SQL statement. It returns a FeedIterator.
public abstract Microsoft.Azure.Cosmos.FeedIterator<T> GetContainerQueryIterator<T> (string queryText = default, string continuationToken = default, Microsoft.Azure.Cosmos.QueryRequestOptions requestOptions = default);
abstract member GetContainerQueryIterator : string * string * Microsoft.Azure.Cosmos.QueryRequestOptions -> Microsoft.Azure.Cosmos.FeedIterator<'T>
Public MustOverride Function GetContainerQueryIterator(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 containers
Examples
- This create the type feed iterator for containers with queryText as input,
string queryText = "SELECT * FROM c where c.status like 'start%'";
using (FeedIterator<ContainerProperties> feedIterator = this.cosmosDatabase.GetContainerQueryIterator<ContainerProperties>(queryText))
{
while (feedIterator.HasMoreResults)
{
FeedResponse<ContainerProperties> response = await feedIterator.ReadNextAsync();
foreach (var container in response)
{
Console.WriteLine(container);
}
}
}
- This create the type feed iterator for containers without queryText, retrieving all containers.
using (FeedIterator<ContainerProperties> feedIterator = this.cosmosDatabase.GetContainerQueryIterator<ContainerProperties>())
{
while (feedIterator.HasMoreResults)
{
FeedResponse<ContainerProperties> response = await feedIterator.ReadNextAsync();
foreach (var container in response)
{
Console.WriteLine(container);
}
}
}
Remarks
Refer to https://docs.microsoft.com/azure/cosmos-db/sql-query-getting-started for syntax and examples.
ReadContainerAsync(ContainerRequestOptions, CancellationToken) is recommended for single container look-up.
Applies to
Azure SDK for .NET
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기