﻿---
title: "ProvidersRepository"
summary: API reference for ProvidersRepository
status: draft
owner: SAIF.Core documentation team
last_reviewed: 2026-09-24
library: SAIF.Data.NHibernate
reference_type: package
---


# ProvidersRepository

`ProvidersRepository` is the only repository in this library that is a plain class rather than a `Repository<T>`/`RepositoryBase<T>` subclass: it wraps a generic `IUnitOfWork` and calls `unitOfWork.GetRepository<T>()` per-entity-type instead of being bound to a single mapped entity. It offers provider lookup by tax id and address lookup filtered by address type, with `GetProviderPaymentAddresses`/`GetProviderPhysicalAddresses` hard-coding the "PAY"/"PHY" address-type codes ([SDN-BR-031](../../business-rules.md#sdn-br-031-provider-payment-address-type-%3D-pay%2C-physical-%3D-phy)).

## Purpose
- Look up a `Provider` by its primary tax id for batch processing scenarios.
- Return active (non-expired) provider addresses filtered by address type, with dedicated payment ("PAY") and physical ("PHY") address helpers ([SDN-BR-031](../../business-rules.md#sdn-br-031-provider-payment-address-type-%3D-pay%2C-physical-%3D-phy)).
- Enforce that a non-null `IUnitOfWork` is supplied at construction, per [SDN-BR-030](../../business-rules.md#sdn-br-030-providersrepository-requires-a-non-null-unit-of-work).

## Context
- Namespace: `SAIF.Data.NHibernate.Repositories`
- Assembly/package: `SAIF.Data.NHibernate` (ships inside the `SAIF.SAIFCode.Core` NuGet package)
- No base class: `ProvidersRepository` is a plain class, not a `Repository<T>`/`RepositoryBase<T>` subclass; it holds a private `IUnitOfWork` field and calls `unitOfWork.GetRepository<T>()` per query.
- `IUnitOfWork` is defined in `SAIF.Framework.Data.NHibernate` (external); its concrete implementation, `NHibernateUnitOfWork`, exposes `GetRepository<TEntity>() : Repository<TEntity>` which constructs a new `Repository<TEntity>` bound to the same session/transaction (resolved via Legends CLI)†.

## Public members
| Member | Signature | Purpose |
| --- | --- | --- |
| ProvidersRepository(IUnitOfWork) | `public ProvidersRepository(IUnitOfWork uow)` | Constructor; validates `uow` is non-null via `Enforce.ArgumentNotNull` (SAIF.Framework.Core), throwing if null, then stores it ([SDN-BR-030](../../business-rules.md#sdn-br-030-providersrepository-requires-a-non-null-unit-of-work)). |
| GetProviderByTaxIdBatch | `public Provider GetProviderByTaxIdBatch(string taxId)` | Returns the single `Provider` whose `PrimaryTaxId` equals `taxId` via `unitOfWork.GetRepository<Provider>().Query().SingleOrDefault()`, or `null` if none/ambiguous match throws ([SQL-048](../../sql/SQL-048-providers-repository-get-provider-by-tax-id-batch.md)). |
| GetProviderAddresses | `public IEnumerable<ProviderAddress> GetProviderAddresses(long providerId, string addressType)` | Returns non-expired `ProviderAddress` rows for the given provider id and address-type code, materialized to a list, via `unitOfWork.GetRepository<ProviderAddress>().Query()` ([SQL-049](../../sql/SQL-049-providers-repository-get-provider-addresses.md)). |
| GetProviderPaymentAddresses | `public IEnumerable<ProviderAddress> GetProviderPaymentAddresses(long providerId)` | Calls `GetProviderAddresses(providerId, "PAY")` to return the provider's payment addresses ([SDN-BR-031](../../business-rules.md#sdn-br-031-provider-payment-address-type-%3D-pay%2C-physical-%3D-phy)). |
| GetProviderPhysicalAddresses | `public IEnumerable<ProviderAddress> GetProviderPhysicalAddresses(long providerId)` | Calls `GetProviderAddresses(providerId, "PHY")` to return the provider's physical addresses ([SDN-BR-031](../../business-rules.md#sdn-br-031-provider-payment-address-type-%3D-pay%2C-physical-%3D-phy)). |

## Behavioral notes
- `GetProviderAddresses` filters on `pa.ExpirationDate == null` (address currently active) in addition to `ProviderLocation.Provider.Id == providerId` and `AddressType.Code == addressType`*.
- Because this class does not derive from `Repository<T>`, it has no CRUD surface of its own; all persistence access goes through per-call `IUnitOfWork.GetRepository<TEntity>()` calls, meaning each query obtains a fresh `Repository<TEntity>` bound to the same underlying session/transaction as the injected unit of work†.

## Constraints and usage notes
- The constructor throws (via `Enforce.ArgumentNotNull`) if `uow` is null; callers must supply a valid `IUnitOfWork` instance ([SDN-BR-030](../../business-rules.md#sdn-br-030-providersrepository-requires-a-non-null-unit-of-work)).
- `GetProviderByTaxIdBatch` uses `SingleOrDefault`, which throws `InvalidOperationException` if more than one `Provider` shares the same `PrimaryTaxId`*.

> **Note:** Statements marked with `†` are derived from dependency library
> documentation via the Legends CLI. Statements marked with `*` were inferred
> from code structure or contextual evidence. Statements marked with `**` could
> not be confirmed; treat as unknown until verified.

## Related documentation
- [Index](../../index.md)
- [Overview](../../overview.md)
- [Architecture](../../architecture.md)
- [Dependencies](../../dependencies.md)
- [Operations and processes](../../operations-processes.md)
- [Business rules](../../business-rules.md)
- [Database tables](../../database-tables.md)
- [SQL catalog](../../sql/index.md)
- [Procedures](../../procedures/index.md)
- [Security and authorization](../../security-authorization.md)
- [API reference](../index.md)

## Sources
- `Data/SAIF.Data.NHibernate/Repositories/ProvidersRepository.cs`
