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

# SQL-151: Retrieve Debtor

This ORM statement performs a read operation on `Debtor` via `IUnitOfWork.GetRepository<T>()`, executed from `Services/SAIF.Services/Collections/CollectionsService.cs (L306, L313, L333, L1574)`.

## Classification

| Field | Value |
| --- | --- |
| **SQL ID** | SQL-151 |
| **Operation type** | Read |
| **Execution method** | ORM (NHibernate LINQ) |
| **Database** | Oracle |
| **Schema** | [unqualified]** |
| **Command type** | N/A (ORM-generated) |
| **Business object** | `Debtor` |
| **Criteria property** | N/A — ORM |
| **Lifecycle method** | `GetDebtorData, GetDebtorDataList, GetDebtors, GetTransactions` |

## Parameters

| Parameter | Direction | Type | Max length | Description |
| --- | --- | --- | --- | --- |
| `caseId` | Input | ** | N/A | `x.Case.Id == caseId` → column join via `Case` (LEGAL_COLLECTION_SEQ_NUM) → `Case.Id` |
| `id` | Input | ** | N/A | `x.Id == id` → column LEGAL_COLL_DEBTOR_SEQ_NUM |

## Tables

| Table | Access | Columns used |
| --- | --- | --- |
| [LEGAL_COLLECTION_DEBTOR](../database-tables.md#legal_collection_debtor) | SELECT | `LEGAL_COLL_DEBTOR_SEQ_NUM`, `UPDATE_NUM`, `HOLD_STATEMENT_FLAG`, `LAST_STATEMENT_DATE`, `INCLUDE_ON_SOIL_FLAG`, `SOIL_EFF_DATE`, `SOIL_EXP_DATE`, `DEBTOR_SSN`, `AFFILIATE_ID`, `LOC_SEQ_NUM`, `WORKER_ID`, `THIRD_PARTY_SEQ_NUM`, `UPDATE_USER`, `UPDATE_DATE`, `BUSINESS_AFFILIATE_FLAG`, `LAST_STATEMENT_BALANCE_AMT`, `LAST_NAME`, `FIRST_NAME`, `MIDDLE_INITIAL`, `SUFFIX`, `CORPORATION_NAME`, `LEGAL_COLLECTION_SEQ_NUM` |

## LINQ statement

Source: `Services/SAIF.Services/Collections/CollectionsService.cs:306`

```csharp
// Services/SAIF.Services/Collections/CollectionsService.cs:306
            var debtors = UnitOfWork.GetRepository<DataModel.Debtor>().Query().Where(x => x.Case.Id == caseId).ToList();

// Services/SAIF.Services/Collections/CollectionsService.cs:313
            var debtor = UnitOfWork.GetRepository<DataModel.Debtor>().Query().SingleOrDefault(x => x.Id == id);

// Services/SAIF.Services/Collections/CollectionsService.cs:333-334
            var debtors = UnitOfWork.GetRepository<DataModel.Debtor>().Query()
                .Where(x => x.Case.Id == caseId);

// Services/SAIF.Services/Collections/CollectionsService.cs:336
            var model = Mapper.Map<Debtor[]>(debtors);

// Services/SAIF.Services/Collections/CollectionsService.cs:1574-1575
            var maxStatementDate = UnitOfWork.GetRepository<DataModel.Debtor>().Query()
                .Where(x => x.Case.Id == caseId).Max(x => x.LastStatementDate);
```

## 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/CollectionsService.cs:306
SELECT
  LCD.LEGAL_COLL_DEBTOR_SEQ_NUM,
  LCD.UPDATE_NUM,
  LCD.HOLD_STATEMENT_FLAG,
  LCD.LAST_STATEMENT_DATE,
  LCD.INCLUDE_ON_SOIL_FLAG,
  LCD.SOIL_EFF_DATE,
  LCD.SOIL_EXP_DATE,
  LCD.DEBTOR_SSN,
  LCD.AFFILIATE_ID,
  LCD.LOC_SEQ_NUM,
  LCD.WORKER_ID,
  LCD.THIRD_PARTY_SEQ_NUM,
  LCD.UPDATE_USER,
  LCD.UPDATE_DATE,
  LCD.BUSINESS_AFFILIATE_FLAG,
  LCD.LAST_STATEMENT_BALANCE_AMT,
  LCD.LAST_NAME,
  LCD.FIRST_NAME,
  LCD.MIDDLE_INITIAL,
  LCD.SUFFIX,
  LCD.CORPORATION_NAME,
  LCD.LEGAL_COLLECTION_SEQ_NUM
FROM LEGAL_COLLECTION_DEBTOR LCD
WHERE LCD.LEGAL_COLLECTION_SEQ_NUM = :caseId

-- Services/SAIF.Services/Collections/CollectionsService.cs:313
SELECT
  LCD.LEGAL_COLL_DEBTOR_SEQ_NUM,
  LCD.UPDATE_NUM,
  LCD.HOLD_STATEMENT_FLAG,
  LCD.LAST_STATEMENT_DATE,
  LCD.INCLUDE_ON_SOIL_FLAG,
  LCD.SOIL_EFF_DATE,
  LCD.SOIL_EXP_DATE,
  LCD.DEBTOR_SSN,
  LCD.AFFILIATE_ID,
  LCD.LOC_SEQ_NUM,
  LCD.WORKER_ID,
  LCD.THIRD_PARTY_SEQ_NUM,
  LCD.UPDATE_USER,
  LCD.UPDATE_DATE,
  LCD.BUSINESS_AFFILIATE_FLAG,
  LCD.LAST_STATEMENT_BALANCE_AMT,
  LCD.LAST_NAME,
  LCD.FIRST_NAME,
  LCD.MIDDLE_INITIAL,
  LCD.SUFFIX,
  LCD.CORPORATION_NAME,
  LCD.LEGAL_COLLECTION_SEQ_NUM
FROM LEGAL_COLLECTION_DEBTOR LCD
WHERE LCD.LEGAL_COLL_DEBTOR_SEQ_NUM = :id
-- NHibernate expects at most one row

-- Services/SAIF.Services/Collections/CollectionsService.cs:333
SELECT
  LCD.LEGAL_COLL_DEBTOR_SEQ_NUM,
  LCD.UPDATE_NUM,
  LCD.HOLD_STATEMENT_FLAG,
  LCD.LAST_STATEMENT_DATE,
  LCD.INCLUDE_ON_SOIL_FLAG,
  LCD.SOIL_EFF_DATE,
  LCD.SOIL_EXP_DATE,
  LCD.DEBTOR_SSN,
  LCD.AFFILIATE_ID,
  LCD.LOC_SEQ_NUM,
  LCD.WORKER_ID,
  LCD.THIRD_PARTY_SEQ_NUM,
  LCD.UPDATE_USER,
  LCD.UPDATE_DATE,
  LCD.BUSINESS_AFFILIATE_FLAG,
  LCD.LAST_STATEMENT_BALANCE_AMT,
  LCD.LAST_NAME,
  LCD.FIRST_NAME,
  LCD.MIDDLE_INITIAL,
  LCD.SUFFIX,
  LCD.CORPORATION_NAME,
  LCD.LEGAL_COLLECTION_SEQ_NUM
FROM LEGAL_COLLECTION_DEBTOR LCD
WHERE LCD.LEGAL_COLLECTION_SEQ_NUM = :caseId

-- Services/SAIF.Services/Collections/CollectionsService.cs:1574
SELECT MAX(LCD.LAST_STATEMENT_DATE)
FROM LEGAL_COLLECTION_DEBTOR LCD
WHERE LCD.LEGAL_COLLECTION_SEQ_NUM = :caseId
```

Translation notes:
- L333-334 is materialized by `Mapper.Map` (L336); `GetAdditionalDebtorData` (L337) runs per element in memory.

## Operations and processes
- CollectionsService.GetDebtorData — see [Operations and processes](../operations-processes.md)
- CollectionsService.GetDebtorDataList — see [Operations and processes](../operations-processes.md)
- CollectionsService.GetDebtors — see [Operations and processes](../operations-processes.md)
- CollectionsService.GetTransactions — see [Operations and processes](../operations-processes.md)

## Sources
- `Services/SAIF.Services/Collections/CollectionsService.cs (L306, L313, L333, L1574)`
