NHibernate 3.0 Cookbook

NHibernate 3.0 Cookbook
eBook: $26.99
Formats: PDF, PacktLib, ePub and Mobi formats
save 15%!
Print + free eBook + free PacktLib access to the book: $71.98    Print cover: $44.99
save 44%!
Free Shipping!
UK, US, Europe and selected countries in Asia.
Also available on:
Table of Contents
Sample Chapters
  • Master the full range of NHibernate features
  • Reduce hours of application development time and get better application architecture and performance
  • Create, maintain, and update your database structure automatically with the help of NHibernate
  • Written and tested for NHibernate 3.0 with input from the development team distilled in to easily accessible concepts and examples
  • Part of Packt's Cookbook series: each recipe is a carefully organized sequence of instructions to complete the task as efficiently as possible


Book Details

Language : English
Paperback : 328 pages [ 235mm x 191mm ]
Release Date : October 2010
ISBN : 184951304X
ISBN 13 : 9781849513043
Author(s) : Jason Dentler
Topics and Technologies : All Books, Application Development, Microsoft Development , Cookbooks, Microsoft, .NET, Open Source

Table of Contents

Chapter 1: Models and Mappings
Chapter 2: Configuration and Schema
Chapter 3: Sessions and Transactions
Chapter 4: Queries
Chapter 5: Testing
Chapter 6: Data Access Layer
Chapter 7: Extending NHibernate
Chapter 8: NHibernate Contribution Projects
Appendix: Menu
  • Chapter 1: Models and Mappings
    • Introduction
    • 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
  • Chapter 2: Configuration and Schema
    • Introduction
    • 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
  • Chapter 3: Sessions and Transactions
    • Introduction
    • 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
  • Chapter 4: Queries
    • Introduction
    • 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
  • Chapter 5: Testing
    • Introduction
    • Using NHibernate Profiler
    • Fast testing with SQLite in-memory database
    • Preloading data with SQLite
    • Using the Fluent NHibernate Persistence Tester
    • Using the Ghostbusters test
  • Chapter 6: Data Access Layer
    • Introduction
    • 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
  • Chapter 7: Extending NHibernate
    • Introduction
    • 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
  • Chapter 8: NHibernate Contribution Projects
    • Introduction
    • 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
  • Appendix: Menu
    • ASP.NET MVC web applications
    • ASP.NET Web Forms applications
    • WPF and WinForms applications

Jason Dentler

Jason Dentler grew up in the small Texas town of Mission Valley. He started tinkering with computers as a kid in the late 1980s, and all these years later, he hasn't stopped. He's worked in a few different industries. Currently, he builds really awesome software in higher education. He's an Eagle Scout and a graduate of the University of Houston – Victoria.

Code Downloads

Download the code and support files for this book.

Submit Errata

Please let us know if you have found any errors not listed on this list by completing our errata submission form. Our editors will check them and add them to this list. Thank you.


- 2 submitted: last submission 21 Jan 2013

Errata type: code | Page number: 282

6th line of the code lacks a “(“, i.e. should be “SetSearchProps(cfg)”.

Errata type: Others | Page number: 244

Given line:Set the dialect to uNHAddIns.Audit.TriggerGenerator. ExtendedMsSql2008Dialect, uNHAddIns"

Correct Line:Set the dialect to uNHAddIns.Audit.TriggerGenerator.Dialects. ExtendedMsSql2008Dialect, uNHAddIns"


Sample chapters

You can view our sample chapters and prefaces of this title on PacktLib or download sample chapters in PDF format.

Frequently bought together

NHibernate 3.0 Cookbook +    Building Dashboards with Microsoft Dynamics GP 2013 and Excel 2013 =
50% Off
the second eBook
Price for both: ₨351.00

Buy both these recommended eBooks together and get 50% off the cheapest eBook.

What you will learn from this book

  • Create a persistent object model for moving data in and out of your database
  • Build the database from your model automatically
  • Configure NHibernate for use with WebForms, MVC, WPF, and WinForms applications
  • Create database queries using a variety of methods, including the new LINQ to NHibernate and QueryOver APIs
  • Build an enterprise-level data access layer
  • Improve the performance of your applications using a variety of techniques
  • Build an infrastructure for fast, easy test-driven development of your data access layer
  • Extend NHibernate to add data encryption and auditing
  • Implement entity validation, full-text search, horizontal partitioning (sharding), and spatial queries using NHibernate Contrib projects

In Detail

NHibernate is an innovative, flexible, scalable, and feature-complete open source project for data access. Although it sounds like an easy task to build and maintain database applications, it can be challenging to get beyond the basics and develop applications that meet your needs perfectly.

The NHibernate Cookbook explains each feature of NHibernate 3.0 in detail through example recipes that you can quickly apply to your applications. Set yourself free from stored procedures and inline SQL. Quite simply, if you build .NET applications that use databases, this book is for you.

The book will take you from the absolute basics of NHibernate through its most advanced features and beyond, showing you how to take full advantage of each concept to quickly create amazing database applications. Beginners will learn several techniques for each of the 4 core NHibernate tasks – mapping, configuration, session & transaction management, and querying – and which techniques fit best with various types of applications. In short, you will be able to build an application using NHibernate. Intermediate level readers will learn how to best implement enterprise application architecture patterns using NHibernate, leading to clean, easy-to-understand code, and increased productivity. In addition to new v3.0 features, advanced readers will learn creative ways to extend NHibernate core, as well as techniques using the NHibernate search, shards, spatial, and validation projects.

Get solutions to common NHibernate problems to develop high-quality performance-critical data access applications


This book contains quick-paced self-explanatory recipes organized in progressive skill levels and functional areas. Each recipe contains step-by-step instructions about everything necessary to execute a particular task. The book is designed so that you can read it from start to end or just open up any chapter and start following the recipes. In short this book is meant to be the ultimate "how-to" reference for NHibernate 3.0, covering every major feature of NHibernate for all experience levels.

Who this book is for

This book is written for NHibernate users at all levels of experience. Examples are written in C# and XML. Some basic knowledge of SQL is assumed.

Code Download and Errata
Packt Anytime, Anywhere
Register Books
Print Upgrades
eBook Downloads
Video Support
Contact Us
Awards Voting Nominations Previous Winners
Judges Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software
Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software