You are previewing NHibernate 3.0 Cookbook.
O'Reilly logo
NHibernate 3.0 Cookbook

Book Description

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

  • 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

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

Table of Contents

  1. NHibernate 3.0 Cookbook
    1. Table of Contents
    2. NHibernate 3.0 Cookbook
    3. Credits
    4. About the Author
    5. About the Reviewers
    6. Preface
      1. What this book covers
      2. What you need for this book
      3. Who this book is for
      4. Conventions
      5. Reader feedback
      6. Customer support
        1. Errata
        2. Piracy
        3. Questions
    7. 1. Models and Mappings
      1. Introduction
      2. Mapping a class with XML
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. What happens to these mappings?
          2. Surrogate keys and natural IDs
          3. ID generator selection
          4. See also
      3. Creating class hierarchy mappings
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Table per class
          2. Table per concrete class
          3. See also
      4. Mapping a one-to-many relationship
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Lazy loading collections
          2. Lazy loading proxies
          3. Collections
          4. Bags
          5. Lists
          6. Sets
          7. Map
          8. See also
      5. Setting up a base entity class
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. See also
      6. Handling versioning and concurrency
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Other methods of optimistic concurrency
          2. See also
      7. Creating mappings fluently
        1. Getting ready
        2. How to do it...
        3. How it works...
          1. See also
      8. Mapping with ConfORM
        1. Getting ready
        2. How to do it...
        3. How it works...
          1. See also
      9. Bidirectional one-to-many class relationships
        1. How to do it...
        2. How it works...
        3. There's more...
      10. Mappings enumerations
        1. How to do it...
        2. How it works...
      11. Creating class components
        1. How to do it...
        2. How it works...
    8. 2. Configuration and Schema
      1. Introduction
      2. Configuring NHibernate with App.config
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. NHibernate properties
          2. Dialects and drivers
          3. See also
      3. Configuring NHibernate with hibernate.cfg.xml
        1. Getting ready
        2. How to do it…
        3. How it works…
        4. There's more…
          1. See also
      4. Configuring NHibernate with code
        1. Getting ready
        2. How to do it…
        3. How it works…
        4. There's more...
          1. See also
      5. Configuring NHibernate with Fluent NHibernate
        1. Getting ready
        2. How to do it…
        3. How it works…
          1. See also
      6. Configuring NHibernate using ConfORM Mappings
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. See also
      7. Configuring NHibernate logging
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Using log4net to troubleshoot NHibernate
          2. See also
      8. Reducing application startup time
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
      9. Generating the database
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. See also
      10. Scripting the database
        1. Getting ready
        2. How to do it...
        3. How it works...
          1. See also
      11. Using NHibernate Schema Tool
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. See also
    9. 3. Sessions and Transactions
      1. Introduction
      2. Setting up session per web request
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. See also
      3. Setting up session per presenter
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's More...
          1. See also
      4. Creating a session ASP.NET MVC action filter
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. View models
          2. See also
      5. Creating a Transaction ASP.NET MVC action filter
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
      6. Using the Conversation per Business Transaction pattern
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. See also
      7. Using session.Merge
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. See also
      8. Using session.Refresh
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. See also
      9. Using stateless sessions
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
      10. Using dictionaries as entities
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Partially dynamic
      11. Using NHibernate with TransactionScope
        1. Getting ready
        2. How to do it...
        3. How it works...
          1. See also
    10. 4. Queries
      1. Introduction
      2. Using Criteria Queries
        1. How to do it...
        2. How it works...
        3. There's more...
          1. See also
      3. Using QueryOver
        1. How to do it...
        2. How it works...
        3. There's more...
          1. See also
      4. Using QueryOver projections and aggregates
        1. How to do it...
        2. How it works...
          1. See also
      5. Using MultiCriteria
        1. How to do it...
        2. How it works...
          1. See also
      6. Using the Hibernate Query Language
        1. How to do it...
        2. How it works...
        3. There's more...
          1. See also
      7. Using MultiQuery
        1. How to do it...
        2. How it works...
          1. See also
      8. Using Named Queries
        1. How to do it...
        2. How it works...
        3. There's more...
          1. Named SQL queries
          2. HQL AddIn
          3. See also
      9. Using Futures
        1. How to do it...
        2. How it works...
        3. There's more...
          1. See also
      10. Eager loading child collections
        1. How to do it...
        2. How it works...
        3. There's more...
          1. See also
      11. Using LINQ to NHibernate
        1. How to do it...
        2. How it works...
          1. See also
      12. Using Detached Queries
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. See also
      13. Using HQL for bulk data changes
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Bulk inserts
          2. See also
    11. 5. Testing
      1. Introduction
      2. Using NHibernate Profiler
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. See also
      3. Fast testing with SQLite in-memory database
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. See also
      4. Preloading data with SQLite
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. See also
      5. Using the Fluent NHibernate Persistence Tester
        1. Getting ready
        2. How to do it...
        3. How it works...
          1. See also
      6. Using the Ghostbusters test
        1. Getting ready
        2. How to do it...
        3. How it works...
          1. See also
    12. 6. Data Access Layer
      1. Introduction
      2. Transaction Auto-wrapping for the data access layer
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. See also
      3. Setting up an NHibernate Repository
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. See also
      4. Using Named Queries in the data access layer
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. See also
      5. Using ICriteria in the data access layer
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. See also
      6. Using Paged Queries in the data access layer
        1. Getting ready
        2. How to do it...
        3. How it works...
          1. See also
      7. Using LINQ Specifications in the data access layer
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Specification composition
          2. See also
    13. 7. Extending NHibernate
      1. Introduction
      2. Creating an encrypted string type
        1. How to do it...
        2. How it works...
        3. There's more...
          1. See also
      3. Using well-known instance type
        1. How to do it...
        2. How it works...
          1. See also
      4. Using dependency injection with entities
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Bland passwords need salt
          2. See also
      5. Creating an audit-event listener
        1. How to do it...
        2. How it works...
        3. There's more...
          1. See also
      6. Creating and changing stamping entities
        1. How to do it...
        2. How it works...
          1. See also
      7. Generating trigger-based auditing
        1. Getting ready
        2. How to do it...
        3. How it works...
          1. See also
      8. Setting MS Sql's Context Info
        1. Getting ready
        2. How to do it...
        3. How it works...
          1. See also
      9. Using dynamic connection strings
        1. How to do it...
        2. How it works...
          1. See also
    14. 8. NHibernate Contribution Projects
      1. Introduction
      2. Configuring the cache
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Entity cache
          2. Query cache
          3. Update timestamp cache
          4. The rules
          5. See also
      3. Configuring the cache with code
        1. Getting ready
        2. How to do it...
        3. How it works...
          1. See also
      4. Property validation with attributes
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. See also
      5. Creating validator classes
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. See also
      6. Using the Burrows framework
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. See also
      7. Setting up full-text search
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
      8. Sharding databases for performance
        1. Getting ready
        2. How to do it...
        3. How it works...
      9. Using NHibernate Spatial
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Geography or geometry?
          2. What's this SRID?
          3. Spatial data types
    15. A. Menu
      1. ASP.NET MVC web applications
      2. ASP.NET Web Forms applications
      3. WPF and WinForms applications
    16. Index