---
title: "SQL-039: PolicyOutputDocumentRepository.GetPolicyOutputDocumentsByImageId"
summary: Read operation for PolicyOutputDocumentRepository
status: draft
owner: SAIF.Core documentation team
last_reviewed: 2026-09-24
library: SAIF.Data.NHibernate
reference_type: package
---


# SQL-039: PolicyOutputDocumentRepository.GetPolicyOutputDocumentsByImageId

This statement is a read operation invoked through ORM (NHibernate LINQ). Executed by `PolicyOutputDocumentRepository.GetPolicyOutputDocumentsByImageId`.

## Classification

| Field | Value |
| --- | --- |
| **SQL ID** | SQL-039 |
| **Operation type** | Read |
| **Execution method** | ORM (NHibernate LINQ) |
| **Database** | Oracle |
| **Schema** | [unqualified]** |
| **Command type** | N/A (ORM-generated) |
| **Business object** | `PolicyOutputDocumentRepository` |
| **Criteria property** | N/A — ORM |
| **Lifecycle method** | `GetPolicyOutputDocumentsByImageId` |

## Parameters

| Parameter | Direction | Type | Max length | Description |
| --- | --- | --- | --- | --- |
| `:imageId` | Input | long | N/A | Method argument bound into the LINQ expression |

## Tables

| Table | Access | Columns used |
| --- | --- | --- |
| [policy_output_document](../database-tables.md#policy_output_document) | SELECT | `output_document_seq_num`, `update_num`, `policy_period_eff_date`, `agency_seq_num`, `agent_num`, `agency_viewed_flag`, `agency_delivery_flag`, `agency_delete_date`, `create_user`, `create_date`, `update_user`, `update_date`, `release_date`, `hold_task_seq_num`, `task_user`, `source_key_text`, `ACCOUNT_NUM`, `policy_num`, `document_status_code` |
| [output_document](../database-tables.md#output_document) | JOIN (LEFT OUTER, fetch) | `output_document_seq_num`, `update_num`, `image_seq_num`, `document_create_date`, `description`, `create_user`, `create_date`, `update_user`, `update_date`, `output_document_type_code` |
| [output_document_type_code](../database-tables.md#output_document_type_code) | JOIN (LEFT OUTER, fetch) | `code`, `code_descr`, `agency_view_flag`, `agency_inbox_flag`, `manual_add_flag`, `freeform_flag`, `sort_priority_num`, `SOURCE_SYSTEM_CODE`, `PACKAGE_NAME`, `image_file_code`, `image_category_code`, `image_document_type_code`, `output_document_category_code`, `Direct_Write_Notify_Text_Code` |
| [POLICY](../database-tables.md#policy) | JOIN (LEFT OUTER, fetch; two aliases — `P` = `Policy`, `P2` = `Policy.RelationshipPolicy`) | `POLICY_NUM`, `POLICY_NAME`, `LEGAL_NAME`, `SECURE_POLICY_CODE`, `OFFICE_CODE`, `ACCOUNT_NUM`, `POLICY_STATUS_CODE`, `MARKET_TYPE_CODE`, `POLICY_RELATIONSHIP_POLICY_NUM`, `POLICY_RELATIONSHIP_CODE`, `customer_service_team_code`, `ENTITY_CODE`, `TRADING_SEQ_NUM`, `RATE_ACCOUNT`, `AGENT_NUM` (both aliases) |
| [SUB_POLICY](../database-tables.md#sub_policy) | JOIN (LEFT OUTER, collection fetch) | `Sub_Policy_Seq_Num`, `SUBMISSION_STATUS_CODE`, `POLICY_NUM` |

## LINQ statement

Source: `Data/SAIF.Data.NHibernate/Repositories/OutputDocuments/PolicyOutputDocumentRepository.cs:58`. The queryable is obtained at `Data/SAIF.Data.NHibernate/Repositories/OutputDocuments/PolicyOutputDocumentRepository.cs:27` (`EagerLoadQuery`).

```csharp
public IEnumerable<PolicyOutputDocument> GetPolicyOutputDocumentsByImageId(long imageId)
{
    return EagerLoadQuery().Where(x => x.OutputDocument.ImageId == imageId);
}

private IQueryable<PolicyOutputDocument> EagerLoadQuery()
{
    return Query()
            .Fetch(p => p.OutputDocument)
            .ThenFetch(o => o.DocumentType)
            .Fetch(p => p.Policy)
            .ThenFetch(p => p.SubmissionPolicies)
            .Fetch(p => p.Policy)
            .ThenFetch(p => p.RelationshipPolicy);
}
```

## 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
  POD.output_document_seq_num,
  POD.update_num,
  POD.policy_period_eff_date,
  POD.agency_seq_num,
  POD.agent_num,
  POD.agency_viewed_flag,
  POD.agency_delivery_flag,
  POD.agency_delete_date,
  POD.create_user,
  POD.create_date,
  POD.update_user,
  POD.update_date,
  POD.release_date,
  POD.hold_task_seq_num,
  POD.task_user,
  POD.source_key_text,
  POD.ACCOUNT_NUM,
  POD.policy_num,
  POD.document_status_code,
  OD.output_document_seq_num,
  OD.update_num,
  OD.image_seq_num,
  OD.document_create_date,
  OD.description,
  OD.create_user,
  OD.create_date,
  OD.update_user,
  OD.update_date,
  OD.output_document_type_code,
  ODTC.code,
  ODTC.code_descr,
  ODTC.agency_view_flag,
  ODTC.agency_inbox_flag,
  ODTC.manual_add_flag,
  ODTC.freeform_flag,
  ODTC.sort_priority_num,
  ODTC.SOURCE_SYSTEM_CODE,
  ODTC.PACKAGE_NAME,
  ODTC.image_file_code,
  ODTC.image_category_code,
  ODTC.image_document_type_code,
  ODTC.output_document_category_code,
  ODTC.Direct_Write_Notify_Text_Code,
  P.POLICY_NUM,
  P.POLICY_NAME,
  P.LEGAL_NAME,
  P.SECURE_POLICY_CODE,
  P.OFFICE_CODE,
  P.ACCOUNT_NUM,
  P.POLICY_STATUS_CODE,
  P.MARKET_TYPE_CODE,
  P.POLICY_RELATIONSHIP_POLICY_NUM,
  P.POLICY_RELATIONSHIP_CODE,
  P.customer_service_team_code,
  P.ENTITY_CODE,
  P.TRADING_SEQ_NUM,
  P.RATE_ACCOUNT,
  P.AGENT_NUM,
  SP.Sub_Policy_Seq_Num,
  SP.SUBMISSION_STATUS_CODE,
  SP.POLICY_NUM,
  P2.POLICY_NUM,
  P2.POLICY_NAME,
  P2.LEGAL_NAME,
  P2.SECURE_POLICY_CODE,
  P2.OFFICE_CODE,
  P2.ACCOUNT_NUM,
  P2.POLICY_STATUS_CODE,
  P2.MARKET_TYPE_CODE,
  P2.POLICY_RELATIONSHIP_POLICY_NUM,
  P2.POLICY_RELATIONSHIP_CODE,
  P2.customer_service_team_code,
  P2.ENTITY_CODE,
  P2.TRADING_SEQ_NUM,
  P2.RATE_ACCOUNT,
  P2.AGENT_NUM
FROM policy_output_document POD
  LEFT OUTER JOIN output_document OD
    ON OD.output_document_seq_num = POD.output_document_seq_num
  LEFT OUTER JOIN output_document_type_code ODTC
    ON ODTC.code = OD.output_document_type_code
  LEFT OUTER JOIN POLICY P
    ON P.POLICY_NUM = POD.policy_num
  LEFT OUTER JOIN SUB_POLICY SP
    ON SP.POLICY_NUM = P.POLICY_NUM
  LEFT OUTER JOIN POLICY P2
    ON P2.POLICY_NUM = P.POLICY_RELATIONSHIP_POLICY_NUM
WHERE OD.image_seq_num = :imageId
```

Translation notes:
- `EagerLoadQuery()` contributes the same five `LEFT OUTER JOIN`s described on SQL-036: `.Fetch(OutputDocument)` (constrained `HasOne`, shared PK), `.ThenFetch(DocumentType)`, `.Fetch(Policy)`, `.ThenFetch(SubmissionPolicies)`, `.ThenFetch(RelationshipPolicy)`.
- `ThenFetch(p => p.SubmissionPolicies)` fetches a collection: without `Distinct()`, the materialized list can contain the same `PolicyOutputDocument` more than once per matching `SUB_POLICY` row.
- `OutputDocument.ImageId` is a plain `Map` to `image_seq_num`, not a `References`; no `image` table is joined.
- `OutputDocumentTypeCode.ImageDocumentTypes` (`HasManyToMany` via `output_doc_image_type_xref`) is lazy and never fetched or filtered, so `output_doc_image_type_xref` is **not** accessed. `ODTC.image_*` columns are selected only as the `References(ImageDocumentType)` FK; `image_document_type_code` is not joined.
- No status predicate is applied; `PolicyOutputDocument.DocumentStatus` is a lazy `References`, so only its FK column is selected and `document_status_code` is not joined.
- `POLICY.OFFICE_CODE` is mapped twice (`Map(OfficeCode)` and `References(Office)`) and is selected once. `Policy` `HasMany` collections other than `SubmissionPolicies` load lazily and are not selected.
- `OutputDocument.PolicyOutputDocument` (`HasOne(...).Cascade.All()`) is the inverse side of the same shared-PK one-to-one; the row is already in the session, so no additional statement is fabricated.
- **Deferred execution:** the method returns the `IQueryable` without materializing it, so the SQL runs when the caller enumerates the result.

## Operations and processes

- [Policy output documents](../operations/policy-output-documents.md)

> **Note:** Statements marked with `**` could not be confirmed; treat
> as unknown until verified.

## Sources
- `Data/SAIF.Data.NHibernate/Repositories/OutputDocuments/PolicyOutputDocumentRepository.cs:58`
