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/azure-functions/durable/durable-functions-dotnet-entities.md
+58-6Lines changed: 58 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -151,13 +151,65 @@ public class Counter : TaskEntity<int>
151
151
152
152
### Deleting entities in the isolated model
153
153
154
-
Deleting an entity in the isolated model is accomplished by setting the entity state to `null`, and this process depends on the entity implementation path used:
154
+
Deleting an entity in the isolated model is accomplished by setting the entity state to `null`, and this process depends on the entity implementation path used.
155
+
156
+
#### Delete with ITaskEntity or function-based syntax
157
+
158
+
When deriving from `ITaskEntity` or using [function based syntax](#function-based-syntax), delete is accomplished by calling `TaskEntityOperation.State.SetState(null)`:
159
+
160
+
```csharp
161
+
// Inside a function-based entity dispatch
162
+
switch (operation.Name.ToLowerInvariant())
163
+
{
164
+
case"delete":
165
+
operation.State.SetState(null);
166
+
break;
167
+
}
168
+
```
169
+
170
+
#### Delete with TaskEntity\<TState\>
171
+
172
+
When deriving from `TaskEntity<TState>`, a delete operation is implicitly defined. However, it can be overridden by defining a method `Delete` on the entity. State can also be deleted from any operation via `this.State = null`.
173
+
174
+
- To delete by setting state to `null` requires `TState` to be nullable.
175
+
- The implicitly defined delete operation deletes non-nullable `TState`.
176
+
177
+
The following example shows a `TaskEntity<int?>` with nullable state that overrides the default delete:
When using a POCO as your state (not deriving from `TaskEntity<TState>`), a delete operation is implicitly defined. It's possible to override the delete operation by defining a method `Delete` on the POCO. However, there isn't a way to set state to `null` in the POCO route, so the implicitly defined delete operation is the only true delete.
197
+
198
+
```csharp
199
+
publicclassCounter
200
+
{
201
+
publicintValue { get; set; }
202
+
203
+
// The implicit delete operation handles state removal.
204
+
// Defining a Delete method here overrides the implicit behavior,
205
+
// but you cannot set state to null from within a POCO entity.
- When deriving from `ITaskEntity` or using [function based syntax](#function-based-syntax), delete is accomplished by calling `TaskEntityOperation.State.SetState(null)`.
157
-
- When deriving from `TaskEntity<TState>`, delete is implicitly defined. However, it can be overridden by defining a method `Delete` on the entity. State can also be deleted from any operation via `this.State = null`.
158
-
- To delete by setting state to null requires `TState` to be nullable.
159
-
- The implicitly defined delete operation deletes non-nullable `TState`.
160
-
- When using a POCO as your state (not deriving from `TaskEntity<TState>`), delete is implicitly defined. It's possible to override the delete operation by defining a method `Delete` on the POCO. However, there isn't a way to set state to `null` in the POCO route, so the implicitly defined delete operation is the only true delete.
_logger.LogInformation("Heartbeat logged at {Timestamp}.", DateTimeOffset.UtcNow);
109
+
returnTask.FromResult<object?>(null);
110
+
}
71
111
}
72
112
```
73
113
114
+
Use `object?` as the generic type argument for class-based orchestrations and activities that don't need functional input or output. This pattern lets you use dependency injection (for example, `ILogger<T>`) in activities while still using the class-based model.
115
+
74
116
## Durable entities
75
117
76
118
Durable entities are supported in the .NET isolated worker. For more information, see the [developer's guide](./durable-functions-dotnet-entities.md).
> The sample linked in the prerequisites (`samples/precompiled`) uses the in-process model. The following **Isolated model** sections show equivalent code for the .NET isolated worker model.
97
+
95
98
Notice the `await Task.WhenAll(tasks);` line. The code doesn't await the individual calls to `E2_CopyFileToBlob`, so they run in parallel. When the orchestrator passes the task array to `Task.WhenAll`, it returns a task that doesn't complete until all copy operations complete. If you're familiar with the Task Parallel Library (TPL) in .NET, this pattern is familiar. The difference is that these tasks could be running on multiple virtual machines concurrently, and the Durable Functions extension ensures that the end-to-end execution is resilient to process recycling.
96
99
97
100
After the orchestrator awaits `Task.WhenAll`, all function calls are complete and return values. Each call to `E2_CopyFileToBlob` returns the number of bytes uploaded. Calculate the total by adding the return values.
logger.LogInformation("Found {FileCount} file(s) under {RootDirectory}.", files.Length, rootDirectory);
393
+
394
+
returnfiles;
395
+
}
396
+
}
397
+
```
398
+
399
+
</details>
400
+
401
+
<br>
402
+
324
403
# [JavaScript](#tab/javascript)
325
404
326
405
<details>
@@ -385,6 +464,60 @@ Java sample coming soon.
385
464
386
465
The function uses Azure Functions binding features like the [`Binder` parameter](../functions-dotnet-class-library.md#binding-at-runtime). You don't need those details for this walkthrough.
0 commit comments