---
title: "SQL-240: EbillQueryProvider.SetCompoundDrugForAllServiceLinesForTheBill"
summary: Update operation for `EbillQueryProvider.SetCompoundDrugForAllServiceLinesForTheBill`
status: draft
owner: SAIF.Core documentation team
last_reviewed: 2026-09-24
library: SAIF.Data
reference_type: package
---

# SQL-240: EbillQueryProvider.SetCompoundDrugForAllServiceLinesForTheBill

This statement is a update operation invoked through ORM (dirty-check flush*). Executed by `EbillQueryProvider.SetCompoundDrugForAllServiceLinesForTheBill`.

## Classification

| Field | Value |
| --- | --- |
| **SQL ID** | SQL-240 |
| **Operation type** | Update |
| **Execution method** | ORM (dirty-check flush*) |
| **Database** | Oracle* |
| **Schema** | [unqualified]** |
| **Command type** | N/A (ORM-generated) |
| **Business object** | `EbillQueryProvider` |
| **Criteria property** | N/A — ORM |
| **Lifecycle method** | `SetCompoundDrugForAllServiceLinesForTheBill` |

## Parameters

| Parameter | Direction | Type | Max length | Description |
| --- | --- | --- | --- | --- |
| `bill` | Input | Ebill | N/A | Method argument of `EbillQueryProvider.SetCompoundDrugForAllServiceLinesForTheBill` bound into the ORM expression; NHibernate generates the bind variable at runtime |

## Tables

| Table | Access | Columns used |
| --- | --- | --- |
| [EBILL_SERVICE](../database-tables.md#ebill_service) | SELECT (COUNT DISTINCT), SELECT, UPDATE (flush) | EBILL_SEQ_NUM, NATIONAL_DRUG_CODE, COMPOUND_DRUG_FLAG, (PrescriptionNumber — **unmapped**), all mapped columns for enumeration |

## LINQ statement

Source: `Data/SAIF.Data/Queries/Claims/Ebilling/EbillQueryProvider.cs:315`.

```csharp
// Data/SAIF.Data/Queries/Claims/Ebilling/EbillQueryProvider.cs:311-316
var billServices = Factory.GetRepository<EbillService>().Query().Where(x => x.Bill == bill && x.NationalDrugCode != null);
if (billServices.Select(x => x.PrescriptionNumber).Distinct().Count() <= 1) return;
foreach (var service in billServices)
{
    service.IsCompoundDrug = true;
}
```

## 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
-- (a) line 312: billServices.Select(x => x.PrescriptionNumber).Distinct().Count()
SELECT COUNT(DISTINCT ES.<PrescriptionNumber>)  -- unresolved mapping: EbillService.PrescriptionNumber has no Map() in EbillServiceMap
FROM EBILL_SERVICE ES
WHERE ES.EBILL_SEQ_NUM = :billId
  AND ES.NATIONAL_DRUG_CODE IS NOT NULL

-- (b) line 313: foreach enumeration of billServices (only when (a) > 1)
SELECT
  ES.EBILL_SERVICE_SEQ_NUM,
  ES.UPDATE_NUM,
  ES.EBILL_SERVICE_SUB_NUM,
  ES.LINE_CONTROL_NUM,
  ES.BILL_SERVICE_DATE,
  ES.BILL_SERVICE_END_DATE,
  ES.CHARGE_AMOUNT,
  ES.SERVICE_QUANTITY,
  ES.UNIT_TYPE_CODE,
  ES.SERVICE_MODIFIER_CODE1,
  ES.SERVICE_MODIFIER_CODE2,
  ES.SERVICE_MODIFIER_CODE3,
  ES.SERVICE_MODIFIER_CODE4,
  ES.BILL_SERVICE_CODE,
  ES.NATIONAL_DRUG_CODE,
  ES.TOOTH_CODE,
  ES.RENDERING_PROVIDER_NPI,
  ES.REFERRING_PROVIDER_NPI,
  ES.DIAGNOSIS_POINTER_CODE1,
  ES.DIAGNOSIS_POINTER_CODE2,
  ES.DIAGNOSIS_POINTER_CODE3,
  ES.DIAGNOSIS_POINTER_CODE4,
  ES.REVENUE_CODE,
  ES.SERVICE_LOCATION_CODE,
  ES.DISPENSE_AS_WRITTEN_CODE,
  ES.DAYS_SUPPLY_QTY,
  ES.UPDATE_USER,
  ES.UPDATE_DATE,
  ES.PRESCRIBER_LAST_NAME,
  ES.PRESCRIBER_FIRST_NAME,
  ES.TAX_CHARGED_AMT,
  ES.COMPOUND_DRUG_FLAG,
  ES.PRESCRIPTION_WRITTEN_DATE,
  ES.EBILL_SEQ_NUM,
  ES.REFERRING_PROVIDER_LOC_SEQ_NUM,
  ES.RENDERING_PROVIDER_LOC_SEQ_NUM
FROM EBILL_SERVICE ES
WHERE ES.EBILL_SEQ_NUM = :billId
  AND ES.NATIONAL_DRUG_CODE IS NOT NULL

-- (c) line 315: dirty-checked at flush/commit, one per changed row (stateful session)
UPDATE EBILL_SERVICE
SET COMPOUND_DRUG_FLAG = 'Y',  -- YesNoType
    UPDATE_NUM = :newVersion
    -- NHibernate default dynamic-update=false: all mapped columns are written
WHERE EBILL_SERVICE_SEQ_NUM = :id
  AND UPDATE_NUM = :oldVersion
```

Translation notes:
- Not accessed: `EBILL` — `x.Bill == bill` compares the reference with a captured entity, which NHibernate translates as a comparison of the FK column `EBILL_SEQ_NUM` with the entity identifier; no join to `EBILL`.
- **Unresolved mapping:** `EbillService.PrescriptionNumber` (`Data/SAIF.Data/Model/Claims/Ebilling/EbillService.cs:47`) has no `Map(...)` in `EbillServiceMap.cs`. NHibernate LINQ would throw `could not resolve property: PrescriptionNumber` at statement (a); the column name cannot be inferred. Marked `<PrescriptionNumber>`.
- `billServices` is an un-materialised `IQueryable`; it is executed twice (the Count at line 312 and the enumeration at line 313).
- `x.NationalDrugCode != null` → `IS NOT NULL`. `COMPOUND_DRUG_FLAG` uses `YesNoType` (`'Y'`/`'N'`). `Version(UPDATE_NUM)` makes the UPDATE optimistic-concurrency checked.
- The cited line 315 is the in-memory assignment that causes (c).

## Operations and processes

- [E-bill processing queries](../operations/e-bill-processing-queries.md)

## Business rules

- [SD-BR-050 E-bill status and assignment-rule code sets](../business-rules.md#sd-br-050-e-bill-status-and-assignment-rule-code-sets)
- [SD-BR-051 Bill included in clearinghouse response file by response-batch state](../business-rules.md#sd-br-051-bill-included-in-clearinghouse-response-file-by-response-batch-state)
- [SD-BR-052 Multiple prescription numbers mark all NDC lines as compound drug](../business-rules.md#sd-br-052-multiple-prescription-numbers-mark-all-ndc-lines-as-compound-drug)

## Sources

- `Data/SAIF.Data/Queries/Claims/Ebilling/EbillQueryProvider.cs:315`
