---
title: ImageRepositoryExtensions
summary: API reference for ImageRepositoryExtensions.
status: draft
owner: Framework
last_reviewed: 2026-09-15
library: SAIF.Framework.Data.NHibernate
reference_type: package
---

# ImageRepositoryExtensions

`ImageRepositoryExtensions` is a static extension-method class providing Oracle sequence-based ID generation for the Imaging domain. It is the library's one confirmed "direct SQL escape hatch" — it bypasses entity mapping entirely by issuing a session-level `CreateSqlQuery` for `NEXTVAL FROM DUAL`, and is Oracle-only (uses Oracle sequence syntax).

## Purpose
- Provides `GetNextImageId`, `GetNextTowId`, and `GetNextImageAffiliationId` extension methods on `IRepository<Image>`, `IRepository<ImageSystem>`, and `IRepository<ImageAffiliation>` respectively, each returning the next value of a dedicated Oracle sequence (`image_seq`, `tower_seq`, `image_affiliation_seq`).
- Implements the [Oracle sequence based ID generation (Imaging domain)](../../operations-processes.md#oracle-sequence-based-id-generation-imaging-domain) operation, cross-referenced from [SQL-001](../../sql/SQL-001-saif-framework-data-nhibernate.md), [SQL-002](../../sql/SQL-002-saif-framework-data-nhibernate.md), and [SQL-003](../../sql/SQL-003-saif-framework-data-nhibernate.md).

## Context
- Namespace: `SAIF.Data.NHibernate.Repositories.Imaging`
- Assembly/package: `SAIF.Framework.Data.NHibernate`

## Public members
| Member | Signature | Purpose |
| --- | --- | --- |
| GetNextImageId | `public static long GetNextImageId(this IRepository<Image> repository)` | Casts `repository` to the concrete `Repository<Image>`, runs `Session.CreateSqlQuery("select image_seq.nextval from dual")`, and returns `Convert.ToInt64(query.UniqueResult())`. See [SQL-001](../../sql/SQL-001-saif-framework-data-nhibernate.md). |
| GetNextTowId | `public static long GetNextTowId(this IRepository<ImageSystem> repository)` | Casts `repository` to the concrete `Repository<ImageSystem>`, runs `Session.CreateSqlQuery("select tower_seq.nextval from dual")`, and returns `Convert.ToInt64(query.UniqueResult())`. See [SQL-002](../../sql/SQL-002-saif-framework-data-nhibernate.md). |
| GetNextImageAffiliationId | `public static long GetNextImageAffiliationId(this IRepository<ImageAffiliation> repository)` | Casts `repository` to the concrete `Repository<ImageAffiliation>`, runs `Session.CreateSqlQuery("select image_affiliation_seq.nextval from dual")`, and returns `Convert.ToInt64(query.UniqueResult())`. See [SQL-003](../../sql/SQL-003-saif-framework-data-nhibernate.md). |

## Behavioral notes
- Each method performs an unchecked downcast from `IRepository<T>` to the concrete `Repository<T>` class to access the internal `Session` field; calling these methods against an `IRepository<T>` implementation that is not backed by `Repository<T>` would throw an `InvalidCastException`.*
- These queries bypass entity mapping/NHibernate query translation entirely — they are raw SQL against Oracle sequences and are not portable to the SQL Server engine (this library has no SQL Server equivalent of these extension methods).

## Constraints and usage notes
- Oracle-only: relies on `NEXTVAL FROM DUAL` syntax, which has no SQL Server equivalent; calling these methods against a SQL Server-backed unit of work would fail at the database level.
- Requires the caller's `IRepository<T>` to actually be a `Repository<T>` instance obtained through `NHibernateUnitOfWork.GetRepository<TEntity>()`.

> **Note:** Statements marked with * were inferred from code structure, naming conventions, or
> contextual evidence where direct confirmation was not available in source artifacts.

## Sources
- `Repositories/Imaging/ImageRepositoryExtensions.cs`
- `Repositories/Repository.cs`
