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

# SQL-156: Retrieve DocumentDistributionLogRequest

This ORM statement performs a read operation on `DocumentDistributionLogRequest` via `IUnitOfWork.GetRepository<T>()`, executed from `Services/SAIF.Services/Documents/DocumentRequestService.cs (L230, L236, L312, L383, L412)`.

## Classification

| Field | Value |
| --- | --- |
| **SQL ID** | SQL-156 |
| **Operation type** | Read |
| **Execution method** | ORM (NHibernate LINQ) |
| **Database** | Oracle |
| **Schema** | [unqualified]** |
| **Command type** | N/A (ORM-generated) |
| **Business object** | `DocumentDistributionLogRequest` |
| **Criteria property** | N/A — ORM |
| **Lifecycle method** | `GetDocumentDistributionLogsForRequest, GetPendingDocuments, GetProcessingDocuments, MarkDocumentRequestsInProcess, UpdateDocumentRequestAndDistribution` |

## Parameters

| Parameter | Direction | Type | Max length | Description |
| --- | --- | --- | --- | --- |
| `DocumentRequestLog.PendingRequest` | Input | ** | N/A | `a.RequestForDocument.DocRequestLogStatusCode == DocumentRequestLog.PendingRequest` → column join via `RequestForDocument` (DOCUMENT_REQUEST_LOG_SEQ_NUM) → `RequestForDocument.DocRequestLogStatusCode` |
| `DocumentRequestLog.ProcessingRequest` | Input | ** | N/A | `a.RequestForDocument.DocRequestLogStatusCode == DocumentRequestLog.ProcessingRequest` → column join via `RequestForDocument` (DOCUMENT_REQUEST_LOG_SEQ_NUM) → `RequestForDocument.DocRequestLogStatusCode` |
| `requestNumber` | Input | ** | N/A | `a.RequestForDocument.Id == requestNumber` → column join via `RequestForDocument` (DOCUMENT_REQUEST_LOG_SEQ_NUM) → `RequestForDocument.Id` |
| `endDateToGet` | Input | ** | N/A | `a.PlannedDistributionDate < …` → column PLANNED_DISTRIBUTION_DATE |
| `DocumentRequestLog.PendingRequest` | Input | ** | N/A | `a.DocRequestLogStatusCode == DocumentRequestLog.PendingRequest` → column DOC_REQUEST_LOG_STATUS_CODE |
| `DocumentRequestLog.ProcessingRequest` | Input | ** | N/A | `a.DocRequestLogStatusCode == DocumentRequestLog.ProcessingRequest` → column DOC_REQUEST_LOG_STATUS_CODE |
| `requestId` | Input | ** | N/A | `a.RequestForDocument.Id == requestId` → column join via `RequestForDocument` (DOCUMENT_REQUEST_LOG_SEQ_NUM) → `RequestForDocument.Id` |

## Tables

| Table | Access | Columns used |
| --- | --- | --- |
| [DOCUMENT_DISTRIBUTION_LOG](../database-tables.md#document_distribution_log) | SELECT | `DOCUMENT_DIST_LOG_SEQ_NUM`, `DOC_REQUEST_LOG_STATUS_CODE`, `PLANNED_DISTRIBUTION_DATE`, `ACTUAL_DISTRIBUTION_DATE`, `PACKAGE_NAME`, `XML`, `PRINTER_NAME`, `PRINT_MODE`, `COPIES`, `SCALE_MODE`, `OUTPUT_PROFILE`, `IMPORT_INFO`, `EMAIL_INFO`, `FAX_INFO`, `IMAGE_PATH`, `TRAY`, `DEFERRED_INFO`, `APPLICATION`, `CERTIFICATION_INFO`, `CREATE_USER`, `CREATE_DATE`, `UPDATE_USER`, `UPDATE_DATE`, `DOCUMENT_REQUEST_LOG_SEQ_NUM` |
| [DOCUMENT_REQUEST_LOG](../database-tables.md#document_request_log) | JOIN | `DOCUMENT_REQUEST_LOG_SEQ_NUM`, `DOC_REQUEST_LOG_STATUS_CODE` |

## LINQ statement

Source: `Services/SAIF.Services/Documents/DocumentRequestService.cs:230`

```csharp
// Services/SAIF.Services/Documents/DocumentRequestService.cs:230-232
            var items = UnitOfWork.GetRepository<DocumentDistributionLogRequest>().Query()
                .Where(a => a.RequestForDocument.DocRequestLogStatusCode == DocumentRequestLog.PendingRequest);
            return Mapper.Map<Contract.DocumentDistributionLog[]>(items);

// Services/SAIF.Services/Documents/DocumentRequestService.cs:236-238
            var items = UnitOfWork.GetRepository<DocumentDistributionLogRequest>().Query()
                .Where(a => a.RequestForDocument.DocRequestLogStatusCode == DocumentRequestLog.ProcessingRequest);
            return Mapper.Map<Contract.DocumentDistributionLog[]>(items);

// Services/SAIF.Services/Documents/DocumentRequestService.cs:312
            var items = UnitOfWork.GetRepository<DocumentDistributionLogRequest>().Query().Where(a => a.RequestForDocument.Id == requestNumber).ToList();

// Services/SAIF.Services/Documents/DocumentRequestService.cs:383-392
            var distributionRequests = UnitOfWork.GetRepository<DocumentDistributionLogRequest>().Query()
                .Where(a => a.PlannedDistributionDate < endDateToGet
                && (a.DocRequestLogStatusCode == a.RequestForDocument.DocRequestLogStatusCode)
                && (a.DocRequestLogStatusCode == DocumentRequestLog.PendingRequest || a.DocRequestLogStatusCode == DocumentRequestLog.ProcessingRequest)
                && (a.OutputProfile.ToUpperInvariant() != "WORD")
                && (specificRequestId == null || specificRequestId == "" || a.RequestForDocument.Id == requestId)
                && (a.ActualDistributionDate == DateTime.MinValue || a.ActualDistributionDate == null)
                )
                .OrderBy(a => a.RequestForDocument.Id).ThenBy(a => a.Id);
            foreach (var distribution in distributionRequests)

// Services/SAIF.Services/Documents/DocumentRequestService.cs:412-416
            var distributionRequests = UnitOfWork.GetRepository<DocumentDistributionLogRequest>().Query()
                .Where(a => a.RequestForDocument.Id == requestId)
                .OrderBy(a => a.RequestForDocument.Id).ThenBy(a => a.Id);

            foreach (var distribution in distributionRequests)
```

## 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/Documents/DocumentRequestService.cs:230
SELECT
  DDL.DOCUMENT_DIST_LOG_SEQ_NUM,
  DDL.DOC_REQUEST_LOG_STATUS_CODE,
  DDL.PLANNED_DISTRIBUTION_DATE,
  DDL.ACTUAL_DISTRIBUTION_DATE,
  DDL.PACKAGE_NAME,
  DDL.XML,
  DDL.PRINTER_NAME,
  DDL.PRINT_MODE,
  DDL.COPIES,
  DDL.SCALE_MODE,
  DDL.OUTPUT_PROFILE,
  DDL.IMPORT_INFO,
  DDL.EMAIL_INFO,
  DDL.FAX_INFO,
  DDL.IMAGE_PATH,
  DDL.TRAY,
  DDL.DEFERRED_INFO,
  DDL.APPLICATION,
  DDL.CERTIFICATION_INFO,
  DDL.CREATE_USER,
  DDL.CREATE_DATE,
  DDL.UPDATE_USER,
  DDL.UPDATE_DATE,
  DDL.DOCUMENT_REQUEST_LOG_SEQ_NUM
FROM DOCUMENT_DISTRIBUTION_LOG DDL
  INNER JOIN DOCUMENT_REQUEST_LOG DRL
    ON DRL.DOCUMENT_REQUEST_LOG_SEQ_NUM = DDL.DOCUMENT_REQUEST_LOG_SEQ_NUM
WHERE DRL.DOC_REQUEST_LOG_STATUS_CODE = 'PEND'

-- Services/SAIF.Services/Documents/DocumentRequestService.cs:236
SELECT
  DDL.DOCUMENT_DIST_LOG_SEQ_NUM,
  DDL.DOC_REQUEST_LOG_STATUS_CODE,
  DDL.PLANNED_DISTRIBUTION_DATE,
  DDL.ACTUAL_DISTRIBUTION_DATE,
  DDL.PACKAGE_NAME,
  DDL.XML,
  DDL.PRINTER_NAME,
  DDL.PRINT_MODE,
  DDL.COPIES,
  DDL.SCALE_MODE,
  DDL.OUTPUT_PROFILE,
  DDL.IMPORT_INFO,
  DDL.EMAIL_INFO,
  DDL.FAX_INFO,
  DDL.IMAGE_PATH,
  DDL.TRAY,
  DDL.DEFERRED_INFO,
  DDL.APPLICATION,
  DDL.CERTIFICATION_INFO,
  DDL.CREATE_USER,
  DDL.CREATE_DATE,
  DDL.UPDATE_USER,
  DDL.UPDATE_DATE,
  DDL.DOCUMENT_REQUEST_LOG_SEQ_NUM
FROM DOCUMENT_DISTRIBUTION_LOG DDL
  INNER JOIN DOCUMENT_REQUEST_LOG DRL
    ON DRL.DOCUMENT_REQUEST_LOG_SEQ_NUM = DDL.DOCUMENT_REQUEST_LOG_SEQ_NUM
WHERE DRL.DOC_REQUEST_LOG_STATUS_CODE = 'PROC'

-- Services/SAIF.Services/Documents/DocumentRequestService.cs:312
SELECT
  DDL.DOCUMENT_DIST_LOG_SEQ_NUM,
  DDL.DOC_REQUEST_LOG_STATUS_CODE,
  DDL.PLANNED_DISTRIBUTION_DATE,
  DDL.ACTUAL_DISTRIBUTION_DATE,
  DDL.PACKAGE_NAME,
  DDL.XML,
  DDL.PRINTER_NAME,
  DDL.PRINT_MODE,
  DDL.COPIES,
  DDL.SCALE_MODE,
  DDL.OUTPUT_PROFILE,
  DDL.IMPORT_INFO,
  DDL.EMAIL_INFO,
  DDL.FAX_INFO,
  DDL.IMAGE_PATH,
  DDL.TRAY,
  DDL.DEFERRED_INFO,
  DDL.APPLICATION,
  DDL.CERTIFICATION_INFO,
  DDL.CREATE_USER,
  DDL.CREATE_DATE,
  DDL.UPDATE_USER,
  DDL.UPDATE_DATE,
  DDL.DOCUMENT_REQUEST_LOG_SEQ_NUM
FROM DOCUMENT_DISTRIBUTION_LOG DDL
WHERE DDL.DOCUMENT_REQUEST_LOG_SEQ_NUM = :requestNumber

-- Services/SAIF.Services/Documents/DocumentRequestService.cs:383
SELECT
  DDL.DOCUMENT_DIST_LOG_SEQ_NUM,
  DDL.DOC_REQUEST_LOG_STATUS_CODE,
  DDL.PLANNED_DISTRIBUTION_DATE,
  DDL.ACTUAL_DISTRIBUTION_DATE,
  DDL.PACKAGE_NAME,
  DDL.XML,
  DDL.PRINTER_NAME,
  DDL.PRINT_MODE,
  DDL.COPIES,
  DDL.SCALE_MODE,
  DDL.OUTPUT_PROFILE,
  DDL.IMPORT_INFO,
  DDL.EMAIL_INFO,
  DDL.FAX_INFO,
  DDL.IMAGE_PATH,
  DDL.TRAY,
  DDL.DEFERRED_INFO,
  DDL.APPLICATION,
  DDL.CERTIFICATION_INFO,
  DDL.CREATE_USER,
  DDL.CREATE_DATE,
  DDL.UPDATE_USER,
  DDL.UPDATE_DATE,
  DDL.DOCUMENT_REQUEST_LOG_SEQ_NUM
FROM DOCUMENT_DISTRIBUTION_LOG DDL
  INNER JOIN DOCUMENT_REQUEST_LOG DRL
    ON DRL.DOCUMENT_REQUEST_LOG_SEQ_NUM = DDL.DOCUMENT_REQUEST_LOG_SEQ_NUM
WHERE DDL.PLANNED_DISTRIBUTION_DATE < :endDateToGet
  AND (DDL.DOC_REQUEST_LOG_STATUS_CODE = DRL.DOC_REQUEST_LOG_STATUS_CODE)
  AND (DDL.DOC_REQUEST_LOG_STATUS_CODE = 'PEND' OR DDL.DOC_REQUEST_LOG_STATUS_CODE = 'PROC')
  AND (UPPER(DDL.OUTPUT_PROFILE) <> 'WORD')
  AND (:specificRequestId IS NULL OR :specificRequestId = '' OR DDL.DOCUMENT_REQUEST_LOG_SEQ_NUM = :requestId)
  AND (DDL.ACTUAL_DISTRIBUTION_DATE = :DateTimeMinValue OR DDL.ACTUAL_DISTRIBUTION_DATE IS NULL)
ORDER BY DDL.DOCUMENT_REQUEST_LOG_SEQ_NUM, DDL.DOCUMENT_DIST_LOG_SEQ_NUM

-- Services/SAIF.Services/Documents/DocumentRequestService.cs:412
SELECT
  DDL.DOCUMENT_DIST_LOG_SEQ_NUM,
  DDL.DOC_REQUEST_LOG_STATUS_CODE,
  DDL.PLANNED_DISTRIBUTION_DATE,
  DDL.ACTUAL_DISTRIBUTION_DATE,
  DDL.PACKAGE_NAME,
  DDL.XML,
  DDL.PRINTER_NAME,
  DDL.PRINT_MODE,
  DDL.COPIES,
  DDL.SCALE_MODE,
  DDL.OUTPUT_PROFILE,
  DDL.IMPORT_INFO,
  DDL.EMAIL_INFO,
  DDL.FAX_INFO,
  DDL.IMAGE_PATH,
  DDL.TRAY,
  DDL.DEFERRED_INFO,
  DDL.APPLICATION,
  DDL.CERTIFICATION_INFO,
  DDL.CREATE_USER,
  DDL.CREATE_DATE,
  DDL.UPDATE_USER,
  DDL.UPDATE_DATE,
  DDL.DOCUMENT_REQUEST_LOG_SEQ_NUM
FROM DOCUMENT_DISTRIBUTION_LOG DDL
WHERE DDL.DOCUMENT_REQUEST_LOG_SEQ_NUM = :requestId
ORDER BY DDL.DOCUMENT_REQUEST_LOG_SEQ_NUM, DDL.DOCUMENT_DIST_LOG_SEQ_NUM
```

Translation notes:
- `RequestForDocument` = `References(...).Column("DOCUMENT_REQUEST_LOG_SEQ_NUM")` (DocumentDistributionLogRequestMap.cs:41) -> DOCUMENT_REQUEST_LOG (DocumentRequestLogMap.cs:10). Constants `PendingRequest` = `"PEND"`, `ProcessingRequest` = `"PROC"` (Data/SAIF.Data/Model/Documents/DocumentRequestLog.cs:26,28).
- L230/L236 are materialized by `Mapper.Map` (L232/L238); L383-391 and L412-414 by `foreach` (L392/L416).
- L387 `a.OutputProfile.ToUpperInvariant()` -> `UPPER(...)`; NHibernate LINQ support for `ToUpperInvariant` is version-dependent (older providers throw `NotSupportedException`).
- L388 `specificRequestId == null || specificRequestId == ""` references only a method argument -> pre-evaluated client-side to a constant; rendered as parameter tests to show intent. `requestId` is a local parsed at L381.
- L389 `DateTime.MinValue` is evaluated client-side -> bind `:DateTimeMinValue`.

## Operations and processes
- DocumentRequestService.GetDocumentDistributionLogsForRequest — see [Operations and processes](../operations-processes.md)
- DocumentRequestService.GetPendingDocuments — see [Operations and processes](../operations-processes.md)
- DocumentRequestService.GetProcessingDocuments — see [Operations and processes](../operations-processes.md)
- DocumentRequestService.MarkDocumentRequestsInProcess — see [Operations and processes](../operations-processes.md)
- DocumentRequestService.UpdateDocumentRequestAndDistribution — see [Operations and processes](../operations-processes.md)

## Sources
- `Services/SAIF.Services/Documents/DocumentRequestService.cs (L230, L236, L312, L383, L412)`
