---
title: "SQL-003: Oracle sequence-based ID generation for ImageAffiliation"
summary: Fetches the next value of the image_affiliation_seq Oracle sequence for a new ImageAffiliation entity.
status: draft
owner: Framework
last_reviewed: 2026-09-15
library: SAIF.Framework.Data.NHibernate
reference_type: package
---

# SQL-003: Oracle sequence-based ID generation for ImageAffiliation

This statement is a direct SQL escape hatch used by `ImageRepositoryExtensions.GetNextImageAffiliationId` to obtain the next `long` value of the `image_affiliation_seq` Oracle sequence. Unlike [SQL-001](SQL-001-saif-framework-data-nhibernate.md) and [SQL-002](SQL-002-saif-framework-data-nhibernate.md), the `ImageAffiliation` entity's `IMAGE_AFFILIATION_SEQ_NUM` identity column *also* has a native NHibernate sequence generator (`GeneratedBy.Native("IMAGE_AFFILIATION_SEQ")`), making this statement a parallel/redundant ID-acquisition path to the mapping's own generator rather than the entity's only path to an ID.*

## Classification

| Field | Value |
| --- | --- |
| **SQL ID** | SQL-003 |
| **Operation type** | Sequence |
| **Execution method** | Inline SQL (`ISessionStrategy.CreateSqlQuery`) |
| **Database** | Oracle |
| **Schema** | `[unqualified]**` |
| **Command type** | Text |
| **Business object** | `ImageAffiliation` (via `IRepository<ImageAffiliation>` extension) |
| **Criteria property** | N/A — no `IBusinessCriteria` exists in this library |
| **Lifecycle method** | `ImageRepositoryExtensions.GetNextImageAffiliationId` |

## Parameters

No parameters — this is a literal, parameterless sequence-name query with no bind variables.

## Tables

| Table | Access | Columns used |
| --- | --- | --- |
| [IMAGE_AFFILIATION](../database-tables.md#image_affiliation) | SELECT (sequence value only; no table row read) | — (`image_affiliation_seq.nextval`, no column reference) |

## Sample SQL

```sql
select image_affiliation_seq.nextval
from dual
```

## Operations and processes
- [Oracle sequence based ID generation (Imaging domain)](../operations-processes.md#oracle-sequence-based-id-generation-imaging-domain)

## Business rules
No business rule governs this statement directly — the sequence read is unconditional. The generated value's use is governed by [BR-005](../business-rules.md#br-005-repository-is-scoped-to-one-unit-of-work) once the caller assigns it to a new `ImageAffiliation` and calls `Add()`.

> **Note:** Statements marked with `*` were inferred from code structure, naming
> conventions, or contextual evidence where direct confirmation was not available
> in source artifacts. Statements marked with `**` could not be confirmed; treat
> as unknown until verified.

## Sources
- `Repositories/Imaging/ImageRepositoryExtensions.cs`
- `Mappings/Imaging/ImageAffiliationMap.cs`
