---
title: "SQL-234: Retrieve OfficeCode via FillPolicy"
summary: Load an OfficeCode by primary key from the office code of the just-loaded policy.
status: draft
owner: SAIF Doc Gen
last_reviewed: 2026-09-24
library: SAIF.Services
reference_type: package
---

# SQL-234: Retrieve OfficeCode via FillPolicy

`PolicyDocumentsBatchService.FillPolicy` loads `OfficeCode` by primary key using `IRepository<T>.Get(id)`, which materializes to NHibernate `ISession.Get`. NHibernate returns the instance from the session's first-level cache (issuing no SQL) if it is already loaded; otherwise it issues the single-row `SELECT` below.

## Classification

| Field | Value |
| --- | --- |
| **SQL ID** | SQL-234 |
| **Operation type** | Read |
| **Execution method** | ORM (`IRepository<T>.Get(id)` → NHibernate `ISession.Get`) |
| **Database** | Oracle |
| **Schema** | [unqualified]** |
| **Command type** | N/A (ORM-generated) |
| **Business object** | `OfficeCode` |
| **Criteria property** | N/A — ORM |
| **Lifecycle method** | `FillPolicy` |

## Parameters

| Parameter | Direction | Type | Max length | Description |
| --- | --- | --- | --- | --- |
| `:code` | Input | string | N/A | `releasedAgencyDeliveredSaifDoc.Policy.Office.Code`, the FK identifier of the just-loaded policy's office proxy |

## Tables

| Table | Access | Columns used |
| --- | --- | --- |
| [OFFICE_CODE](../database-tables.md#office_code) | SELECT | CODE, CODE_DESCR, CANCELLATION_TRACK_CODE, LOC_SEQ_NUM, PMS_OFFICE_CODE, POLICY_REGION_CODE, POLICY_RENEWAL_TRACK_CODE |

The `Policy` `Get(...)` at L369 is a separate statement documented on its own page; `POLICY` is not part of this statement.

## LINQ statement

Source: `Services/SAIF.Services/OutputDocuments/PolicyDocumentsBatchService.cs:370`

```csharp
releasedAgencyDeliveredSaifDoc.Policy.Office =
    unitOfWork.GetRepository<Data.Model.OfficeCode>().Get(releasedAgencyDeliveredSaifDoc.Policy.Office.Code);
```

## Sample SQL

> **Inferred SQL:** This SQL was inferred from the LINQ statement above and the NHibernate mappings. It is not concrete SQL from source code; NHibernate generates the executed statement at runtime, so aliases, column order, join syntax, and bind-parameter names may differ.

```sql
-- Inferred from LINQ (NHibernate mapping translation); not concrete SQL
SELECT O.CODE,
       O.CODE_DESCR,
       O.CANCELLATION_TRACK_CODE,
       O.LOC_SEQ_NUM,
       O.PMS_OFFICE_CODE,
       O.POLICY_REGION_CODE,
       O.POLICY_RENEWAL_TRACK_CODE
FROM   OFFICE_CODE O
WHERE  O.CODE = :code
```

Translation notes:
- No LINQ query here: this is a load by primary key. NHibernate returns the instance from the session's first-level cache (issuing no SQL) if it is already loaded; otherwise it issues this single-row `SELECT`. Provenance stays `inferred-from-linq` in the skill's sense (SQL derived from the ORM mapping, not concrete text).
- The `Policy` `Get(...)` at L369 is a separate statement documented on its own page; `POLICY` is not part of this statement.

## Operations and processes
- PolicyDocumentsBatchService.FillPolicy — see [Operations and processes](../operations-processes.md)

## Sources
- `Services/SAIF.Services/OutputDocuments/PolicyDocumentsBatchService.cs (L371)`
