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.
0 commit comments