Repository<TEntity>¶
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 typeTEntity. - Binds itself to exactly one
NHibernateUnitOfWork's session for its entire lifetime, per BR-005.
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. |
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. |
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 fromRepositoryBase<TEntity>.ImageRepositoryExtensionscastsIRepository<Image>/IRepository<ImageSystem>/IRepository<ImageAffiliation>down to this concreteRepository<T>type to reach its internalSessionfor direct SQL sequence queries — see ImageRepositoryExtensions.*
Constraints and usage notes¶
- Instances are created only by
NHibernateUnitOfWork.GetRepository<TEntity>(); there is no factory or DI-friendly abstraction for constructing aRepository<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.csRepositories/RepositoryBase.csUnitOfWork/NHibernateUnitOfWork.cs