DigitalTwinsClient.GetRelationshipAsync<T> Method

Definition

Gets a relationship on a digital twin asynchronously.

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

Type Parameters

T

The type to deserialize the relationship to.

Parameters

digitalTwinId
System.String

The Id of the source digital twin.

relationshipId
System.String

The Id of the relationship to retrieve.

cancellationToken
System.Threading.CancellationToken

The cancellation token.

Returns

System.Threading.Tasks.Task<Response<T>>

The deserialized application/json relationship corresponding to the provided relationshipId and the http response Response<T>.

Exceptions

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

System.ArgumentNullException

The exception is thrown when digitalTwinId or relationshipId is null.

Examples

This sample demonstrates getting and deserializing a digital twin relationship into a custom data type.

Response<CustomRelationship> getCustomRelationshipResponse = await client.GetRelationshipAsync<CustomRelationship>(
    "floorTwinId",
    "floorBuildingRelationshipId");
CustomRelationship getCustomRelationship = getCustomRelationshipResponse.Value;
Console.WriteLine($"Retrieved and deserialized relationship '{getCustomRelationship.Id}' from twin '{getCustomRelationship.SourceId}'.\n\t" +
    $"Prop1: {getCustomRelationship.Prop1}\n\t" +
    $"Prop2: {getCustomRelationship.Prop2}");

Remarks

For more samples, see our repo samples.

Applies to