Condividi tramite


DigitalTwinsClient.CreateOrReplaceRelationshipAsync<T> Method

Definition

Creates a relationship on a digital twin asynchronously. If the provided relationship Id is already in use, this will attempt to replace the existing relationship with the provided relationship.

public virtual System.Threading.Tasks.Task<Azure.Response<T>> CreateOrReplaceRelationshipAsync<T> (string digitalTwinId, string relationshipId, T relationship, Azure.ETag? ifNoneMatch = default, System.Threading.CancellationToken cancellationToken = default);
abstract member CreateOrReplaceRelationshipAsync : string * string * 'T * Nullable<Azure.ETag> * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Azure.Response<'T>>
override this.CreateOrReplaceRelationshipAsync : string * string * 'T * Nullable<Azure.ETag> * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Azure.Response<'T>>
Public Overridable Function CreateOrReplaceRelationshipAsync(Of T) (digitalTwinId As String, relationshipId As String, relationship As T, Optional ifNoneMatch As Nullable(Of ETag) = Nothing, 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 which is being created.

relationship
T

The application/json relationship to be created.

ifNoneMatch
Nullable<ETag>

If-None-Match header that makes the request method conditional on a recipient cache or origin server either not having any current representation of the target resource. For more information about this property, see RFC 7232. Acceptable values are null or "". If ifNonMatch option is null the service will replace the existing entity with the new entity. If ifNoneMatch option is "" (or All) the service will reject the request if the entity already exists. An optional ETag to only make the request if the value does not match on the service.

cancellationToken
CancellationToken

The cancellation token.

Returns

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

var floorBuildingRelationshipPayload = new CustomRelationship
{
    Id = "floorBuildingRelationshipId",
    SourceId = "floorTwinId",
    TargetId = "buildingTwinId",
    Name = "containedIn",
    Prop1 = "Prop1 val",
    Prop2 = 4
};

Response<CustomRelationship> createCustomRelationshipResponse = await client
    .CreateOrReplaceRelationshipAsync<CustomRelationship>("floorTwinId", "floorBuildingRelationshipId", floorBuildingRelationshipPayload);
Console.WriteLine($"Created a digital twin relationship '{createCustomRelationshipResponse.Value.Id}' " +
    $"from twin '{createCustomRelationshipResponse.Value.SourceId}' to twin '{createCustomRelationshipResponse.Value.TargetId}'.");

Remarks

Relationships are a one-way link from a source digital twin to another, as described at creation time of the assigned model of the digital twin.

For more samples, see our repo samples.

Applies to

See also