Skip to content

Commit 0290d3c

Browse files
committed
RDoc-3547 Clear session: fix article (C#)
1 parent 1d82ade commit 0290d3c

File tree

10 files changed

+435
-105
lines changed

10 files changed

+435
-105
lines changed

docs/client-api/session/how-to/_clear-a-session-csharp.mdx

Lines changed: 86 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,99 @@ import Tabs from '@theme/Tabs';
33
import TabItem from '@theme/TabItem';
44
import CodeBlock from '@theme/CodeBlock';
55

6-
To clear session state, stop tracking entities, and remove all pending commands,
7-
use the `Clear` method from the `Advanced` session operations.
6+
<Admonition type="note" title="">
87

9-
## Syntax
8+
* Use the `Clear()` method to clear the session’s state:
9+
it **removes ALL tracked entities** and **cancels ALL pending operations** (e.g., _Store_, _Delete_).
10+
This is useful when you need to discard all tracked changes and reset the session state.
11+
12+
* To remove only a **single entity** from tracking, see [Evict a single entity](../../../client-api/session/how-to/evict-entity-from-a-session.mdx).
13+
14+
* In this article:
15+
* [Clear the session's state](../../../client-api/session/how-to/clear-a-session.mdx#clear-the-sessions-state)
16+
* [Syntax](../../../client-api/session/how-to/clear-a-session.mdx#syntax)
17+
18+
</Admonition>
19+
20+
---
21+
22+
## Clear the session's state
23+
24+
<Tabs groupId='languageSyntax'>
25+
<TabItem value="sync_session" label="sync_session">
26+
```csharp
27+
using (var session = store.OpenSession())
28+
{
29+
// Store a new employee
30+
var newEmployee = new Employee
31+
{
32+
FirstName = "John",
33+
LastName = "Doe"
34+
};
35+
session.Store(newEmployee, "employees/1");
36+
37+
// Load an existing employee and modify it
38+
var existingEmployee = session.Load<Employee>("employees/2");
39+
existingEmployee.LastName = "UpdatedLastName";
1040

11-
<TabItem value="clear_1" label="clear_1">
12-
<CodeBlock language="csharp">
13-
{`void Clear();
14-
`}
15-
</CodeBlock>
41+
// Load another employee and mark for deletion
42+
var employeeToDelete = session.Load<Employee>("employees/3");
43+
session.Delete(employeeToDelete);
44+
45+
// At this point:
46+
// * employees/1 is pending insert
47+
// * employees/2 is pending update
48+
// * employees/3 is pending delete
49+
50+
// Clear the session state
51+
// this will remove all tracking and pending operations
52+
session.Advanced.Clear();
53+
54+
// SaveChanges does nothing - all operations were discarded
55+
session.SaveChanges();
56+
}
57+
```
1658
</TabItem>
59+
<TabItem value="async_session" label="async_session">
60+
```csharp
61+
using (var asyncSession = store.OpenAsyncSession())
62+
{
63+
// Store a new employee
64+
var newEmployee = new Employee
65+
{
66+
FirstName = "John",
67+
LastName = "Doe"
68+
};
69+
await asyncSession.StoreAsync(newEmployee, "employees/1");
1770

18-
## Example
71+
// Load an existing employee and modify it
72+
var existingEmployee = await asyncSession.LoadAsync<Employee>("employees/2");
73+
existingEmployee.LastName = "UpdatedLastName";
1974

20-
<TabItem value="clear_2" label="clear_2">
21-
<CodeBlock language="csharp">
22-
{`session.Store(new Employee
23-
\{
24-
FirstName = "John",
25-
LastName = "Doe"
26-
\});
75+
// Load another employee and mark for deletion
76+
var employeeToDelete = await asyncSession.LoadAsync<Employee>("employees/3");
77+
asyncSession.Delete(employeeToDelete);
2778

28-
session.Advanced.Clear();
79+
// At this point:
80+
// * employees/1 is pending insert
81+
// * employees/2 is pending update
82+
// * employees/3 is pending delete
2983
30-
session.SaveChanges(); // nothing will happen
31-
`}
32-
</CodeBlock>
84+
// Clear the session state
85+
// this will remove all tracking and pending operations
86+
asyncSession.Advanced.Clear();
87+
88+
// SaveChangesAsync does nothing - all operations were discarded
89+
await asyncSession.SaveChangesAsync();
90+
}
91+
```
3392
</TabItem>
93+
</Tabs>
3494

95+
## Syntax
3596

97+
<TabItem value="" label="">
98+
```csharp
99+
void Clear();
100+
```
101+
</TabItem>

docs/client-api/session/how-to/clear-a-session.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: "Session: How to Clear a Session"
2+
title: "How to Clear a Session"
33
hide_table_of_contents: true
44
sidebar_label: ...clear a session
55
sidebar_position: 0

versioned_docs/version-5.4/client-api/session/how-to/_clear-a-session-csharp.mdx

Lines changed: 86 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,99 @@ import Tabs from '@theme/Tabs';
33
import TabItem from '@theme/TabItem';
44
import CodeBlock from '@theme/CodeBlock';
55

6-
To clear session state, stop tracking entities, and remove all pending commands,
7-
use the `Clear` method from the `Advanced` session operations.
6+
<Admonition type="note" title="">
87

9-
## Syntax
8+
* Use the `Clear()` method to clear the session’s state:
9+
it **removes ALL tracked entities** and **cancels ALL pending operations** (e.g., _Store_, _Delete_).
10+
This is useful when you need to discard all tracked changes and reset the session state.
11+
12+
* To remove only a **single entity** from tracking, see [Evict a single entity](../../../client-api/session/how-to/evict-entity-from-a-session.mdx).
13+
14+
* In this article:
15+
* [Clear the session's state](../../../client-api/session/how-to/clear-a-session.mdx#clear-the-sessions-state)
16+
* [Syntax](../../../client-api/session/how-to/clear-a-session.mdx#syntax)
17+
18+
</Admonition>
19+
20+
---
21+
22+
## Clear the session's state
23+
24+
<Tabs groupId='languageSyntax'>
25+
<TabItem value="sync_session" label="sync_session">
26+
```csharp
27+
using (var session = store.OpenSession())
28+
{
29+
// Store a new employee
30+
var newEmployee = new Employee
31+
{
32+
FirstName = "John",
33+
LastName = "Doe"
34+
};
35+
session.Store(newEmployee, "employees/1");
36+
37+
// Load an existing employee and modify it
38+
var existingEmployee = session.Load<Employee>("employees/2");
39+
existingEmployee.LastName = "UpdatedLastName";
1040

11-
<TabItem value="clear_1" label="clear_1">
12-
<CodeBlock language="csharp">
13-
{`void Clear();
14-
`}
15-
</CodeBlock>
41+
// Load another employee and mark for deletion
42+
var employeeToDelete = session.Load<Employee>("employees/3");
43+
session.Delete(employeeToDelete);
44+
45+
// At this point:
46+
// * employees/1 is pending insert
47+
// * employees/2 is pending update
48+
// * employees/3 is pending delete
49+
50+
// Clear the session state
51+
// this will remove all tracking and pending operations
52+
session.Advanced.Clear();
53+
54+
// SaveChanges does nothing - all operations were discarded
55+
session.SaveChanges();
56+
}
57+
```
1658
</TabItem>
59+
<TabItem value="async_session" label="async_session">
60+
```csharp
61+
using (var asyncSession = store.OpenAsyncSession())
62+
{
63+
// Store a new employee
64+
var newEmployee = new Employee
65+
{
66+
FirstName = "John",
67+
LastName = "Doe"
68+
};
69+
await asyncSession.StoreAsync(newEmployee, "employees/1");
1770

18-
## Example
71+
// Load an existing employee and modify it
72+
var existingEmployee = await asyncSession.LoadAsync<Employee>("employees/2");
73+
existingEmployee.LastName = "UpdatedLastName";
1974

20-
<TabItem value="clear_2" label="clear_2">
21-
<CodeBlock language="csharp">
22-
{`session.Store(new Employee
23-
\{
24-
FirstName = "John",
25-
LastName = "Doe"
26-
\});
75+
// Load another employee and mark for deletion
76+
var employeeToDelete = await asyncSession.LoadAsync<Employee>("employees/3");
77+
asyncSession.Delete(employeeToDelete);
2778

28-
session.Advanced.Clear();
79+
// At this point:
80+
// * employees/1 is pending insert
81+
// * employees/2 is pending update
82+
// * employees/3 is pending delete
2983
30-
session.SaveChanges(); // nothing will happen
31-
`}
32-
</CodeBlock>
84+
// Clear the session state
85+
// this will remove all tracking and pending operations
86+
asyncSession.Advanced.Clear();
87+
88+
// SaveChangesAsync does nothing - all operations were discarded
89+
await asyncSession.SaveChangesAsync();
90+
}
91+
```
3392
</TabItem>
93+
</Tabs>
3494

95+
## Syntax
3596

97+
<TabItem value="" label="">
98+
```csharp
99+
void Clear();
100+
```
101+
</TabItem>

versioned_docs/version-5.4/client-api/session/how-to/clear-a-session.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: "Session: How to Clear a Session"
2+
title: "How to Clear a Session"
33
hide_table_of_contents: true
44
sidebar_label: ...clear a session
55
sidebar_position: 0

versioned_docs/version-6.0/client-api/session/how-to/_clear-a-session-csharp.mdx

Lines changed: 86 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,99 @@ import Tabs from '@theme/Tabs';
33
import TabItem from '@theme/TabItem';
44
import CodeBlock from '@theme/CodeBlock';
55

6-
To clear session state, stop tracking entities, and remove all pending commands,
7-
use the `Clear` method from the `Advanced` session operations.
6+
<Admonition type="note" title="">
87

9-
## Syntax
8+
* Use the `Clear()` method to clear the session’s state:
9+
it **removes ALL tracked entities** and **cancels ALL pending operations** (e.g., _Store_, _Delete_).
10+
This is useful when you need to discard all tracked changes and reset the session state.
11+
12+
* To remove only a **single entity** from tracking, see [Evict a single entity](../../../client-api/session/how-to/evict-entity-from-a-session.mdx).
13+
14+
* In this article:
15+
* [Clear the session's state](../../../client-api/session/how-to/clear-a-session.mdx#clear-the-sessions-state)
16+
* [Syntax](../../../client-api/session/how-to/clear-a-session.mdx#syntax)
17+
18+
</Admonition>
19+
20+
---
21+
22+
## Clear the session's state
23+
24+
<Tabs groupId='languageSyntax'>
25+
<TabItem value="sync_session" label="sync_session">
26+
```csharp
27+
using (var session = store.OpenSession())
28+
{
29+
// Store a new employee
30+
var newEmployee = new Employee
31+
{
32+
FirstName = "John",
33+
LastName = "Doe"
34+
};
35+
session.Store(newEmployee, "employees/1");
36+
37+
// Load an existing employee and modify it
38+
var existingEmployee = session.Load<Employee>("employees/2");
39+
existingEmployee.LastName = "UpdatedLastName";
1040

11-
<TabItem value="clear_1" label="clear_1">
12-
<CodeBlock language="csharp">
13-
{`void Clear();
14-
`}
15-
</CodeBlock>
41+
// Load another employee and mark for deletion
42+
var employeeToDelete = session.Load<Employee>("employees/3");
43+
session.Delete(employeeToDelete);
44+
45+
// At this point:
46+
// * employees/1 is pending insert
47+
// * employees/2 is pending update
48+
// * employees/3 is pending delete
49+
50+
// Clear the session state
51+
// this will remove all tracking and pending operations
52+
session.Advanced.Clear();
53+
54+
// SaveChanges does nothing - all operations were discarded
55+
session.SaveChanges();
56+
}
57+
```
1658
</TabItem>
59+
<TabItem value="async_session" label="async_session">
60+
```csharp
61+
using (var asyncSession = store.OpenAsyncSession())
62+
{
63+
// Store a new employee
64+
var newEmployee = new Employee
65+
{
66+
FirstName = "John",
67+
LastName = "Doe"
68+
};
69+
await asyncSession.StoreAsync(newEmployee, "employees/1");
1770

18-
## Example
71+
// Load an existing employee and modify it
72+
var existingEmployee = await asyncSession.LoadAsync<Employee>("employees/2");
73+
existingEmployee.LastName = "UpdatedLastName";
1974

20-
<TabItem value="clear_2" label="clear_2">
21-
<CodeBlock language="csharp">
22-
{`session.Store(new Employee
23-
\{
24-
FirstName = "John",
25-
LastName = "Doe"
26-
\});
75+
// Load another employee and mark for deletion
76+
var employeeToDelete = await asyncSession.LoadAsync<Employee>("employees/3");
77+
asyncSession.Delete(employeeToDelete);
2778

28-
session.Advanced.Clear();
79+
// At this point:
80+
// * employees/1 is pending insert
81+
// * employees/2 is pending update
82+
// * employees/3 is pending delete
2983
30-
session.SaveChanges(); // nothing will happen
31-
`}
32-
</CodeBlock>
84+
// Clear the session state
85+
// this will remove all tracking and pending operations
86+
asyncSession.Advanced.Clear();
87+
88+
// SaveChangesAsync does nothing - all operations were discarded
89+
await asyncSession.SaveChangesAsync();
90+
}
91+
```
3392
</TabItem>
93+
</Tabs>
3494

95+
## Syntax
3596

97+
<TabItem value="" label="">
98+
```csharp
99+
void Clear();
100+
```
101+
</TabItem>

versioned_docs/version-6.0/client-api/session/how-to/clear-a-session.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: "Session: How to Clear a Session"
2+
title: "How to Clear a Session"
33
hide_table_of_contents: true
44
sidebar_label: ...clear a session
55
sidebar_position: 0

0 commit comments

Comments
 (0)