---
title: "SQL-270: Retrieve PolicyRelationship via GetManualAffiliationPolicies"
summary: Read operation against PolicyRelationship via NHibernate ORM.
status: draft
owner: SAIF Doc Gen
last_reviewed: 2026-09-24
library: SAIF.Services
reference_type: package
---

# SQL-270: Retrieve PolicyRelationship via GetManualAffiliationPolicies

This statement finds manual (PHP-type) policy affiliation relationships for a given policy, both as parent and as member, excluding relationships where the related policy is cancelled ("PC"). It runs via `IUnitOfWork.GetRepository<T>()`, executed from `Services/SAIF.Services/Policies/PolicyAssociation/PolicyAssociationService.cs (L185, L190, L198, L204)`.

## Classification

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

## Parameters

| Parameter | Direction | Type | Max length | Description |
| --- | --- | --- | --- | --- |
| `:policyNumber` | Input | long | N/A | policy number matched against `ParentPolicy.PolicyNumber` or `MemberPolicy.PolicyNumber` depending on the statement |

## Tables

| Table | Access | Columns used |
| --- | --- | --- |
| [POLICY_RELATIONSHIP](../database-tables.md#policy_relationship) | SELECT | `parent_policy_num`, `mbr_policy_num`, `affil_typ_cd` |
| [POLICY](../database-tables.md#policy) | JOIN (alias PP for `ParentPolicy`, MP for `MemberPolicy`) | `POLICY_NUM`, `POLICY_STATUS_CODE` |

## LINQ statement

Source: `Services/SAIF.Services/Policies/PolicyAssociation/PolicyAssociationService.cs:185`

```csharp
// Services/SAIF.Services/Policies/PolicyAssociation/PolicyAssociationService.cs:185-188
var parentPolicies1 = unitOfWork.GetRepository<PolicyRelationship>()
    .Query()
    .Where(x => x.AffiliateTypeCode == "PHP" && x.ParentPolicy.Status.Code != "PC")
    .FirstOrDefault(x => x.ParentPolicy.PolicyNumber == policyNumber);

// Services/SAIF.Services/Policies/PolicyAssociation/PolicyAssociationService.cs:190-195
var parentPolicies2 = unitOfWork.GetRepository<PolicyRelationship>()
    .Query()
    .Where(x => x.ParentPolicy.PolicyNumber == policyNumber
        && x.AffiliateTypeCode == "PHP"
        && x.MemberPolicy.Status.Code != "PC" && x.ParentPolicy.Status.Code != "PC")
  .ToList();

// Services/SAIF.Services/Policies/PolicyAssociation/PolicyAssociationService.cs:198-201
var memberPolices1 = unitOfWork.GetRepository<PolicyRelationship>()
    .Query()
    .Where(x => x.MemberPolicy.PolicyNumber == policyNumber && x.AffiliateTypeCode == "PHP" && x.MemberPolicy.Status.Code != "PC" && x.ParentPolicy.Status.Code != "PC")
  .ToList();

// Services/SAIF.Services/Policies/PolicyAssociation/PolicyAssociationService.cs:204-207
var memberPolicies2 = unitOfWork.GetRepository<PolicyRelationship>()
    .Query()
    .Where(x => x.MemberPolicy.PolicyNumber == policyNumber && x.AffiliateTypeCode == "PHP" && x.MemberPolicy.Status.Code != "PC")
   .ToList();
```

## 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
-- parentPolicies1 (L185)
SELECT *
FROM (
  SELECT
    PR.parent_policy_num,
    PR.mbr_policy_num,
    PR.affil_typ_cd
  FROM POLICY_RELATIONSHIP PR
    INNER JOIN POLICY PP
      ON PP.POLICY_NUM = PR.parent_policy_num
  WHERE PR.affil_typ_cd = 'PHP'
    AND PP.POLICY_STATUS_CODE <> 'PC'
    AND PR.parent_policy_num = :policyNumber
)
WHERE ROWNUM <= 1

-- parentPolicies2 (L190)
SELECT
  PR.parent_policy_num,
  PR.mbr_policy_num,
  PR.affil_typ_cd
FROM POLICY_RELATIONSHIP PR
  INNER JOIN POLICY MP
    ON MP.POLICY_NUM = PR.mbr_policy_num
  INNER JOIN POLICY PP
    ON PP.POLICY_NUM = PR.parent_policy_num
WHERE PR.parent_policy_num = :policyNumber
  AND PR.affil_typ_cd = 'PHP'
  AND MP.POLICY_STATUS_CODE <> 'PC'
  AND PP.POLICY_STATUS_CODE <> 'PC'

-- memberPolices1 (L198)
SELECT
  PR.parent_policy_num,
  PR.mbr_policy_num,
  PR.affil_typ_cd
FROM POLICY_RELATIONSHIP PR
  INNER JOIN POLICY MP
    ON MP.POLICY_NUM = PR.mbr_policy_num
  INNER JOIN POLICY PP
    ON PP.POLICY_NUM = PR.parent_policy_num
WHERE PR.mbr_policy_num = :policyNumber
  AND PR.affil_typ_cd = 'PHP'
  AND MP.POLICY_STATUS_CODE <> 'PC'
  AND PP.POLICY_STATUS_CODE <> 'PC'

-- memberPolicies2 (L204)
SELECT
  PR.parent_policy_num,
  PR.mbr_policy_num,
  PR.affil_typ_cd
FROM POLICY_RELATIONSHIP PR
  INNER JOIN POLICY MP
    ON MP.POLICY_NUM = PR.mbr_policy_num
WHERE PR.mbr_policy_num = :policyNumber
  AND PR.affil_typ_cd = 'PHP'
  AND MP.POLICY_STATUS_CODE <> 'PC'
```

Translation notes:
- Four statements under one SQL ID (L185 `FirstOrDefault`; L190/L198/L204 `ToList`). `First`/`FirstOrDefault` → Oracle10 dialect row limit `SELECT * FROM (...) WHERE ROWNUM <= 1` (no `ORDER BY`, so the row returned is not deterministic if more than one matches).
- Join order and whether NHibernate uses `INNER JOIN` or theta-style joins for the implicit navigation is inferred.

## Operations and processes
- PolicyAssociationService.GetManualAffiliationPolicies — see [Operations and processes](../operations-processes.md)

## Sources
- `Services/SAIF.Services/Policies/PolicyAssociation/PolicyAssociationService.cs (L185, L190, L198, L204)`
