---
title: Repository&lt;TEntity&gt;
summary: API reference for Repository<TEntity>.
status: draft
owner: Framework
last_reviewed: 2026-09-15
library: SAIF.Framework.Data.NHibernate
reference_type: package
---

# Repository&lt;TEntity&gt;

`Repository<TEntity>` is the concrete, constructible generic repository returned by `NHibernateUnitOfWork.GetRepository<TEntity>()`. It adds only a constructor to `RepositoryBase<TEntity>`, binding the repository to the `Session`/`SessionHelper` of the `NHibernateUnitOfWork` instance that created it.

## Purpose
- Provides the constructor consumers (indirectly, via `NHibernateUnitOfWork.GetRepository<TEntity>()`) use to obtain a working repository for any mapped entity type `TEntity`.
- Binds itself to exactly one `NHibernateUnitOfWork`'s session for its entire lifetime, per [BR-005](../../business-rules.md#br-005-repository-is-scoped-to-one-unit-of-work).

## Context
- Namespace: `SAIF.Data.NHibernate`
- Assembly/package: `SAIF.Framework.Data.NHibernate`

## Public members
| Member | Signature | Purpose |
| --- | --- | --- |
| Repository(unitOfWork) | `public Repository(NHibernateUnitOfWork unitOfWork)` | Constructs a repository bound to `unitOfWork.Session` and `unitOfWork.SessionHelper`; called by `NHibernateUnitOfWork.GetRepository<TEntity>()` on every invocation. |

## Inherited public members

Members in this section are inherited from `RepositoryBase<TEntity>` in `SAIF.Framework.Data.NHibernate`. They are available on this type through inheritance.

| Member | Signature | Purpose | Origin |
| --- | --- | --- | --- |
| Add | `public void Add(TEntity entity)` | Delegates to `Session.Add(entity)`: stateful strategy calls `ISession.SaveOrUpdate(entity)`; stateless strategy calls `IStatelessSession.Insert(entity)`. | `SAIF.Framework.Data.NHibernate` — `RepositoryBase<TEntity>` |
| Update | `public void Update(TEntity entity)` | Delegates to `Session.Update(entity)`; no-op under the stateful strategy, explicit write under the stateless strategy. See [BR-003](../../business-rules.md#br-003-stateless-updates-require-explicit-persistence). | `SAIF.Framework.Data.NHibernate` — `RepositoryBase<TEntity>` |
| Delete | `public void Delete(TEntity entity)` | Delegates to `Session.Delete(entity)` in both session strategies. | `SAIF.Framework.Data.NHibernate` — `RepositoryBase<TEntity>` |
| Query | `public IQueryable<TEntity> Query()` | Delegates to `Session.Query<TEntity>()` (LINQ to NHibernate) in both session strategies. | `SAIF.Framework.Data.NHibernate` — `RepositoryBase<TEntity>` |
| Get | `public TEntity Get(object id)` | Stateful: `ISession.Get<TEntity>(id)`. Stateless: `IStatelessSession.Get<TEntity>(id)`. | `SAIF.Framework.Data.NHibernate` — `RepositoryBase<TEntity>` |
| Load | `public TEntity Load(object id)` | Stateful: `ISession.Load<TEntity>(id)` (lazy proxy). Stateless: delegates to `IStatelessSession.Get<TEntity>(id)` (no lazy proxy). | `SAIF.Framework.Data.NHibernate` — `RepositoryBase<TEntity>` |
| SystemDate | `public DateTime SystemDate { get; }` | Server "now" via `SessionHelper.SystemDate`, with a local-clock fallback. See [BR-004](../../business-rules.md#br-004-systemdate-falls-back-to-local-clock). | `SAIF.Framework.Data.NHibernate` — `RepositoryBase<TEntity>` |

## Behavioral notes
- `Repository<TEntity>` adds no behavior of its own beyond construction; all CRUD/query behavior — including the stateful/stateless divergence — comes from `RepositoryBase<TEntity>`.
- `ImageRepositoryExtensions` casts `IRepository<Image>`/`IRepository<ImageSystem>`/`IRepository<ImageAffiliation>` down to this concrete `Repository<T>` type to reach its internal `Session` for direct SQL sequence queries — see [ImageRepositoryExtensions](../SAIF.Data.NHibernate.Repositories.Imaging/ImageRepositoryExtensions.md).*

## Constraints and usage notes
- Instances are created only by `NHibernateUnitOfWork.GetRepository<TEntity>()`; there is no factory or DI-friendly abstraction for constructing a `Repository<TEntity>` independently of a unit of work.

> **Note:** Statements marked with * were inferred from code structure, naming conventions, or
> contextual evidence where direct confirmation was not available in source artifacts.

## Sources
- `Repositories/Repository.cs`
- `Repositories/RepositoryBase.cs`
- `UnitOfWork/NHibernateUnitOfWork.cs`
