BasicRelationship Class
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Although relationships have a user-defined schema, these properties should exist on every instance. This is useful to use as a base class to ensure your custom relationships have the necessary properties.
public class BasicRelationship
type BasicRelationship = class
Public Class BasicRelationship
- Inheritance
-
BasicRelationship
Examples
Here's an example of how to use the BasicRelationship helper class to serialize and create a relationship from a building digital twin to a floor digital twin.
var buildingFloorRelationshipPayload = new BasicRelationship
{
Id = "buildingFloorRelationshipId",
SourceId = "buildingTwinId",
TargetId = "floorTwinId",
Name = "contains",
Properties =
{
{ "Prop1", "Prop1 value" },
{ "Prop2", 6 }
}
};
Response<BasicRelationship> createBuildingFloorRelationshipResponse = await client
.CreateOrReplaceRelationshipAsync<BasicRelationship>("buildingTwinId", "buildingFloorRelationshipId", buildingFloorRelationshipPayload);
Console.WriteLine($"Created a digital twin relationship '{createBuildingFloorRelationshipResponse.Value.Id}' " +
$"from twin '{createBuildingFloorRelationshipResponse.Value.SourceId}' to twin '{createBuildingFloorRelationshipResponse.Value.TargetId}'.");
Here's an example of how to use the BasicRelationship helper class to get and deserialize a relationship.
Response<BasicRelationship> getBasicRelationshipResponse = await client.GetRelationshipAsync<BasicRelationship>(
"buildingTwinId",
"buildingFloorRelationshipId");
if (getBasicRelationshipResponse.GetRawResponse().Status == (int)HttpStatusCode.OK)
{
BasicRelationship basicRelationship = getBasicRelationshipResponse.Value;
Console.WriteLine($"Retrieved relationship '{basicRelationship.Id}' from twin {basicRelationship.SourceId}.\n\t" +
$"Prop1: {basicRelationship.Properties["Prop1"]}\n\t" +
$"Prop2: {basicRelationship.Properties["Prop2"]}");
}
Remarks
This helper class will only work with System.Text.Json. When used with the ObjectSerializer, parameter to DigitalTwinsClientOptions it will only work with the default (JsonObjectSerializer).
For more samples, see our repo samples.
Constructors
BasicRelationship() |
Properties
ETag |
A string representing a weak ETag for the entity that this request performs an operation against, as per RFC7232. |
Id |
The unique Id of the relationship. This field is present on every relationship. |
Name |
The name of the relationship, which defines the type of link (e.g. Contains). This field is present on every relationship. |
Properties |
Additional, custom properties defined in the DTDL model. This property will contain any relationship properties that are not already defined in this class. |
SourceId |
The unique Id of the source digital twin. This field is present on every relationship. |
TargetId |
The unique Id of the target digital twin. This field is present on every relationship. |