共用方式為


Database.GetUserQueryIterator Method

Definition

Overloads

GetUserQueryIterator<T>(QueryDefinition, String, QueryRequestOptions)

This method creates a query for users 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.

GetUserQueryIterator<T>(String, String, QueryRequestOptions)

This method creates a query for users under an database using a SQL statement. It returns a FeedIterator.

GetUserQueryIterator<T>(QueryDefinition, String, QueryRequestOptions)

Source:
Database.cs

This method creates a query for users 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> GetUserQueryIterator<T> (Microsoft.Azure.Cosmos.QueryDefinition queryDefinition, string continuationToken = default, Microsoft.Azure.Cosmos.QueryRequestOptions requestOptions = default);
abstract member GetUserQueryIterator : Microsoft.Azure.Cosmos.QueryDefinition * string * Microsoft.Azure.Cosmos.QueryRequestOptions -> Microsoft.Azure.Cosmos.FeedIterator<'T>
Public MustOverride Function GetUserQueryIterator(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 user query request.

Returns

An iterator to go through the users

Examples

This create the type feed iterator for users with queryDefinition as input.

QueryDefinition queryDefinition = new QueryDefinition("SELECT * FROM c where c.status like @status")
    .WithParameter("@status", "start%");
using (FeedIterator<UserProperties> resultSet = this.cosmosDatabase.GetUserQueryIterator<UserProperties>(queryDefinition))
{
    while (feedIterator.HasMoreResults)
    {
        foreach (UserProperties properties in await feedIterator.ReadNextAsync())
        {
            Console.WriteLine(properties.Id);
        }
    }
}

Applies to

GetUserQueryIterator<T>(String, String, QueryRequestOptions)

Source:
Database.cs

This method creates a query for users under an database using a SQL statement. It returns a FeedIterator.

public abstract Microsoft.Azure.Cosmos.FeedIterator<T> GetUserQueryIterator<T> (string queryText = default, string continuationToken = default, Microsoft.Azure.Cosmos.QueryRequestOptions requestOptions = default);
abstract member GetUserQueryIterator : string * string * Microsoft.Azure.Cosmos.QueryRequestOptions -> Microsoft.Azure.Cosmos.FeedIterator<'T>
Public MustOverride Function GetUserQueryIterator(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 user query request.

Returns

An iterator to go through the users

Examples

  1. This create the type feed iterator for users with queryText as input,
string queryText = "SELECT * FROM c where c.status like 'start%'";
using (FeedIterator<UserProperties> HasMoreResults = this.cosmosDatabase.GetUserQueryIterator<UserProperties>(queryText))
{
    while (feedIterator.HasMoreResults)
    {
        FeedResponse<UserProperties> response = await feedIterator.ReadNextAsync();
        foreach (var user in response)
        {
            Console.WriteLine(user);
        }
    }
}
  1. This create the type feed iterator for users without queryText, retrieving all users.
using (FeedIterator<UserProperties> feedIterator = this.cosmosDatabase.GetUserQueryIterator<UserProperties>())
{
    while (feedIterator.HasMoreResults)
    {
        FeedResponse<UserProperties> response = await feedIterator.ReadNextAsync();
        foreach (var user in response)
        {
            Console.WriteLine(user);
        }
    }
}

Applies to