SQL-260: Retrieve Policy via PolicyQuery (property)¶
This statement reads a single POLICY row by policy number. PolicyQuery is a protected property that only returns an unexecuted IQueryable<Policy>; the actual SQL executes at each downstream SingleOrDefault call in GenerateTasksService (payment, missing-payment, and expiring-judgment task generation). It is issued via NHibernate LINQ from Services/SAIF.Services/Collections/GenerateTasksService.cs.
Classification¶
| Field | Value |
|---|---|
| SQL ID | SQL-260 |
| Operation type | Read |
| Execution method | ORM (NHibernate LINQ) |
| Database | Oracle |
| Schema | [unqualified]** |
| Command type | N/A (ORM-generated) |
| Business object | GenerateTasksService |
| Criteria property | N/A — ORM |
| Lifecycle method | PolicyQuery (property); consumed at L105, L163, L238 |
Parameters¶
| Parameter | Direction | Type | Max length | Description |
|---|---|---|---|---|
:PolicyNum |
Input | long | N/A | Policy number (...PolicyNum.Value at each consumer: selectedPayment.Case, missingPayment.Case, expiringJudgment) |
Tables¶
| Table | Access | Columns used |
|---|---|---|
| POLICY | SELECT | 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: Services/SAIF.Services/Collections/GenerateTasksService.cs:27
// Services/SAIF.Services/Collections/GenerateTasksService.cs:27-33
protected IQueryable<SAIF.Data.Model.Policies.Policy> PolicyQuery
{
get
{
return UnitOfWork.GetRepository<SAIF.Data.Model.Policies.Policy>().Query();
}
}
// Services/SAIF.Services/Collections/GenerateTasksService.cs:105
? PolicyQuery.SingleOrDefault(x => x.PolicyNumber == selectedPayment.Case.PolicyNum.Value)
// Services/SAIF.Services/Collections/GenerateTasksService.cs:163
? PolicyQuery.SingleOrDefault(x => x.PolicyNumber == missingPayment.Case.PolicyNum.Value)
// Services/SAIF.Services/Collections/GenerateTasksService.cs:238
? PolicyQuery.SingleOrDefault(x => x.PolicyNumber == expiringJudgment.PolicyNum.Value)
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.
-- Inferred from LINQ (NHibernate mapping translation); not concrete SQL
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
WHERE P.POLICY_NUM = :PolicyNum
-- NHibernate expects at most one row
Translation notes:
- The cited line (L31) only returns an unexecuted IQueryable<Policy>; no SQL runs there. The statement executes at each downstream SingleOrDefault (L105, L163, L238), all with the same shape.
- Single/SingleOrDefault → no row limit; NHibernate throws if more than one row is returned.
- Expressions that do not reference the lambda parameter (captured locals, members of already-loaded objects, Convert.ToInt64(...), DateTime.Today) are evaluated client-side by NHibernate's partial evaluator and bound as a single parameter value.
- OFFICE_CODE is mapped both as Map(OfficeCode) (PolicyMap.cs:18) and References(Office) (PolicyMap.cs:26); it is selected once. All other References contribute their FK column only; HasMany collections (Periods, DbaNames, OscPolicies, SubmissionPolicies, TeamFunctions, BusinessAffiliates) are lazy and not selected.
Operations and processes¶
- GenerateTasksService.PolicyQuery (property) — see Operations and processes
Sources¶
Services/SAIF.Services/Collections/GenerateTasksService.cs (L31)