diff --git a/sdk/digitaltwins/Azure.DigitalTwins.Core/samples/DigitalTwinsClientSample/RelationshipSamples.cs b/sdk/digitaltwins/Azure.DigitalTwins.Core/samples/DigitalTwinsClientSample/RelationshipSamples.cs index 6a3a4b89cd666..2a102241918ec 100644 --- a/sdk/digitaltwins/Azure.DigitalTwins.Core/samples/DigitalTwinsClientSample/RelationshipSamples.cs +++ b/sdk/digitaltwins/Azure.DigitalTwins.Core/samples/DigitalTwinsClientSample/RelationshipSamples.cs @@ -178,27 +178,18 @@ public async Task RunSamplesAsync(DigitalTwinsClient client) #endregion Snippet:DigitalTwinsSampleGetIncomingRelationships - #region Snippet:DigitalTwinsSampleDeleteAllRelationships + // Delete the contains relationship, created earlier in the sample code, from building to floor. + + #region Snippet:DigitalTwinsSampleDeleteRelationship - // Delete all relationships from building to floor. These relationships were created using the BasicRelationship type. - AsyncPageable buildingRelationshipsToDelete = client.GetRelationshipsAsync("buildingTwinId"); - await foreach (var relationshipToDelete in buildingRelationshipsToDelete) - { - BasicRelationship relationship = JsonSerializer.Deserialize(relationshipToDelete); - Response deleteRelationshipResponse = await client.DeleteRelationshipAsync(relationship.SourceId, relationship.Id); - Console.WriteLine($"Deleted relationship with Id {relationship.Id}. Status response: {deleteRelationshipResponse.Status}."); - } + Response deleteBuildingRelationshipResponse = await client.DeleteRelationshipAsync("buildingTwinId", "buildingFloorRelationshipId"); + Console.WriteLine($"Deleted relationship with Id buildingFloorRelationshipId. Status response: {deleteBuildingRelationshipResponse.Status}."); - // Delete all relationships from floor to building. These relationships were created using the CustomRelationship type. - AsyncPageable floorRelationshipsToDelete = client.GetRelationshipsAsync("floorTwinId"); - await foreach (var relationshipToDelete in floorRelationshipsToDelete) - { - CustomRelationship relationship = JsonSerializer.Deserialize(relationshipToDelete); - Response deleteRelationshipResponse = await client.DeleteRelationshipAsync(relationship.SourceId, relationship.Id); - Console.WriteLine($"Deleted relationship with Id {relationship.Id}. Status response: {deleteRelationshipResponse.Status}."); - } + #endregion Snippet:DigitalTwinsSampleDeleteRelationship - #endregion Snippet:DigitalTwinsSampleDeleteAllRelationships + // Delete the containedIn relationship, created earlier in the sample code, from floor to building. + Response deleteFloorRelationshipResponse = await client.DeleteRelationshipAsync("floorTwinId", "floorBuildingRelationshipId"); + Console.WriteLine($"Deleted relationship with Id floorBuildingRelationshipId. Status response: {deleteFloorRelationshipResponse.Status}."); // Clean up. try diff --git a/sdk/digitaltwins/Azure.DigitalTwins.Core/samples/Readme.md b/sdk/digitaltwins/Azure.DigitalTwins.Core/samples/Readme.md index f776b08e76296..afe29f39d27ce 100644 --- a/sdk/digitaltwins/Azure.DigitalTwins.Core/samples/Readme.md +++ b/sdk/digitaltwins/Azure.DigitalTwins.Core/samples/Readme.md @@ -416,24 +416,9 @@ await foreach (IncomingRelationship incomingRelationship in incomingRelationship To delete all outgoing relationships for a digital twin, simply iterate over the relationships and delete them iteratively. -```C# Snippet:DigitalTwinsSampleDeleteAllRelationships -// Delete all relationships from building to floor. These relationships were created using the BasicRelationship type. -AsyncPageable buildingRelationshipsToDelete = client.GetRelationshipsAsync("buildingTwinId"); -await foreach (var relationshipToDelete in buildingRelationshipsToDelete) -{ - BasicRelationship relationship = JsonSerializer.Deserialize(relationshipToDelete); - Response deleteRelationshipResponse = await client.DeleteRelationshipAsync(relationship.SourceId, relationship.Id); - Console.WriteLine($"Deleted relationship with Id {relationship.Id}. Status response: {deleteRelationshipResponse.Status}."); -} - -// Delete all relationships from floor to building. These relationships were created using the CustomRelationship type. -AsyncPageable floorRelationshipsToDelete = client.GetRelationshipsAsync("floorTwinId"); -await foreach (var relationshipToDelete in floorRelationshipsToDelete) -{ - CustomRelationship relationship = JsonSerializer.Deserialize(relationshipToDelete); - Response deleteRelationshipResponse = await client.DeleteRelationshipAsync(relationship.SourceId, relationship.Id); - Console.WriteLine($"Deleted relationship with Id {relationship.Id}. Status response: {deleteRelationshipResponse.Status}."); -} +```C# Snippet:DigitalTwinsSampleDeleteRelationship +Response deleteBuildingRelationshipResponse = await client.DeleteRelationshipAsync("buildingTwinId", "buildingFloorRelationshipId"); +Console.WriteLine($"Deleted relationship with Id buildingFloorRelationshipId. Status response: {deleteBuildingRelationshipResponse.Status}."); ``` ## Create, list, and delete event routes of digital twins