---
title: "SQL-229: ServiceCodeQueryProvider.GetServiceCode"
summary: Read operation for `ServiceCodeQueryProvider.GetServiceCode`
status: draft
owner: SAIF.Core documentation team
last_reviewed: 2026-09-24
library: SAIF.Data
reference_type: package
---

# SQL-229: ServiceCodeQueryProvider.GetServiceCode

This statement is a read operation invoked through ORM (NHibernate LINQ). Executed by `ServiceCodeQueryProvider.GetServiceCode`.

## Classification

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

## Parameters

| Parameter | Direction | Type | Max length | Description |
| --- | --- | --- | --- | --- |
| `code` | Input | string | N/A | Method argument of `ServiceCodeQueryProvider.GetServiceCode` bound into the ORM expression; NHibernate generates the bind variable at runtime |
| `type` | Input | string | N/A | Method argument of `ServiceCodeQueryProvider.GetServiceCode` bound into the ORM expression; NHibernate generates the bind variable at runtime |
| `serviceDate` | Input | DateTime | N/A | Method argument of `ServiceCodeQueryProvider.GetServiceCode` bound into the ORM expression; NHibernate generates the bind variable at runtime |

## Tables

| Table | Access | Columns used |
| --- | --- | --- |
| [CBP_SERVICE_CODE](../database-tables.md#cbp_service_code) | SELECT | CODE, BILL_SERVICE_TYPE_CODE, UPDATE_NUM, EFF_DATE, EXP_DATE, RP_1099_REQ_FLAG, UPDATE_USER, UPDATE_DATE, NURSE_REVIEW_REQUIRED_FLAG, DCBS_REPORT_SERVICE_CODE |

## LINQ statement

Source: `Data/SAIF.Data/Queries/Claims/ServiceCodeQueryProvider.cs:19-23`. The repository/queryable is initialised at `Data/SAIF.Data/Queries/Claims/ServiceCodeQueryProvider.cs:14`.

```csharp
// Data/SAIF.Data/Queries/Claims/ServiceCodeQueryProvider.cs:14
repository = Factory.GetRepository<CbpServiceCode>().Query();

// Data/SAIF.Data/Queries/Claims/ServiceCodeQueryProvider.cs:19-23
public CbpServiceCode GetServiceCode(string code, string type, DateTime serviceDate)
{
    var service = repository.SingleOrDefault(x => x.Code == code
        && x.ServiceType.Code == type
        && ((x.EffectiveDate <= serviceDate)
            && (x.ExpirationDate.GetValueOrDefault(serviceDate) >=
                                    serviceDate)));

    return service;


}
```

## 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.

```sql
-- Inferred from LINQ (NHibernate mapping translation); not concrete SQL
SELECT
  CSC.CODE,
  CSC.BILL_SERVICE_TYPE_CODE,
  CSC.UPDATE_NUM,
  CSC.EFF_DATE,
  CSC.EXP_DATE,
  CSC.RP_1099_REQ_FLAG,
  CSC.UPDATE_USER,
  CSC.UPDATE_DATE,
  CSC.NURSE_REVIEW_REQUIRED_FLAG,
  CSC.DCBS_REPORT_SERVICE_CODE
FROM CBP_SERVICE_CODE CSC
WHERE CSC.CODE = :code
  AND CSC.BILL_SERVICE_TYPE_CODE = :type
  AND CSC.EFF_DATE <= :serviceDate
  AND COALESCE(CSC.EXP_DATE, :serviceDate) >= :serviceDate
-- SingleOrDefault: NHibernate expects at most one row
```

Translation notes:
- `ExpirationDate.GetValueOrDefault(serviceDate)` → `COALESCE(CSC.EXP_DATE, :serviceDate)`. NHibernate's LINQ provider supports `GetValueOrDefault(x)` as coalesce.

## Operations and processes

- [Other query providers](../operations/other-query-providers.md)


## Sources
- `Data/SAIF.Data/Queries/Claims/ServiceCodeQueryProvider.cs:19`
