PacktLib: NHibernate 3.0 Cookbook

NHibernate 3.0 Cookbook


About the Author

About the Reviewers


Models and Mappings


Mapping a class with XML

Creating class hierarchy mappings

Mapping a one-to-many relationship

Setting up a base entity class

Handling versioning and concurrency

Creating mappings fluently

Mapping with ConfORM

Bidirectional one-to-many class relationships

Mappings enumerations

Creating class components

Configuration and Schema


Configuring NHibernate with App.config

Configuring NHibernate with hibernate.cfg.xml

Configuring NHibernate with code

Configuring NHibernate with Fluent NHibernate

Configuring NHibernate using ConfORM Mappings

Configuring NHibernate logging

Reducing application startup time

Generating the database

Scripting the database

Using NHibernate Schema Tool

Sessions and Transactions


Setting up session per web request

Setting up session per presenter

Creating a session ASP.NET MVC action filter

Creating a Transaction ASP.NET MVC action filter

Using the Conversation per Business Transaction pattern

Using session.Merge

Using session.Refresh

Using stateless sessions

Using dictionaries as entities

Using NHibernate with TransactionScope



Using Criteria Queries

Using QueryOver

Using QueryOver projections and aggregates

Using MultiCriteria

Using the Hibernate Query Language

Using MultiQuery

Using Named Queries

Using Futures

Eager loading child collections

Using LINQ to NHibernate

Using Detached Queries

Using HQL for bulk data changes



Using NHibernate Profiler

Fast testing with SQLite in-memory database

Preloading data with SQLite

Using the Fluent NHibernate Persistence Tester

Using the Ghostbusters test

Data Access Layer


Transaction Auto-wrapping for the data access layer

Setting up an NHibernate Repository

Using Named Queries in the data access layer

Using ICriteria in the data access layer

Using Paged Queries in the data access layer

Using LINQ Specifications in the data access layer

Extending NHibernate


Creating an encrypted string type

Using well-known instance type

Using dependency injection with entities

Creating an audit-event listener

Creating and changing stamping entities

Generating trigger-based auditing

Setting MS Sql's Context Info

Using dynamic connection strings

NHibernate Contribution Projects


Configuring the cache

Configuring the cache with code

Property validation with attributes

Creating validator classes

Using the Burrows framework

Setting up full-text search

Sharding databases for performance

Using NHibernate Spatial