---
title: "SQL-032: Create ImageAgency via AddImage"
summary: Create operation against ImageAgency via NHibernate ORM.
status: draft
owner: SAIF Doc Gen
last_reviewed: 2026-09-24
library: SAIF.Services
reference_type: package
---

# SQL-032: Create ImageAgency via AddImage

This ORM statement performs a create operation on `ImageAgency` via `AddImage`, executed from `Services/SAIF.Services/Agencies/Imaging/ImageService.cs` (L106).

## Classification

| Field | Value |
| --- | --- |
| **SQL ID** | SQL-032 |
| **Operation type** | Create |
| **Execution method** | ORM (IRepository.Add) |
| **Database** | Oracle |
| **Schema** | [unqualified]** |
| **Command type** | N/A (ORM-generated) |
| **Business object** | `ImageAgency` |
| **Criteria property** | N/A — ORM |
| **Lifecycle method** | `AddImage` |

## Parameters

| Parameter | Direction | Type | Max length | Description |
| --- | --- | --- | --- | --- |
| `:Id` | Input | `long` | N/A | Identifier from `image_agency_seq.NEXTVAL` |
| `:Agency` | Input | `Agency` | N/A | Identifier of the referenced `Agency` entity (`References(x => x.Agency)`) |
| `:Image` | Input | `Image` | N/A | Identifier of the referenced `?` entity (`References(x => x.Image)`) |

## Tables

| Table | Access | Columns used |
| --- | --- | --- |
| [Image_Agency](../database-tables.md#image_agency) | INSERT | image_agency_seq_num, agency_seq_num, image_seq_num (identifier from sequence `image_agency_seq.NEXTVAL`) |

## LINQ statement

Source: `Services/SAIF.Services/Agencies/Imaging/ImageService.cs:106`.

```csharp
// Services/SAIF.Services/Agencies/Imaging/ImageService.cs:106
unitOfWork.GetRepository<agenciesDataModel.ImageAgency>().Add(agencyImage);
```

## 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 image_agency_seq.NEXTVAL
FROM DUAL

INSERT INTO Image_Agency (
  image_agency_seq_num,
  agency_seq_num,
  image_seq_num)
VALUES (
  :Id,
  :Agency,
  :Image)
```

Translation notes:
- `:Id` is the value fetched from sequence `image_agency_seq` (`GeneratedBy.Native("image_agency_seq")`) before the INSERT; NHibernate assigns it to `ImageAgency.Id`.
- Reference FK values are bound from the associated entity's identifier; the referenced tables are **not** read or joined by this statement: `Agency` → `agency_seq_num` (entity table `Agency` not accessed); `Image` → `image_seq_num`.

## Operations and processes
- ImageService.AddImage — see [Operations and processes](../operations-processes.md)

> **Note:** Statements marked with `**` could not be confirmed; treat as unknown until verified.

## Sources
- `Services/SAIF.Services/Agencies/Imaging/ImageService.cs (L106)`
