Share via


DigitalTwinsClient.GetRelationshipsAsync<T> Method

Definition

Gets all the relationships on a digital twin by iterating through a collection asynchronously.

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

Type Parameters

T

The type to deserialize the relationship to.

Parameters

digitalTwinId
String

The Id of the source digital twin.

relationshipName
String

The name of a relationship to filter to. If null, all relationships for the digital twin will be returned.

cancellationToken
CancellationToken

The cancellation token.

Returns

The pageable list AsyncPageable<T> of application/json relationships belonging to the specified digital twin and the HTTP response.

Exceptions

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

The exception is thrown when digitalTwinId is null.

Examples

This sample demonstrates iterating over outgoing relationships and deserializing relationship strings into BasicRelationship objects.

AsyncPageable<BasicRelationship> relationships = client.GetRelationshipsAsync<BasicRelationship>("buildingTwinId");
await foreach (BasicRelationship relationship in relationships)
{
    Console.WriteLine($"Retrieved relationship '{relationship.Id}' with source {relationship.SourceId}' and " +
        $"target {relationship.TargetId}.\n\t" +
        $"Prop1: {relationship.Properties["Prop1"]}\n\t" +
        $"Prop2: {relationship.Properties["Prop2"]}");
}

Remarks

Relationships that are returned as part of the pageable list can always be deserialized into an instance of BasicRelationship. You may also deserialize the relationship into custom type that extend the BasicRelationship.

For more samples, see our repo samples.

Applies to

See also