Skip to content

SQL-249: PolicyExtensions.GenerateDefaultPolicies

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

Classification

Field Value
SQL ID SQL-249
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 GenerateDefaultPolicies

Tables

Table Access Columns used
POLICY INSERT ×24 (hypothetical) POLICY_NUM, POLICY_NAME, LEGAL_NAME, SECURE_POLICY_CODE, OFFICE_CODE, ACCOUNT_NUM, POLICY_STATUS_CODE, MARKET_TYPE_CODE, POLICY_RELATIONSHIP_POLICY_NUM, POLICY_RELATIONSHIP_CODE, customer_service_team_code, ENTITY_CODE, TRADING_SEQ_NUM, RATE_ACCOUNT, AGENT_NUM

LINQ statement

Source: Data/SAIF.Data/TestRepository/RepositoryExtensions/PolicyExtensions.cs:64.

// Data/SAIF.Data/TestRepository/RepositoryExtensions/PolicyExtensions.cs:64-66
var polRepo = uow.GetRepository<Policy>();
var testRepo = polRepo as TestRepository<Policy>;
testRepo.KeyPropertyName = "PolicyNumber";

// Data/SAIF.Data/TestRepository/RepositoryExtensions/PolicyExtensions.cs:80-87
var policy = new Policy
{
    MarketType = i.IsBetween(10, 15) ? arpMarketType : volMarketType,
    PolicyName = string.Concat("Policy #", i),
    Agent = i % 2 == 0 ? saifAgent : externalAgent162,
    Office = i.IsBetween(10, 15) ? arpOffice : (i.IsBetween(16, 24) ? portlandOffice : serviceCenterOffice)
};
polRepo.Add(policy);

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.

-- Inferred from LINQ (NHibernate mapping translation); not concrete SQL
INSERT INTO POLICY (
  POLICY_NUM,
  POLICY_NAME,
  LEGAL_NAME,
  SECURE_POLICY_CODE,
  OFFICE_CODE,
  ACCOUNT_NUM,
  POLICY_STATUS_CODE,
  MARKET_TYPE_CODE,
  POLICY_RELATIONSHIP_POLICY_NUM,
  POLICY_RELATIONSHIP_CODE,
  customer_service_team_code,
  ENTITY_CODE,
  TRADING_SEQ_NUM,
  RATE_ACCOUNT,
  AGENT_NUM)
VALUES (
  :PolicyNumber,
  :PolicyName,
  :LegalName,
  :SecurePolicyCode,
  :OfficeCode,
  :AccountNumber,
  :Status,
  :MarketType,
  :RelationshipPolicy,
  :Relationship,
  :CustomerServiceTeam,
  :Entity,
  :MainDbaName,
  :RateAccount,
  :Agent)

Translation notes: - Not accessed: MARKET_TYPE_CODE, OFFICE_CODE, Agent — the MarketType, Office, Agent references contribute FK values only (their lookups are SQL-282/SQL-283). OFFICE_CODE is mapped twice on POLICY (Map(OfficeCode) and References(Office)); the column is written once. - Line 65 casts to TestRepository<Policy> and sets KeyPropertyName = "PolicyNumber" so the test double auto-generates POLICY_NUM; against a real UoW the cast yields null and line 66 throws NullReferenceException — this code cannot run against NHibernate. - HasMany(...).Cascade.All() on TeamFunctions (assigned at line 96) would cascade save-or-update to POLICY_TEAM_FUNCTION rows already added in SQL-248.

Sources

  • Data/SAIF.Data/TestRepository/RepositoryExtensions/PolicyExtensions.cs:64