You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/digital-twins/how-to-manage-twin.md
+25-25Lines changed: 25 additions & 25 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,7 @@ titleSuffix: Azure Digital Twins
5
5
description: See how to retrieve, update, and delete individual twins and relationships.
6
6
author: baanders
7
7
ms.author: baanders # Microsoft employees only
8
-
ms.date: 2/13/2025
8
+
ms.date: 03/04/2025
9
9
ms.topic: how-to
10
10
ms.service: azure-digital-twins
11
11
@@ -45,12 +45,12 @@ To create a digital twin, you need to provide:
45
45
* The [model](concepts-models.md) you want to use
46
46
* Any desired initialization of twin data, including...
47
47
- Properties (initialization optional): You can set initial values for properties of the digital twin if you want. Properties are treated as optional and can be set later, but note that **they won't show up as part of a twin until they've been set**.
48
-
- Components (initialization required if they're present on a twin): If your twin contains any [components](concepts-models.md#model-attributes), these must be initialized when the twin is created. They can be empty objects, but the components themselves have to exist.
48
+
- Components (initialization required if they're present on a twin): If your twin contains any [components](concepts-models.md#model-attributes), these components must be initialized when the twin is created. They can be empty objects, but the components themselves have to exist.
49
49
50
50
The model and any initial property values are provided through the `initData` parameter, which is a JSON string containing the relevant data. For more information on structuring this object, continue to the next section.
51
51
52
52
> [!TIP]
53
-
> After creating or updating a twin, there may be a latency of up to 10 seconds before the changes will be reflected in [queries](how-to-query-graph.md). The `GetDigitalTwin` API (described [later in this article](#get-data-for-a-digital-twin)) does not experience this delay, so if you need an instant response, use the API call instead of querying to see your newly-created twins.
53
+
> After you create or update a twin, there might be a latency of up to 10 seconds before the changes will be reflected in [queries](how-to-query-graph.md). The `GetDigitalTwin` API (described [later in this article](#get-data-for-a-digital-twin)) doesn't experience this delay, so if you need an instant response, use the API call instead of querying to see your newlycreated twins.
54
54
55
55
### Initialize model and properties
56
56
@@ -86,7 +86,7 @@ You can use the [Import Jobs API](concepts-apis-sdks.md#bulk-import-with-the-imp
86
86
>[!TIP]
87
87
>The Import Jobs API also allows models and relationships to be imported in the same call, to create all parts of a graph at once. For more about this process, see [Upload models, twins, and relationships in bulk with the Import Jobs API](how-to-manage-graph.md#upload-models-twins-and-relationships-in-bulk-with-the-import-jobs-api).
Youcanviewanexampleimportfileandasampleprojectfor creating these files in the [Import Jobs API introduction](concepts-apis-sdks.md#bulk-import-with-the-import-jobs-api).
92
92
@@ -100,7 +100,7 @@ You can access the details of any digital twin by calling the `GetDigitalTwin()`
Thiscallreturnstwindataasastrongly-typedobjecttypesuchas `BasicDigitalTwin`. `BasicDigitalTwin` isaserializationhelperclassincludedwiththeSDK, whichreturnsthecoretwinmetadataandpropertiesinpreparsedform. YoucanalwaysdeserializetwindatausingtheJSONlibraryofyourchoice, like `System.Text.Json` or `Newtonsoft.Json`. Forbasicaccesstoatwin, however, thehelperclassescanmakethismoreconvenient.
103
+
Thiscallreturnstwindataasastronglytypedobjecttypesuchas `BasicDigitalTwin`. `BasicDigitalTwin` isaserializationhelperclassincludedwiththeSDK, whichreturnsthecoretwinmetadataandpropertiesinpreparsedform. YoucanalwaysdeserializetwindatausingtheJSONlibraryofyourchoice, like `System.Text.Json` or `Newtonsoft.Json`. Forbasicaccesstoatwin, however, thehelperclassescanmakedeserializingtwindatamoreconvenient.
@@ -142,11 +142,11 @@ The result of calling `object result = await client.GetDigitalTwinAsync("my-moon
142
142
143
143
The defined properties of the digital twin are returned as top-level properties on the digital twin. Metadata or system information that isn't part of the DTDL definition is returned with a `$` prefix. Metadata properties include the following values:
144
144
*`$dtId`: The ID of the digital twin in this Azure Digital Twins instance
145
-
*`$etag`: A standard HTTP field assigned by the web server. This is updated to a new value every time the twin is updated, which can be useful to determine whether the twin's data has been updated on the server since a previous check. You can use `If-Match` to perform updates and deletes that only complete if the entity's etag matches the etag provided. For more information on these operations, see the documentation for [DigitalTwins Update](/rest/api/digital-twins/dataplane/twins/digital-twins-update) and [DigitalTwins Delete](/rest/api/digital-twins/dataplane/twins/digital-twins-delete).
146
-
*`$metadata`: A set of metadata properties, which might include the following:
145
+
*`$etag`: A standard HTTP field assigned by the web server. This property is updated to a new value every time the twin is updated, which can be useful to determine whether the twin's data updated on the server since a previous check. You can use `If-Match` to perform updates and deletes that only complete if the entity's etag matches the etag provided. For more information on these operations, see the documentation for [DigitalTwins Update](/rest/api/digital-twins/dataplane/twins/digital-twins-update) and [DigitalTwins Delete](/rest/api/digital-twins/dataplane/twins/digital-twins-delete).
146
+
*`$metadata`: A set of metadata properties, which might include the following properties:
147
147
-`$model`, the DTMI of the model of the digital twin.
148
-
-`lastUpdateTime` for twin properties. This is a timestamp indicating the date and time that Azure Digital Twins processed the property update message
149
-
-`sourceTime` for twin properties. This is an optional, writable property representing the timestamp when the property update was observed in the real world.
148
+
-`lastUpdateTime` for twin properties. This property is a timestamp indicating the date and time that Azure Digital Twins processed the property update message
149
+
-`sourceTime` for twin properties. This property is an optional, writable property representing the timestamp when the property update was observed in the real world.
150
150
151
151
You can read more about the fields contained in a digital twin in [Digital twin JSON format](concepts-twins-graph.md#digital-twin-json-format). You can read more about the serialization helper classes like `BasicDigitalTwin` in [Azure Digital Twins APIs and SDKs](concepts-apis-sdks.md#serialization-helpers-in-the-net-c-sdk).
152
152
@@ -160,7 +160,7 @@ Here's the body of the basic query that returns a list of all digital twins in t
160
160
161
161
## Update a digital twin
162
162
163
-
To update properties of a digital twin, write the information you want to replace in [JSON Patch](http://jsonpatch.com/) format. For a full list of JSON Patch operations that can be used, including `replace`, `add` and `remove`, see the [Operations for JSON Patch](http://jsonpatch.com/#operations).
163
+
To update properties of a digital twin, write the information you want to replace in [JSON Patch](http://jsonpatch.com/) format. For a full list of JSON Patch operations that can be used, including `replace`, `add`, and `remove`, see the [Operations for JSON Patch](http://jsonpatch.com/#operations).
164
164
165
165
After crafting the JSON Patch document containing update information, pass the document into the `UpdateDigitalTwin()` method:
166
166
@@ -169,9 +169,9 @@ After crafting the JSON Patch document containing update information, pass the d
169
169
A single patch call can update as many properties on a single twin as you want (even all of them). If you need to update properties across multiple twins, you need a separate update call for each twin.
170
170
171
171
> [!TIP]
172
-
> After creating or updating a twin, there may be a latency of up to 10 seconds before the changes will be reflected in [queries](how-to-query-graph.md). The `GetDigitalTwin` API (described [earlier in this article](#get-data-for-a-digital-twin)) does not experience this delay, so use the API call instead of querying to see your newly-updated twins if you need an instant response.
172
+
> After you create or update a twin, there might be a latency of up to 10 seconds before the changes will be reflected in [queries](how-to-query-graph.md). The `GetDigitalTwin` API (described [earlier in this article](#get-data-for-a-digital-twin)) doesn't experience this delay, so use the API call instead of querying to see your newlyupdated twins if you need an instant response.
173
173
174
-
Here's an example of JSON Patch code. This document replaces the *mass* and *radius* property values of the digital twin it's applied to. This example shows the JSON Patch `replace` operation, which replaces the value of an existing property.
174
+
Here's an example of JSON Patch code. This document replaces the *mass* and *radius* property values of the applicable digital twin. This example shows the JSON Patch `replace` operation, which replaces the value of an existing property.
@@ -198,7 +198,7 @@ Consider a model with an object-type property, `ObjectProperty`. `ObjectProperty
198
198
199
199
When a twin is created using this model, it's not necessary to instantiate the `ObjectProperty` at that time. If the object property isn't instantiated during twin creation, there's no default path created to access `ObjectProperty` and its `StringSubProperty` for a patch operation. You need to add the path to `ObjectProperty` yourself before you can update its properties.
200
200
201
-
This can be done with a JSON Patch `add` operation, like this:
201
+
This addition can be done with a JSON Patch `add` operation, like this:
Although the first step isn't necessary in cases where `ObjectProperty` was instantiated when the twin was created, it's recommended to use it every time you update a sub-property for the first time, since you might not always know with certainty whether the object property was initially instantiated or not.
216
+
Although the first step isn't necessary in cases where `ObjectProperty` was instantiated when the twin was created, we recommend that you use it every time you update a sub-property for the first time, because you might not always know with certainty whether the object property was initially instantiated or not.
217
217
218
218
### Update a digital twin's model
219
219
@@ -223,7 +223,7 @@ For example, consider the following JSON Patch document that replaces the digita
To update the `sourceTime` field on a property that's part of a component, include the component at the start of the path. In the example above, you would do this by changing the path value from `/$metadata/Temperature/sourceTime` to `myComponent/$metadata/Temperature/sourceTime`.
247
+
To update the `sourceTime` field on a property that's part of a component, include the component at the start of the path. In the previous example, you would include the component by changing the path value from `/$metadata/Temperature/sourceTime` to `myComponent/$metadata/Temperature/sourceTime`.
248
248
249
249
>[!NOTE]
250
-
> If you update both the `sourceTime` and value on a property, and then later update only the property's value, the `sourceTime` timestamp from the first update will remain.
250
+
> If you update both the `sourceTime` and value on a property, and then later update only the property's value, the `sourceTime` timestamp from the first update remains.
251
251
252
252
253
253
### Handle conflicting update calls
254
254
255
-
Azure Digital Twins ensures that all incoming requests are processed one after the other. This means that even if multiple functions try to update the same property on a twin at the same time, there's **no need** for you to write explicit locking code to handle the conflict.
255
+
Azure Digital Twins ensures that all incoming requests are processed sequentially, one after the other. This sequential processing means that even if multiple functions try to update the same property on a twin at the same time, there's **no need** for you to write explicit locking code to handle the conflict.
256
256
257
257
This behavior is on a per-twin basis.
258
258
@@ -273,13 +273,13 @@ Here's an example of the code to delete twins and their relationships. The `Dele
273
273
274
274
### Delete all digital twins
275
275
276
-
For an example of how to delete all twins at once, download the sample app used in the [Explore the basics with a sample client app](tutorial-command-line-app.md). The *CommandLoop.cs* file does this in a `CommandDeleteAllTwins()` function.
276
+
For an example of how to delete all twins at once, download the sample app used in the [Explore the basics with a sample client app](tutorial-command-line-app.md). The *CommandLoop.cs* file deletes all digital twins in a `CommandDeleteAllTwins()` function.
You can use the runnable code sample below to create a twin, update its details, and delete the twin.
282
+
You can use the following runnable code sample to create a twin, update its details, and delete the twin.
283
283
284
284
### Set up sample project files
285
285
@@ -305,14 +305,14 @@ Next, complete the following steps to configure your project code:
305
305
dotnet add package Azure.Identity
306
306
```
307
307
308
-
You also need to set up local credentials if you want to run the sample directly. The next section walks through this.
308
+
You also need to set up local credentials if you want to run the sample directly. The next section walks through this prerequisite.
309
309
[!INCLUDE [Azure Digital Twins: local credentials prereq (outer)](../../includes/digital-twins-local-credentials-outer.md)]
310
310
311
311
### Run the sample
312
312
313
313
Now that setup is complete, you can run the sample code project.
314
314
315
-
Here's the console output of the above program:
315
+
Here's the console output of the previous program:
316
316
317
317
:::image type="content" source="./media/how-to-manage-twin/console-output-manage-twins.png" alt-text="Screenshot of the console output showing that the twin is created, updated, and deleted." lightbox="./media/how-to-manage-twin/console-output-manage-twins.png":::
0 commit comments