---
title: "SQL-247: PolicyExtensions.GenerateAgencies"
summary: Create operation for `PolicyExtensions.GenerateAgencies`
status: draft
owner: SAIF.Core documentation team
last_reviewed: 2026-09-24
library: SAIF.Data
reference_type: package
---

# SQL-247: PolicyExtensions.GenerateAgencies

This statement is a create operation invoked through ORM (IRepository.Add). Executed by `PolicyExtensions.GenerateAgencies`.

## Classification

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

## Tables

| Table | Access | Columns used |
| --- | --- | --- |
| [Agent](../database-tables.md#agent) | INSERT ×45 (hypothetical) | agent_num, agent_name, agent_exp_date, agency_seq_num, mail_addr_loc_seq_num |

## LINQ statement

Source: `Data/SAIF.Data/TestRepository/RepositoryExtensions/PolicyExtensions.cs:31`.

```csharp
// Data/SAIF.Data/TestRepository/RepositoryExtensions/PolicyExtensions.cs:31
var producers = uow.GetRepository<Agent>();

// Data/SAIF.Data/TestRepository/RepositoryExtensions/PolicyExtensions.cs:47-52
var producer = new Agent
{
    Name = string.Concat("Producer #", j),
    Agency = agency,
};
producers.Add(producer);
```

## Sample SQL

> **Test double — no runtime SQL.** This statement executes against `TestUnitOfWork`/`TestRepository<T>` (in-memory, `List<TEntity>`-backed test doubles in `SAIF.Framework.Core`); no NHibernate session is opened and no SQL is issued at runtime. The SQL below is the hypothetical statement the same expression would produce against a real NHibernate `IUnitOfWork` using the in-repo mappings, shown to document the mapping shape only — **no database table is accessed when this code runs.**

> **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
INSERT INTO Agent (
  agent_num,
  agent_name,
  agent_exp_date,
  agency_seq_num,
  mail_addr_loc_seq_num)
VALUES (
  :Id,
  :Name,
  :ExpirationDate,
  :Agency,
  :MailingLocation)
```

Translation notes:
- Not accessed: `Agency` — `Agency = agency` sets the FK value `agency_seq_num` only; no read of `Agency`.
- `Id(agent_num)` is assigned; the loop does not set `Id`, so every producer would carry the default `0` — duplicate-key on a real database. Hypothetical only.

## Sources

- `Data/SAIF.Data/TestRepository/RepositoryExtensions/PolicyExtensions.cs:31`
