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

# SQL-298: Retrieve SpecialHandlingCode via SaveLegalBill

This statement retrieves a `SpecialHandlingCode` matching a legal bill's special-handling code via NHibernate LINQ, executed from `Services/SAIF.Services/Legal/Bills/BillSaveService.cs (L336)` and materialized with `SingleOrDefault`. It backs `SaveLegalBill`, which resolves the special handling code entity referenced by an incoming legal bill before persisting it.

## Classification

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

## Parameters

| Parameter | Direction | Type | Max length | Description |
| --- | --- | --- | --- | --- |
| `:Code` | Input | string | N/A | `x.Code == bill.SpecialHandling.Code` |

## Tables

| Table | Access | Columns used |
| --- | --- | --- |
| [CL_PAYMENT_SPCL_HANDLING_CODE](../database-tables.md#cl_payment_spcl_handling_code) | SELECT | `CODE`, `CODE_DESCR`, `UPDATE_DATE`, `UPDATE_USER`, `UPDATE_NUM` |

## LINQ statement

Source: `Services/SAIF.Services/Legal/Bills/BillSaveService.cs:334`

```csharp
// Services/SAIF.Services/Legal/Bills/BillSaveService.cs:334-337
legalBill.SpecialHandling = bill.SpecialHandling == null
        ? null
        : _unitOfWork.GetRepository<SpecialHandlingCode>()
                .Query().SingleOrDefault(x => x.Code == bill.SpecialHandling.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
  CPSHC.CODE,
  CPSHC.CODE_DESCR,
  CPSHC.UPDATE_DATE,
  CPSHC.UPDATE_USER,
  CPSHC.UPDATE_NUM
FROM CL_PAYMENT_SPCL_HANDLING_CODE CPSHC
WHERE CPSHC.CODE = :Code
-- NHibernate expects at most one row
```

Translation notes:
- Runs only when `bill.SpecialHandling != null` (C# ternary).
- `Single`/`SingleOrDefault` → no row limit; NHibernate throws if more than one row is returned.

## Operations and processes
- BillSaveService.SaveLegalBill — see [Operations and processes](../operations-processes.md)

## Sources
- `Services/SAIF.Services/Legal/Bills/BillSaveService.cs (L336)`
