---
title: SqlServerUnitOfWorkFactory
summary: API reference for SqlServerUnitOfWorkFactory.
status: draft
owner: Framework
last_reviewed: 2026-09-15
library: SAIF.Framework.Data.NHibernate
reference_type: package
---

# SqlServerUnitOfWorkFactory

`SqlServerUnitOfWorkFactory` is the stateful SQL Server implementation of `UnitOfWorkFactoryBase`. It opens a stateful NHibernate `ISession` against SQL Server and wraps it in `StatefulSessionStrategy`, pairing it with `SqlServerConfigurationFactory` for configuration and `SqlServerSessionHelper` for engine-specific session helper behavior. There is no stateless SQL Server unit-of-work factory in this library.

## Purpose
- Overrides `CreateUnitOfWork` to open a stateful SQL Server `ISession` (`factory.OpenSession()`) and wrap it in `StatefulSessionStrategy`, giving consumers full change-tracking, lazy-loading, and first-level cache behavior.
- Overrides `BuildSessionHelper` to return a `SqlServerSessionHelper`, used for SQL Server-specific ID handling in repository operations.

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

## Public members
| Member | Signature | Purpose |
| --- | --- | --- |
| SqlServerUnitOfWorkFactory() | `public SqlServerUnitOfWorkFactory()` | Default constructor; wires an internal `SqlServerConfigurationFactory` for configuration resolution. |

## Inherited public members

Members in this section are inherited from `UnitOfWorkFactoryBase` in `SAIF.Framework.Data.NHibernate`. They are available on this type through inheritance.

| Member | Signature | Purpose | Origin |
| --- | --- | --- | --- |
| GetUnitOfWork | `NHibernateUnitOfWork GetUnitOfWork(string connectionString, int batchSize, bool showSql)` | Resolves a cached or new `ISessionFactory`, opens a stateful SQL Server session via `CreateUnitOfWork`, and returns a `NHibernateUnitOfWork`. | `SAIF.Framework.Data.NHibernate` — `UnitOfWorkFactoryBase` |

## Behavioral notes
- Every unit of work produced by this factory uses full NHibernate change tracking; entities loaded through it are tracked for flush-time change detection.

## Constraints and usage notes
- Requires a SQL Server-compatible connection string; pairs with `SqlServerConfigurationFactory` internally and cannot be redirected to a different engine's configuration factory.
- Unlike the Oracle path, there is no corresponding stateless SQL Server factory in this library, per the Phase 1 analysis's open question about this asymmetry.*

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

## Sources
- `Factories/SqlServerUnitOfWorkFactory.cs`
- `Factories/UnitOfWorkFactoryBase.cs`
