共用方式為


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
String

The Id of the source digital twin.

relationshipId
String

The Id of the relationship to retrieve.

cancellationToken
CancellationToken

The cancellation token.

Returns

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.

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

See also