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

# SQL-314: Retrieve SubpoenaStatus via SetNewSubpoenaStatus

This statement retrieves the `SUBPOENA_STATUS_CODE` row matching a caller-supplied status code via NHibernate LINQ over `IUnitOfWork.GetRepository<SubpoenaStatus>()`. It is executed by `SubpoenaPaymentService.SetNewSubpoenaStatus` (`Services/SAIF.Services/Legal/Subpoenas/SubpoenaPaymentService.cs (L340)`) to resolve the target status before assigning it to a subpoena.

## Classification

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

## Parameters

| Parameter | Direction | Type | Max length | Description |
| --- | --- | --- | --- | --- |
| `:toCode` | Input | String | N/A | Status code (`toCode`) matched against `CODE` |

## Tables

| Table | Access | Columns used |
| --- | --- | --- |
| [SUBPOENA_STATUS_CODE](../database-tables.md#subpoena_status_code) | SELECT | `CODE`, `CODE_DESCR` |

## LINQ statement

Source: `Services/SAIF.Services/Legal/Subpoenas/SubpoenaPaymentService.cs:340`

```csharp
// Services/SAIF.Services/Legal/Subpoenas/SubpoenaPaymentService.cs:340-342
subpoena.SubpoenaStatus = _unitOfWork.GetRepository<SubpoenaData.SubpoenaStatus>()
    .Query()
    .SingleOrDefault(x => x.Code == toCode);
```

## 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
  SSC.CODE,
  SSC.CODE_DESCR
FROM SUBPOENA_STATUS_CODE SSC
WHERE SSC.CODE = :toCode
-- NHibernate expects at most one row
```

Translation notes:
- `Single`/`SingleOrDefault` → no row limit; NHibernate throws if more than one row is returned.

## Operations and processes
- SubpoenaPaymentService.SetNewSubpoenaStatus — see [Operations and processes](../operations-processes.md)

## Sources
- `Services/SAIF.Services/Legal/Subpoenas/SubpoenaPaymentService.cs (L340)`
