共用方式為


DigitalTwinsClient.QueryAsync<T>(String, CancellationToken) Method

Definition

Queries for digital twins by iterating through a collection asynchronously.

public virtual Azure.AsyncPageable<T> QueryAsync<T> (string query, System.Threading.CancellationToken cancellationToken = default);
abstract member QueryAsync : string * System.Threading.CancellationToken -> Azure.AsyncPageable<'T>
override this.QueryAsync : string * System.Threading.CancellationToken -> Azure.AsyncPageable<'T>
Public Overridable Function QueryAsync(Of T) (query As String, Optional cancellationToken As CancellationToken = Nothing) As AsyncPageable(Of T)

Type Parameters

T

The type to deserialize the result to.

Parameters

query
String

The query string, in SQL-like syntax.

cancellationToken
CancellationToken

The cancellation token.

Returns

The pageable list AsyncPageable<T> of query results.

Exceptions

The exception that captures the errors from the service. Check the ErrorCode and Status properties for more details.

Examples

// This code snippet demonstrates the simplest way to iterate over the digital twin results, where paging
// happens under the covers.
AsyncPageable<BasicDigitalTwin> asyncPageableResponse = client.QueryAsync<BasicDigitalTwin>("SELECT * FROM digitaltwins");

// Iterate over the twin instances in the pageable response.
// The "await" keyword here is required because new pages will be fetched when necessary,
// which involves a request to the service.
await foreach (BasicDigitalTwin twin in asyncPageableResponse)
{
    Console.WriteLine($"Found digital twin '{twin.Id}'");
}

Remarks

For more samples, see our repo samples. Note that there may be a delay between before changes in your instance are reflected in queries. For more details on query limitations, see Query limitations.

Applies to

See also