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

# SQL-217: ProviderQueryProvider.HasActiveRelationship

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

## Classification

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

## Parameters

| Parameter | Direction | Type | Max length | Description |
| --- | --- | --- | --- | --- |
| `providerLocationId` | Input | long | N/A | Method argument of `ProviderQueryProvider.HasActiveRelationship` bound into the ORM expression; NHibernate generates the bind variable at runtime |
| `parentProviderLocationId` | Input | long | N/A | Method argument of `ProviderQueryProvider.HasActiveRelationship` bound into the ORM expression; NHibernate generates the bind variable at runtime |

## Tables

| Table | Access | Columns used |
| --- | --- | --- |
| [PROVIDER_RELATIONSHIP](../database-tables.md#provider_relationship) | SELECT (existence) | EXP_DATE, PROVIDER_LOCATION_SEQ_NUM, PARENT_PROVIDER_LOC_SEQ_NUM |

## LINQ statement

Source: `Data/SAIF.Data/Queries/Providers/ProviderQueryProvider.cs:240-243`.

```csharp
public bool HasActiveRelationship(long providerLocationId, long parentProviderLocationId)
{
    return Factory.GetRepository<ProviderRelationship>().Query()
        .Any(x => !x.ExpirationDate.HasValue
                  && x.ProviderLocation.Id == providerLocationId
                  && x.ParentProviderLocation.Id == parentProviderLocationId);
}
```

## 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 * FROM (
  SELECT 1
  FROM PROVIDER_RELATIONSHIP PR
  WHERE PR.EXP_DATE IS NULL
    AND PR.PROVIDER_LOCATION_SEQ_NUM = :providerLocationId
    AND PR.PARENT_PROVIDER_LOC_SEQ_NUM = :parentProviderLocationId
) WHERE ROWNUM <= 1
```

Translation notes:
- `!x.ExpirationDate.HasValue` → `IS NULL`. `Any()` → existence probe.

## Operations and processes

- [Provider queries](../operations/provider-queries.md)

## Business rules

- [SD-BR-080 Provider identity relationship and address code sets](../business-rules.md#sd-br-080-provider-identity-relationship-and-address-code-sets)
- [SD-BR-082 Dismissed bills excluded from provider location ids](../business-rules.md#sd-br-082-dismissed-bills-excluded-from-provider-location-ids)
- [SD-BR-083 Provider in MCO only within date window](../business-rules.md#sd-br-083-provider-in-mco-only-within-date-window)

## Sources
- `Data/SAIF.Data/Queries/Providers/ProviderQueryProvider.cs:240`
