---
title: Bulk-load contracts for a set of agencies
summary: Populate each agency's contract child collection in one pass.
status: draft
owner: Technical Writer
last_reviewed: 2026-07-31
library: SAIF.Business.Policy.Agency
reference_type: package
operation_id: OP-004
trigger: A caller bulk-loads contract children after loading agencies.
---

# Bulk-load contracts for a set of agencies

This operation avoids per-agency lazy contract retrieval by loading all contract rows once and then distributing them to the matching agencies already present in a collection.

| Field | Value |
| --- | --- |
| **Operation ID** | OP-004 |
| **Trigger** | A caller invokes `clsAgencyCollection.RetrieveContracts()`. |
| **Inputs** | Populated `clsAgencyCollection` |
| **Outputs** | Agency `Contracts` collections populated in memory |
| **Primary components** | `clsAgencyCollection.RetrieveContracts`, `clsAgencyContractCollection.GetAgencyContractCollection` |
| **Entry point** | `Business\SAIF.Business.Policy.Agency\clsAgencyCollection.vb` |

## Steps
1. Retrieve the full contract collection by executing [SQL-004](../sql/SQL-004-retrieve-agency-contracts.md) against [AGENCY_CONTRACT](../database-tables.md#agency_contract).
2. Reset each agency's contract child collection to a fresh empty collection before assignment.
3. Iterate the retrieved contract rows and locate the parent agency by `AgencySeqNum`.
4. Add each contract to the matching agency when the parent exists; otherwise discard the row silently ([BR-006](../business-rules.md#br-006-bulk-loaders-discard-orphan-child-rows)).
5. Return with every in-scope agency carrying an in-memory contract collection populated from the shared query ([BR-007](../business-rules.md#br-007-bulk-loaders-replace-n-plus-1-child-retrieval), [BR-010](../business-rules.md#br-010-agency-contract-collection-scope-depends-on-agency-sequence-number)).

## Process flow

The following diagram visualizes the contract bulk-load path.

```mermaid
flowchart TD
  Start([RetrieveContracts]) --> Query[Run SQL-004]
  Query --> Reset[Reset each agency contract collection]
  Reset --> Match{Parent agency found?}
  Match -->|Yes| Add[Add contract to agency]
  Match -->|No| Drop[Discard row]
  Add --> End([Child collections populated])
  Drop --> End
```

## Failure and edge-case behavior
- Contracts whose parent agency is not already in the collection are ignored.
- The bulk query reads all contracts when no agency filter is supplied.

## Related documentation
- [Index](../index.md)
- [Overview](../overview.md)
- [Operations and processes](../operations-processes.md)
- [Business rules](../business-rules.md)
- [Database tables](../database-tables.md)
- [SQL catalog](../sql/index.md)
- [API reference](../api/index.md)

## Sources
- `Business\SAIF.Business.Policy.Agency\clsAgencyCollection.vb`
- `Business\SAIF.Business.Policy.Agency\clsAgencyContractCollection.vb`
