Skip to content

Commit 9c5d27a

Browse files
docs: LazyList<T> invalidation via IsValid, TTList<T> properties
1 parent 3a6ef56 commit 9c5d27a

4 files changed

Lines changed: 18 additions & 9 deletions

File tree

docs/guide/context.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ Create a Unit of Work session. See [Sessions](sessions.md):
267267
LSession := LContext.CreateSession<TPerson>(LPersonList);
268268
```
269269

270-
An overload accepts a `TTLazyList<T>` directly. After `ApplyChanges` the lazy list is invalidated so it reloads from the database on next access:
270+
When the list comes from a lazy collection (a `TTLazyList<T>` field exposed as `TTList<T>`), `ApplyChanges` invalidates the underlying lazy list so it reloads from the database on next access:
271271

272272
```pascal
273273
LSession := LContext.CreateSession<TOrder>(LCustomer.Orders);

docs/guide/cookbook.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,14 +224,23 @@ type
224224
// ...
225225
[TDetailColumn('ID', 'OrderID')]
226226
FDetails: TTLazyList<TOrderDetail>;
227+
228+
function GetDetails: TTList<TOrderDetail>;
227229
public
228-
property Details: TTLazyList<TOrderDetail> read FDetails;
230+
property Details: TTList<TOrderDetail> read GetDetails;
229231
end;
230232
```
231233

234+
```pascal
235+
function TOrder.GetDetails: TTList<TOrderDetail>;
236+
begin
237+
Result := FDetails.List;
238+
end;
239+
```
240+
232241
```pascal
233242
LOrder := LContext.Get<TOrder>(LOrderID);
234-
for LDetail in LOrder.Details.Value do
243+
for LDetail in LOrder.Details do
235244
Writeln(Format(' %s x%d', [LDetail.ProductName, LDetail.Quantity]));
236245
```
237246

docs/guide/lazy-loading.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,21 +89,21 @@ end;
8989

9090
### Behavior
9191

92-
- The list is loaded on the first access to `.List`. A SELECT query is executed with a filter matching the foreign key column to the parent's ID.
92+
- The list is loaded on first access. A SELECT query is executed with a filter matching the foreign key column to the parent's ID.
9393
- `AddEntity` creates a new entity via the context and adds it to the list:
9494

9595
```pascal
9696
LNewEmployee := FEmployees.AddEntity;
9797
LNewEmployee.Firstname := 'Alice';
9898
```
9999

100-
- When the parent's ID changes, the cached list is freed and will be reloaded on next access.
100+
- When the parent's ID changes, the cached list is invalidated and will be reloaded on next access.
101101

102102
### Invalidation and Sessions
103103

104-
`TTLazyList<T>` implements the `ITLazyList<T>` interface (`Invalidate`, `GetList`). Calling `Invalidate` discards the cached list so the next access re-runs the SELECT.
104+
The cached list carries an `IsValid` flag. When it is cleared -- for example when the parent's ID changes -- the next access re-runs the SELECT and refills the same list instance in place.
105105

106-
This integrates with the Unit of Work: `CreateSession<T>` has an overload that takes a `TTLazyList<T>` directly. When the session's `ApplyChanges` completes, it invalidates the lazy list automatically, so the in-memory collection reflects the persisted state on the next read:
106+
This integrates with the Unit of Work: the collection is a `TTList<T>`, so you pass it straight to `CreateSession<T>`. When the session's `ApplyChanges` completes, it invalidates the underlying lazy list automatically, so the in-memory collection reflects the persisted state on the next read:
107107

108108
```pascal
109109
var LSession := LContext.CreateSession<TEmployee>(LDepartment.Employees);

docs/guide/sessions.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ end;
2929

3030
## Creating from a Lazy List
3131

32-
`CreateSession<T>` also accepts a `TTLazyList<T>` (via the `ITLazyList<T>` interface) instead of a plain list. This is convenient for editing the children of a parent entity loaded through [lazy loading](lazy-loading.md):
32+
A lazy collection exposes its children as a `TTList<T>`, which you can pass straight to `CreateSession<T>`. This is convenient for editing the children of a parent entity loaded through [lazy loading](lazy-loading.md):
3333

3434
```pascal
3535
var LSession := LContext.CreateSession<TEmployee>(LDepartment.Employees);
3636
```
3737

38-
When `ApplyChanges` completes, the session invalidates the lazy list, so the parent's collection reloads from the database on next access and stays in sync with the persisted state.
38+
When `ApplyChanges` completes, the session invalidates the underlying lazy list, so the parent's collection reloads from the database on next access and stays in sync with the persisted state.
3939

4040
## How It Works
4141

0 commit comments

Comments
 (0)