Free Sample
+ Collection

NHibernate 3.0 Cookbook

Jason Dentler

Get solutions to common NHibernate problems to develop high-quality performance-critical data access applications
RRP $26.99
RRP $44.99
Print + eBook

Want this title & more?

$12.99 p/month

Subscribe to PacktLib

Enjoy full and instant access to over 2000 books and videos – you’ll find everything you need to stay ahead of the curve and make sure you can always get the job done.

Book Details

ISBN 139781849513043
Paperback328 pages

About This Book

  • 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


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.

Table of Contents

Chapter 1: 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
Chapter 2: 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
Chapter 3: 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
Chapter 4: Queries
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
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
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
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
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

What You Will Learn

  • 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.


Read More

Recommended for You