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

# SQL-026: Create DocumentTemplateOption via AddTemplateOptions

This ORM statement performs a create operation on `DocumentTemplateOption` via `AddTemplateOptions`, executed from `Services/SAIF.Services/Documents/TemplateSearchService.cs` (L837).

## Classification

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

## Parameters

| Parameter | Direction | Type | Max length | Description |
| --- | --- | --- | --- | --- |
| `:Id` | Input | `long` | N/A | Identifier from `DOCUMENT_OPTION_SEQ.NEXTVAL` |
| `:DocumentTemplateSeqNum` | Input | `long` | N/A |  |
| `:CreateUser` | Input | `string` | N/A |  |
| `:CreateDate` | Input | `DateTime` | N/A |  |
| `:DocumentOptionCode` | Input | `DocumentOptionCode` | N/A | Identifier of the referenced `DocumentOptionCode` entity (`References(x => x.DocumentOptionCode)`) |

## Tables

| Table | Access | Columns used |
| --- | --- | --- |
| [DOCUMENT_TEMPLATE_OPTION](../database-tables.md#document_template_option) | INSERT | DOCUMENT_OPTION_SEQ_NUM, DOCUMENT_TEMPLATE_SEQ_NUM, CREATE_USER, CREATE_DATE, DOCUMENT_OPTION_CODE (identifier from sequence `DOCUMENT_OPTION_SEQ.NEXTVAL`) |

## LINQ statement

Source: `Services/SAIF.Services/Documents/TemplateSearchService.cs:837`.

```csharp
// Services/SAIF.Services/Documents/TemplateSearchService.cs:837
unitOfWork.GetRepository<DocumentTemplateOption>().Add(newTemplateOp);
```

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

INSERT INTO DOCUMENT_TEMPLATE_OPTION (
  DOCUMENT_OPTION_SEQ_NUM,
  DOCUMENT_TEMPLATE_SEQ_NUM,
  CREATE_USER,
  CREATE_DATE,
  DOCUMENT_OPTION_CODE)
VALUES (
  :Id,
  :DocumentTemplateSeqNum,
  :CreateUser,
  :CreateDate,
  :DocumentOptionCode)
```

Translation notes:
- `:Id` is the value fetched from sequence `DOCUMENT_OPTION_SEQ` (`GeneratedBy.Native("DOCUMENT_OPTION_SEQ")`) before the INSERT; NHibernate assigns it to `DocumentTemplateOption.Id`.
- The mapping declares `.Column(" DOCUMENT_TEMPLATE_SEQ_NUM")` with a leading space; Oracle treats the unquoted identifier as `DOCUMENT_TEMPLATE_SEQ_NUM`.
- Reference FK values are bound from the associated entity's identifier; the referenced tables are **not** read or joined by this statement: `DocumentOptionCode` → `DOCUMENT_OPTION_CODE` (entity table `DOCUMENT_OPTION_CODE` not accessed).

## Operations and processes
- TemplateSearchService.AddTemplateOptions — see [Operations and processes](../operations-processes.md)

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

## Sources
- `Services/SAIF.Services/Documents/TemplateSearchService.cs (L837)`
