BasicRelationship クラス

定義

リレーションシップにはユーザー定義スキーマがありますが、これらのプロパティはすべてのインスタンスに存在する必要があります。 これは、カスタム リレーションシップに必要なプロパティがあることを確認するために、基底クラスとして を使用する場合に便利です。

public class BasicRelationship
type BasicRelationship = class
Public Class BasicRelationship
継承
BasicRelationship

BasicRelationship ヘルパー クラスを使用して、建物のデジタル ツインからフロア デジタル ツインへのリレーションシップをシリアル化して作成する方法の例を次に示します。

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}'.");

ここでは、BasicRelationship ヘルパー クラスを使用してリレーションシップを取得および逆シリアル化する方法の例を示します。

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"]}");
}

注釈

このヘルパー クラスは、 でのみ機能 System.Text.Jsonします。 を と共に使用すると、 ObjectSerializerパラメーター DigitalTwinsClientOptions は既定の (JsonObjectSerializer) でのみ機能します。

その他のサンプルについては、 リポジトリのサンプルを参照してください。

コンストラクター

BasicRelationship()

リレーションシップにはユーザー定義スキーマがありますが、これらのプロパティはすべてのインスタンスに存在する必要があります。 これは、カスタム リレーションシップに必要なプロパティがあることを確認するために、基底クラスとして を使用する場合に便利です。

プロパティ

ETag

RFC7232 に従って、この要求が操作を実行するエンティティの弱い ETag を表す文字列。

Id

リレーションシップの一意の ID。 このフィールドは、すべてのリレーションシップに存在します。

Name

リンクの種類を定義するリレーションシップの名前 (例: Contains)。 このフィールドは、すべてのリレーションシップに存在します。

Properties

DTDL モデルで定義されている追加のカスタム プロパティ。 このプロパティには、このクラスでまだ定義されていないリレーションシップ プロパティが含まれます。

SourceId

ソース デジタル ツインの一意の ID。 このフィールドは、すべてのリレーションシップに存在します。

TargetId

ターゲット デジタル ツインの一意の ID。 このフィールドは、すべてのリレーションシップに存在します。

適用対象