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

# SQL-107: Retrieve Case

This ORM statement performs a read operation on `Case` via `IUnitOfWork.GetRepository<T>()`, executed from `Services/SAIF.Services/Collections/CashReceiptsService.cs (L80, L199)`.

## Classification

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

## Parameters

| Parameter | Direction | Type | Max length | Description |
| --- | --- | --- | --- | --- |
| `cashReceipt.CaseId` | Input | ** | N/A | `x.Id == cashReceipt.CaseId` → column LEGAL_COLLECTION_SEQ_NUM |

## Tables

| Table | Access | Columns used |
| --- | --- | --- |
| [LEGAL_COLLECTION](../database-tables.md#legal_collection) | SELECT | `LEGAL_COLLECTION_SEQ_NUM`, `UPDATE_NUM`, `POLICY_NUM`, `SAIF_CLAIM_NUM`, `RECEIVED_DATE`, `RECORDING_COUNTY_CODE`, `STATE`, `COURT_CASE_NUM`, `CURRENT_BALANCE_AMT`, `UPDATE_USER`, `UPDATE_DATE`, `CREDIT_REP_USER`, `INTEREST_CALC_OPTION_CODE`, `INTEREST_ANNUAL_RATE`, `JUDGMENT_CODE`, `JUDGMENT_YEARS`, `LEGAL_COLLECTION_CODE`, `LEGAL_COLLECTION_STATUS_CODE` |

## LINQ statement

Source: `Services/SAIF.Services/Collections/CashReceiptsService.cs:80`

```csharp
// Services/SAIF.Services/Collections/CashReceiptsService.cs:80-82
                cashReceipt.Case = UnitOfWork.GetRepository<DataModel.Case>()
                   .Query()
                   .SingleOrDefault(x => x.Id == cashReceipt.CaseId);

// Services/SAIF.Services/Collections/CashReceiptsService.cs:199-201
                Case = UnitOfWork.GetRepository<DataModel.Case>()
                   .Query()
                   .SingleOrDefault(x => x.Id == cashReceipt.CaseId)
```

## 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/Collections/CashReceiptsService.cs:80
SELECT
  LC.LEGAL_COLLECTION_SEQ_NUM,
  LC.UPDATE_NUM,
  LC.POLICY_NUM,
  LC.SAIF_CLAIM_NUM,
  LC.RECEIVED_DATE,
  LC.RECORDING_COUNTY_CODE,
  LC.STATE,
  LC.COURT_CASE_NUM,
  LC.CURRENT_BALANCE_AMT,
  LC.UPDATE_USER,
  LC.UPDATE_DATE,
  LC.CREDIT_REP_USER,
  LC.INTEREST_CALC_OPTION_CODE,
  LC.INTEREST_ANNUAL_RATE,
  LC.JUDGMENT_CODE,
  LC.JUDGMENT_YEARS,
  LC.LEGAL_COLLECTION_CODE,
  LC.LEGAL_COLLECTION_STATUS_CODE
FROM LEGAL_COLLECTION LC
WHERE LC.LEGAL_COLLECTION_SEQ_NUM = :CaseId
-- NHibernate expects at most one row

-- Services/SAIF.Services/Collections/CashReceiptsService.cs:199
SELECT
  LC.LEGAL_COLLECTION_SEQ_NUM,
  LC.UPDATE_NUM,
  LC.POLICY_NUM,
  LC.SAIF_CLAIM_NUM,
  LC.RECEIVED_DATE,
  LC.RECORDING_COUNTY_CODE,
  LC.STATE,
  LC.COURT_CASE_NUM,
  LC.CURRENT_BALANCE_AMT,
  LC.UPDATE_USER,
  LC.UPDATE_DATE,
  LC.CREDIT_REP_USER,
  LC.INTEREST_CALC_OPTION_CODE,
  LC.INTEREST_ANNUAL_RATE,
  LC.JUDGMENT_CODE,
  LC.JUDGMENT_YEARS,
  LC.LEGAL_COLLECTION_CODE,
  LC.LEGAL_COLLECTION_STATUS_CODE
FROM LEGAL_COLLECTION LC
WHERE LC.LEGAL_COLLECTION_SEQ_NUM = :CaseId
-- NHibernate expects at most one row
```

Translation notes:
- `cashReceipt.CaseId` -> bind `:CaseId`.
- `Case` has `HasMany` Activities/Debtors/Transactions with cascade (CaseMap.cs); collections load lazily with their own statements and are not part of this SELECT. `References` (`CREDIT_REP_USER`, `INTEREST_CALC_OPTION_CODE`, `INTEREST_ANNUAL_RATE`, `JUDGMENT_CODE`, `JUDGMENT_YEARS`, `LEGAL_COLLECTION_CODE`, `LEGAL_COLLECTION_STATUS_CODE`) contribute FK columns only; none of the referenced tables is joined.

## Operations and processes
- CashReceiptsService.AddTransaction — see [Operations and processes](../operations-processes.md)
- CashReceiptsService.GenerateReport — see [Operations and processes](../operations-processes.md)

## Sources
- `Services/SAIF.Services/Collections/CashReceiptsService.cs (L80, L199)`
