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

# SQL-121: Retrieve CbpBillStatusCode

This ORM statement performs a read operation on `CbpBillStatusCode` via `IUnitOfWork.GetRepository<T>()`, executed from `Services/SAIF.Services/Claims/Bills/BillEntryService.cs (L348, L374, L380)`.

## Classification

| Field | Value |
| --- | --- |
| **SQL ID** | SQL-121 |
| **Operation type** | Read |
| **Execution method** | ORM (NHibernate LINQ) |
| **Database** | Oracle |
| **Schema** | [unqualified]** |
| **Command type** | N/A (ORM-generated) |
| **Business object** | `CbpBillStatusCode` |
| **Criteria property** | N/A — ORM |
| **Lifecycle method** | `CreateNewBill, GetBillStatusCodes, UpdateBillStatus` |

## Parameters

| Parameter | Direction | Type | Max length | Description |
| --- | --- | --- | --- | --- |
| `billStatusCode` | Input | ** | N/A | `x.Code == billStatusCode` → column CODE |
| `initialBillStatusCode` | Input | ** | N/A | `x.Code == initialBillStatusCode` → column CODE |

## Tables

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

## LINQ statement

Source: `Services/SAIF.Services/Claims/Bills/BillEntryService.cs:348`

```csharp
// Services/SAIF.Services/Claims/Bills/BillEntryService.cs:348
            var newStatusCode = unitOfWork.GetRepository<CbpBillStatusCode>().Query().SingleOrDefault(x => x.Code == billStatusCode);

// Services/SAIF.Services/Claims/Bills/BillEntryService.cs:374
            return unitOfWork.GetRepository<CbpBillStatusCode>().Query().OrderBy(x => x.Description).ToList();

// Services/SAIF.Services/Claims/Bills/BillEntryService.cs:380
            var initialBillStatus = unitOfWork.GetRepository<CbpBillStatusCode>().Query().SingleOrDefault(x => x.Code == initialBillStatusCode);
```

## 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
-- Services/SAIF.Services/Claims/Bills/BillEntryService.cs:348
SELECT
  CBSC.CODE,
  CBSC.UPDATE_NUM,
  CBSC.CODE_DESCR,
  CBSC.ACTIVE_FLAG,
  CBSC.EXT_IW_CODE_DESCR,
  CBSC.UPDATE_DATE,
  CBSC.UPDATE_USER
FROM CBP_BILL_STATUS_CODE CBSC
WHERE CBSC.CODE = :billStatusCode
-- NHibernate expects at most one row

-- Services/SAIF.Services/Claims/Bills/BillEntryService.cs:374
SELECT
  CBSC.CODE,
  CBSC.UPDATE_NUM,
  CBSC.CODE_DESCR,
  CBSC.ACTIVE_FLAG,
  CBSC.EXT_IW_CODE_DESCR,
  CBSC.UPDATE_DATE,
  CBSC.UPDATE_USER
FROM CBP_BILL_STATUS_CODE CBSC
ORDER BY CBSC.CODE_DESCR

-- Services/SAIF.Services/Claims/Bills/BillEntryService.cs:380
SELECT
  CBSC.CODE,
  CBSC.UPDATE_NUM,
  CBSC.CODE_DESCR,
  CBSC.ACTIVE_FLAG,
  CBSC.EXT_IW_CODE_DESCR,
  CBSC.UPDATE_DATE,
  CBSC.UPDATE_USER
FROM CBP_BILL_STATUS_CODE CBSC
WHERE CBSC.CODE = :initialBillStatusCode
-- NHibernate expects at most one row
```

Translation notes:
- `CODE` is mapped twice in CbpBillStatusCodeMap.cs -> selected once.

## Operations and processes
- BillEntryService.CreateNewBill — see [Operations and processes](../operations-processes.md)
- BillEntryService.GetBillStatusCodes — see [Operations and processes](../operations-processes.md)
- BillEntryService.UpdateBillStatus — see [Operations and processes](../operations-processes.md)

## Business rules
- [SVC-BR-BIL-094](<../business-rules.md#svc-br-bil-094-status-code-must-exist%2C-else-throw-invaliddataexception-%22error%3A-new-bill-status-code-is-invalid%3A-%7Bcode%7D%22%3B-new-status-effective-today%2C-responsible-%3D-recipient.toupper()-or-current-user>)

## Sources
- `Services/SAIF.Services/Claims/Bills/BillEntryService.cs (L348, L374, L380)`
