﻿---
title: "InvestigationRepositoryExtensions"
summary: API reference for InvestigationRepositoryExtensions
status: draft
owner: SAIF.Core documentation team
last_reviewed: 2026-09-24
library: SAIF.Data.NHibernate
reference_type: package
---


# InvestigationRepositoryExtensions

`InvestigationRepositoryExtensions` is a static class of extension methods on `IRepository<Investigation>` that run raw, hand-written Oracle SQL (via `CreateSqlQuery`) instead of NHibernate mappings, because — per an inline code comment in the source — "using nhibernate named queries with mappings wasn't working" for this join. Both methods cast the `IRepository<Investigation>` receiver to the concrete `Repository<Investigation>` to reach its `Session` property, meaning they only work when the runtime type behind the interface is actually `Repository<Investigation>`.

## Purpose
- Resolve the display name of an investigation's subject (worker, company, or provider-location business name, with `nvl` fallbacks) and the associated worker id and policy name, per [SDN-BR-050](../../business-rules.md#sdn-br-050-investigation-subject-name-resolves-via-person%2C-company-or-provider-location%2C-with-nvl-fallbacks).
- Resolve the claim id associated with an investigation case number.

## Context
- Namespace: `SAIF.Data.NHibernate.Repositories.Investigations`
- Assembly/package: `SAIF.Data.NHibernate` (ships inside the `SAIF.SAIFCode.Core` NuGet package)
- Static class; extension methods target `IRepository<Investigation>` (external interface, `SAIF.Framework.Data.NHibernate`) and internally cast to `Repository<Investigation>` (external, same library) to access `Session`.

## Public members
| Member | Signature | Purpose |
| --- | --- | --- |
| GetSubjectName | `public static GetSubjectNameData GetSubjectName(this IRepository<Investigation> repo, long caseNumber)` | Casts `repo` to `Repository<Investigation>`, runs an inline SQL `SELECT` joining `investigation`, `subject`, `person`, `company`, `provider_location`, and `policy` for the given `caseNumber`, and resolves the worker/subject display name using `nvl(person.NAME, nvl(company_name, nvl(business_name, '')))`. Returns `null` if no row matches; otherwise returns a `GetSubjectNameData` with `LegacyDataWorkerName`, `WorkerId` (nullable, converted from `decimal`), and `PolicyName` ([SDN-BR-050](../../business-rules.md#sdn-br-050-investigation-subject-name-resolves-via-person%2C-company-or-provider-location%2C-with-nvl-fallbacks), [SQL-032](../../sql/SQL-032-investigation-repository-extensions-get-subject-name.md)). |
| GetClaimId | `public static long GetClaimId(this IRepository<Investigation> repo, long caseNumber)` | Casts `repo` to `Repository<Investigation>`, runs an inline SQL `SELECT inv.claim_id FROM investigation inv WHERE investigation_seq_num = :investigationId`, and returns the claim id converted to `long` via `Convert.ToInt64` ([SQL-033](../../sql/SQL-033-investigation-repository-extensions-get-claim-id.md)). |

## Behavioral notes
- Both methods bind their SQL parameter (`:investigationId`) explicitly via `SetParameter<long>`, so caller-supplied case numbers cannot be used for SQL injection (SC-SDN-05, [Security and authorization](../../security-authorization.md)).
- `GetSubjectName` reads the raw ADO result as an untyped `Array` (`(Array)result`) and indexes into it positionally (`GetValue(0)`, `GetValue(1)`, `GetValue(2)`); any change to the column order in the inline SQL would silently break the mapping without a compile-time error*.
- `GetClaimId` will throw an unhandled `InvalidCastException`/`FormatException` from `Convert.ToInt64` if no investigation matches `caseNumber` (i.e. `UniqueResult()` returns `null`), since `Convert.ToInt64(null)` returns `0` rather than throwing — callers should verify this edge case before relying on a non-zero result as "found"*.

## Constraints and usage notes
- Both extension methods require the `IRepository<Investigation>` instance to actually be a `Repository<Investigation>` at runtime; passing any other `IRepository<Investigation>` implementation will throw an `InvalidCastException`*.

> **Note:** Statements marked with `†` are derived from dependency library
> documentation via the Legends CLI. Statements marked with `*` were inferred
> from code structure or contextual evidence. Statements marked with `**` could
> not be confirmed; treat as unknown until verified.

## Related documentation
- [Index](../../index.md)
- [Overview](../../overview.md)
- [Architecture](../../architecture.md)
- [Dependencies](../../dependencies.md)
- [Operations and processes](../../operations-processes.md)
- [Business rules](../../business-rules.md)
- [Database tables](../../database-tables.md)
- [SQL catalog](../../sql/index.md)
- [Procedures](../../procedures/index.md)
- [Security and authorization](../../security-authorization.md)
- [API reference](../index.md)

## Sources
- `Data/SAIF.Data.NHibernate/Repositories/Investigations/InvestigationRepositoryExtensions.cs`
