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

# SQL-053: Create Task

This ORM statement performs a create operation on `Task` via `CreateMarketingTask, CreateUnderwritingTask`, executed from `Services/SAIF.Services/Tasks/TaskFactory.cs` (L41), `Services/SAIF.Services/Tasks/TaskFactory.cs` (L56).

## Classification

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

## Parameters

| Parameter | Direction | Type | Max length | Description |
| --- | --- | --- | --- | --- |
| `:Id` | Input | `long` | N/A | Identifier from `TASK_SEQ.NEXTVAL` |
| `:UpdateNumber` | Input | `int` | N/A | Version column (`Version()`); NHibernate writes its initial value |
| `:TaskDate` | Input | `DateTime` | N/A |  |
| `:TaskText` | Input | `string` | N/A |  |
| `:TaskUser` | Input | `string` | N/A |  |
| `:IsSavedToNotepad` | Input | `bool` | N/A | Bound as `'Y'`/`'N'` (`YesNoType`) |
| `:IsDeleted` | Input | `bool` | N/A | Bound as `'Y'`/`'N'` (`YesNoType`) |
| `:ImageId` | Input | `long?` | N/A |  |
| `:ContextCode` | Input | `string` | N/A |  |
| `:ContextKey` | Input | `string` | N/A |  |
| `:ContextCategory` | Input | `string` | N/A |  |
| `:ContextText` | Input | `string` | N/A |  |
| `:ContextDate` | Input | `DateTime?` | N/A |  |
| `:ContextNumber` | Input | `long?` | N/A |  |
| `:CreateDate` | Input | `DateTime` | N/A |  |
| `:CreateUser` | Input | `string` | N/A |  |
| `:UpdateDate` | Input | `DateTime` | N/A |  |
| `:UpdateUser` | Input | `string` | N/A |  |
| `:TaskSecurity` | Input | `string` | N/A |  |
| `:ClaimId` | Input | `long` | N/A |  |
| `:Policy` | Input | `Policy` | N/A | Identifier of the referenced `Policy` entity (`References(x => x.Policy)`) |
| `:TaskAction` | Input | `TaskAction` | N/A | Identifier of the referenced `TaskAction` entity (`References(x => x.TaskAction)`) |
| `:TaskCategory` | Input | `TaskCategory` | N/A | Identifier of the referenced `TaskCategory` entity (`References(x => x.TaskCategory)`) |
| `:TaskPriority` | Input | `TaskPriority` | N/A | Identifier of the referenced `TaskPriority` entity (`References(x => x.TaskPriority)`) |
| `:TaskSource` | Input | `TaskSource` | N/A | Identifier of the referenced `TaskSource` entity (`References(x => x.TaskSource)`) |
| `:TaskGroup` | Input | `TaskGroup` | N/A | Identifier of the referenced `TaskGroup` entity (`References(x => x.TaskGroup)`) |
| `:LegalNoteCategory` | Input | `LegalNoteCategory` | N/A | Identifier of the referenced `LegalNoteCategory` entity (`References(x => x.LegalNoteCategory)`) |

## Tables

| Table | Access | Columns used |
| --- | --- | --- |
| [TASK](../database-tables.md#task) | INSERT | TASK_SEQ_NUM, UPDATE_SEQ_NUM, TASK_DATE, TASK_TEXT, TASK_USER, NOTEPAD_FLAG, DELETE_FLAG, IMAGE_SEQ_NUM, CONTEXT_CODE, CONTEXT_KEY, CONTEXT_CATEGORY, CONTEXT_TEXT, CONTEXT_DATE, CONTEXT_NUM, CREATE_DATE, CREATE_USER, UPDATE_DATE, UPDATE_USER, TASK_SECURITY, CLAIM_ID, POLICY_NUM, TASK_ACTION_CODE, TASK_CATEGORY_CODE, TASK_PRIORITY_CODE, TASK_SOURCE_CODE, CLAIM_TASK_GROUP_CODE, LEGAL_NOTE_CATEGORY_CODE (identifier from sequence `TASK_SEQ.NEXTVAL`) |

## LINQ statement

Source: `Services/SAIF.Services/Tasks/TaskFactory.cs:41`, `Services/SAIF.Services/Tasks/TaskFactory.cs:56`.

```csharp
// Services/SAIF.Services/Tasks/TaskFactory.cs:83
private IRepository<Task> TaskRepository { get { return factory.GetRepository<Task>(); } }

// Services/SAIF.Services/Tasks/TaskFactory.cs:41
TaskRepository.Add(task);

// Services/SAIF.Services/Tasks/TaskFactory.cs:56
TaskRepository.Add(task);
```

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

INSERT INTO TASK (
  TASK_SEQ_NUM,
  UPDATE_SEQ_NUM,
  TASK_DATE,
  TASK_TEXT,
  TASK_USER,
  NOTEPAD_FLAG,
  DELETE_FLAG,
  IMAGE_SEQ_NUM,
  CONTEXT_CODE,
  CONTEXT_KEY,
  CONTEXT_CATEGORY,
  CONTEXT_TEXT,
  CONTEXT_DATE,
  CONTEXT_NUM,
  CREATE_DATE,
  CREATE_USER,
  UPDATE_DATE,
  UPDATE_USER,
  TASK_SECURITY,
  CLAIM_ID,
  POLICY_NUM,
  TASK_ACTION_CODE,
  TASK_CATEGORY_CODE,
  TASK_PRIORITY_CODE,
  TASK_SOURCE_CODE,
  CLAIM_TASK_GROUP_CODE,
  LEGAL_NOTE_CATEGORY_CODE)
VALUES (
  :Id,
  :UpdateNumber,
  :TaskDate,
  :TaskText,
  :TaskUser,
  :IsSavedToNotepad,
  :IsDeleted,
  :ImageId,
  :ContextCode,
  :ContextKey,
  :ContextCategory,
  :ContextText,
  :ContextDate,
  :ContextNumber,
  :CreateDate,
  :CreateUser,
  :UpdateDate,
  :UpdateUser,
  :TaskSecurity,
  :ClaimId,
  :Policy,
  :TaskAction,
  :TaskCategory,
  :TaskPriority,
  :TaskSource,
  :TaskGroup,
  :LegalNoteCategory)
```

Translation notes:
- `:Id` is the value fetched from sequence `TASK_SEQ` (`GeneratedBy.Native("TASK_SEQ")`) before the INSERT; NHibernate assigns it to `Task.Id`.
- `UPDATE_SEQ_NUM` is the optimistic-concurrency version column (`Version(x => x.UpdateNumber)`); NHibernate sets its initial value on INSERT.
- `:IsSavedToNotepad`, `:IsDeleted` are bound as `'Y'` / `'N'` (`YesNoType`).
- Reference FK values are bound from the associated entity's identifier; the referenced tables are **not** read or joined by this statement: `Policy` → `POLICY_NUM` (entity table `POLICY` not accessed); `TaskAction` → `TASK_ACTION_CODE` (entity table `TASK_ACTION_CODE` not accessed); `TaskCategory` → `TASK_CATEGORY_CODE` (entity table `TASK_CATEGORY_CODE` not accessed); `TaskPriority` → `TASK_PRIORITY_CODE` (entity table `TASK_PRIORITY_CODE` not accessed); `TaskSource` → `TASK_SOURCE_CODE` (entity table `TASK_SOURCE_CODE` not accessed); `TaskGroup` → `CLAIM_TASK_GROUP_CODE` (entity table `CLAIM_TASK_GROUP_CODE` not accessed); `LegalNoteCategory` → `LEGAL_NOTE_CATEGORY_CODE` (entity table `NOTE_CATEGORY_CODE` not accessed).
- Two call sites (`:41`, `:56`); `TaskRepository` is `factory.GetRepository<Task>()` (`TaskFactory.cs:83`, `IRepositoryFactory` injected at line 21). The `TaskCategory` used by `CreateDefaultTask` comes from `_queryProvider.GetCategory(categoryCode)` (`TaskFactory.cs:61`), a separate query; the priority/source/action FKs are copied from that category.

## Operations and processes
- TaskFactory.CreateMarketingTask — see [Operations and processes](../operations-processes.md)
- TaskFactory.CreateUnderwritingTask — see [Operations and processes](../operations-processes.md)

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

## Sources
- `Services/SAIF.Services/Tasks/TaskFactory.cs (L41, L56)`
