---
title: "SQL-197: Retrieve FileRequest via LoadTaskMailIDList"
summary: Read operation against FileRequest via NHibernate ORM.
status: draft
owner: SAIF Doc Gen
last_reviewed: 2026-09-25
library: SAIF.Services
reference_type: package
---

# SQL-197: Retrieve FileRequest via LoadTaskMailIDList

This statement retrieves the most recent `FileRequest` for a paper file matching a given policy number, joined to `PaperFile` to filter by policy number. It is called from `AutoImportHelperService.LoadTaskMailIDList`.

## Classification

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

## Parameters

| Parameter | Direction | Type | Max length | Description |
| --- | --- | --- | --- | --- |
| `:policyNumber` | Input | String | N/A | `_policyDetail.PolicyNumber`, captured — filters `PAPER_FILE.POLICY_NUM` |

## Tables

| Table | Access | Columns used |
| --- | --- | --- |
| [FILE_REQUEST](../database-tables.md#file_request) | SELECT | all mapped columns; order `CREATE_DATE` |
| PAPER_FILE | JOIN | `PAPER_FILE_SEQ_NUM` (join), `POLICY_NUM` (filter) |

## LINQ statement

Source: `Services/SAIF.Services/Imaging/AutoImportHelperService.cs:221`

```csharp
var fileRequest = _unitOfWork
    .GetRepository<FileRequest>()
    .Query().OrderByDescending(f => f.CreateDate)
    .FirstOrDefault(x => x.PaperFile.PolicyNumber == _policyDetail.PolicyNumber);
```

## 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 * FROM (
    SELECT FR.FILE_REQUEST_SEQ_NUM,
       FR.TASK_RECIPIENT_MAIL_ID,
       FR.SPECIAL_INSTRUCTIONS,
       FR.CREATE_DATE,
       FR.CREATE_USER,
       FR.PAPER_FILE_SEQ_NUM
    FROM   FILE_REQUEST FR
    INNER JOIN PAPER_FILE PF ON PF.PAPER_FILE_SEQ_NUM = FR.PAPER_FILE_SEQ_NUM
    WHERE  PF.POLICY_NUM = :policyNumber
    ORDER BY FR.CREATE_DATE DESC
) WHERE ROWNUM <= 1;
```

Translation notes:
- `OrderByDescending(...).FirstOrDefault(predicate)` translates the predicate to `WHERE`, then wraps with the Oracle10 `ROWNUM <= 1` limit.
- `x.PaperFile.PolicyNumber` is a non-identifier property → `INNER JOIN PAPER_FILE`.

## Operations and processes
- AutoImportHelperService.LoadTaskMailIDList — see [Operations and processes](../operations-processes.md)

## Sources
- `Services/SAIF.Services/Imaging/AutoImportHelperService.cs (L222)`
