@@ -196,19 +196,21 @@ public async Task DeleteTwinsAsync()
196
196
197
197
foreach ( KeyValuePair < string , string > twin in twins )
198
198
{
199
+ var digitalTwinId = twin . Key ;
200
+
199
201
try
200
202
{
201
203
// Delete all relationships
202
- AsyncPageable < string > relationships = client . GetRelationshipsAsync ( twin . Key ) ;
204
+ AsyncPageable < string > relationships = client . GetRelationshipsAsync ( digitalTwinId ) ;
203
205
await foreach ( var relationshipJson in relationships )
204
206
{
205
207
BasicRelationship relationship = JsonSerializer . Deserialize < BasicRelationship > ( relationshipJson ) ;
206
- await client . DeleteRelationshipAsync ( twin . Key , relationship . Id ) ;
208
+ await client . DeleteRelationshipAsync ( digitalTwinId , relationship . Id ) ;
207
209
Console . WriteLine ( $ "Found and deleted relationship with Id { relationship . Id } .") ;
208
210
}
209
211
210
212
// Delete any incoming relationships
211
- AsyncPageable < IncomingRelationship > incomingRelationships = client . GetIncomingRelationshipsAsync ( twin . Key ) ;
213
+ AsyncPageable < IncomingRelationship > incomingRelationships = client . GetIncomingRelationshipsAsync ( digitalTwinId ) ;
212
214
213
215
await foreach ( IncomingRelationship incomingRelationship in incomingRelationships )
214
216
{
@@ -217,7 +219,6 @@ public async Task DeleteTwinsAsync()
217
219
}
218
220
219
221
// Now the digital twin should be safe to delete
220
- string digitalTwinId = twin . Key ;
221
222
222
223
#region Snippet:DigitalTwinsSampleDeleteTwin
223
224
@@ -233,7 +234,7 @@ public async Task DeleteTwinsAsync()
233
234
}
234
235
catch ( RequestFailedException ex )
235
236
{
236
- FatalError ( $ "Failed to delete { twin . Key } due to { ex . Message } ") ;
237
+ FatalError ( $ "Failed to delete { digitalTwinId } due to { ex . Message } ") ;
237
238
}
238
239
}
239
240
}
0 commit comments