Skip to content

SQL-286: PolicyOutputDocumentExtensions.GetRegionalPolicyServedByDirectWriter

This statement is a read operation invoked through ORM (NHibernate LINQ). Executed by PolicyOutputDocumentExtensions.GetRegionalPolicyServedByDirectWriter.

Classification

Field Value
SQL ID SQL-286
Operation type Read
Execution method ORM (NHibernate LINQ)
Database Oracle*
Schema [unqualified]**
Command type N/A (ORM-generated)
Business object PolicyOutputDocumentExtensions
Criteria property N/A — ORM
Lifecycle method GetRegionalPolicyServedByDirectWriter

Tables

Table Access Columns used
POLICY SELECT (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
Agent JOIN (hypothetical) agent_num, agency_seq_num

LINQ statement

Source: Data/SAIF.Data/TestRepository/RepositoryExtensions/PolicyOutputDocumentExtensions.cs:47.

// Data/SAIF.Data/TestRepository/RepositoryExtensions/PolicyOutputDocumentExtensions.cs:47-54
var policy =
    uow.GetRepository<Policy>()
        .Query()
        .FirstOrDefault(
            p =>
                p.Office.Code != OfficeCode.AssignedRiskOfficeCode &&
                p.Office.Code != OfficeCode.ServiceCenterOfficeCode &&
                p.Agent.Agency.Id == 0);

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
SELECT *
FROM (
  SELECT
    P.POLICY_NUM,
    P.POLICY_NAME,
    P.LEGAL_NAME,
    P.SECURE_POLICY_CODE,
    P.OFFICE_CODE,
    P.ACCOUNT_NUM,
    P.POLICY_STATUS_CODE,
    P.MARKET_TYPE_CODE,
    P.POLICY_RELATIONSHIP_POLICY_NUM,
    P.POLICY_RELATIONSHIP_CODE,
    P.customer_service_team_code,
    P.ENTITY_CODE,
    P.TRADING_SEQ_NUM,
    P.RATE_ACCOUNT,
    P.AGENT_NUM
  FROM POLICY P
  INNER JOIN Agent A
    ON A.agent_num = P.AGENT_NUM
  WHERE P.OFFICE_CODE <> :p0  -- 'HOME'
    AND P.OFFICE_CODE <> :p1  -- 'SERV'
    AND A.agency_seq_num = :p2  -- 0)
WHERE ROWNUM <= 1

Translation notes: - Not accessed: OFFICE_CODE — p.Office.Code is the identifier of OfficeCode, short-circuited to POLICY.OFFICE_CODE. Agency — p.Agent.Agency.Id is the identifier of Agency, short-circuited to Agent.agency_seq_num; only the Agent hop requires a join. - Implicit navigation p.Agent.Agency produces an inner join to Agent (NHibernate 4 may render it as a theta join FROM POLICY P, Agent A WHERE A.agent_num = P.AGENT_NUM); policies with a null AGENT_NUM are excluded. - OFFICE_CODE is mapped twice on POLICY (Map(OfficeCode) and References(Office)); the predicate uses the same column.

Sources

  • Data/SAIF.Data/TestRepository/RepositoryExtensions/PolicyOutputDocumentExtensions.cs:47