SQL-190: OverpaymentQueryProvider.GetRecoverableBalance¶
This statement is a read operation invoked through ORM (NHibernate LINQ). Executed by OverpaymentQueryProvider.GetRecoverableBalance.
Classification¶
| Field | Value |
|---|---|
| SQL ID | SQL-190 |
| Operation type | Read |
| Execution method | ORM (NHibernate LINQ) |
| Database | Oracle* |
| Schema | [unqualified]** |
| Command type | N/A (ORM-generated) |
| Business object | OverpaymentQueryProvider |
| Criteria property | N/A — ORM |
| Lifecycle method | GetRecoverableBalance |
Parameters¶
| Parameter | Direction | Type | Max length | Description |
|---|---|---|---|---|
workerId |
Input | long | N/A | Method argument of OverpaymentQueryProvider.GetRecoverableBalance bound into the ORM expression; NHibernate generates the bind variable at runtime |
Tables¶
| Table | Access | Columns used |
|---|---|---|
| CL_OVERPAYMENT | SELECT (existence + aggregate) | WORKER_ID, AMENDED_OVERPAYMENT_SEQ_NUM, OVERPAYMENT_STATUS_CODE (filters); OUTSTANDING_AMOUNT (SUM) |
LINQ statement¶
Source: Data/SAIF.Data/Queries/Claims/OverpaymentQueryProvider.cs:22-28. The repository/queryable is initialised at Data/SAIF.Data/Queries/Claims/OverpaymentQueryProvider.cs:12.
// Data/SAIF.Data/Queries/Claims/OverpaymentQueryProvider.cs:12
repository = Factory.GetRepository<Overpayment>().Query();
// Data/SAIF.Data/Queries/Claims/OverpaymentQueryProvider.cs:22-28
public decimal GetRecoverableBalance(long workerId)
{
var statusCodes = new string[] { "1", "3" };
var result = (decimal)0;
var opRecords = repository
.Where(x => x.Worker.PersonId == workerId)
.Where(x => x.AmendedOverpaymentId == 0)
.Where(x => statusCodes.Contains(x.Status.Code));
if (opRecords.Any())
result = opRecords.Sum(x => x.OutstandingAmount);
return result;
}
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
-- Statement 1 (line 27): opRecords.Any()
SELECT * FROM (
SELECT 1
FROM CL_OVERPAYMENT CO
WHERE CO.WORKER_ID = :workerId
AND CO.AMENDED_OVERPAYMENT_SEQ_NUM = 0
AND CO.OVERPAYMENT_STATUS_CODE IN ('1', '3')
) WHERE ROWNUM <= 1;
-- Statement 2 (line 28), only when statement 1 returns a row: opRecords.Sum(x => x.OutstandingAmount)
SELECT SUM(CO.OUTSTANDING_AMOUNT)
FROM CL_OVERPAYMENT CO
WHERE CO.WORKER_ID = :workerId
AND CO.AMENDED_OVERPAYMENT_SEQ_NUM = 0
AND CO.OVERPAYMENT_STATUS_CODE IN ('1', '3')
Translation notes:
- The three chained Where calls are ANDed together.
- statusCodes.Contains(x.Status.Code) → IN (:p0, :p1). The values are shown inline.
- Two round trips: Any(), then Sum(). The Any guard avoids a null-to-decimal cast failure on an empty SUM.
Operations and processes¶
Business rules¶
Sources¶
Data/SAIF.Data/Queries/Claims/OverpaymentQueryProvider.cs:22