NHibernate 4.x Cookbook - Second Edition

Over 90 incredible and powerful recipes to help you efficiently use NHibernate in your application
Preview in Mapt

NHibernate 4.x Cookbook - Second Edition

Gunnar Liljas, Alexander Zaytsev, Jason Dentler

Over 90 incredible and powerful recipes to help you efficiently use NHibernate in your application
Mapt Subscription
FREE
$29.99/m after trial
eBook
$10.00
RRP $39.99
Save 74%
Print + eBook
$49.99
RRP $49.99
What do I get with a Mapt Pro subscription?
  • Unlimited access to all Packt’s 5,000+ eBooks and Videos
  • Early Access content, Progress Tracking, and Assessments
  • 1 Free eBook or Video to download and keep every month after trial
What do I get with an eBook?
  • Download this book in EPUB, PDF, MOBI formats
  • DRM FREE - read and interact with your content when you want, where you want, and how you want
  • Access this title in the Mapt reader
What do I get with Print & eBook?
  • Get a paperback copy of the book delivered to you
  • Download this book in EPUB, PDF, MOBI formats
  • DRM FREE - read and interact with your content when you want, where you want, and how you want
  • Access this title in the Mapt reader
What do I get with a Video?
  • Download this Video course in MP4 format
  • DRM FREE - read and interact with your content when you want, where you want, and how you want
  • Access this title in the Mapt reader
$0.00
$10.00
$49.99
$29.99 p/m after trial
RRP $39.99
RRP $49.99
Subscription
eBook
Print + eBook
Start 30 Day Trial

Frequently bought together


NHibernate 4.x Cookbook - Second Edition Book Cover
NHibernate 4.x Cookbook - Second Edition
$ 39.99
$ 10.00
Data Visualization with D3 4.x Cookbook - Second Edition Book Cover
Data Visualization with D3 4.x Cookbook - Second Edition
$ 35.99
$ 10.00
Buy 2 for $20.00
Save $55.98
Add to Cart

Book Details

ISBN 139781784396428
Paperback448 pages

Book Description

NHibernate is a mature, 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. NHibernate allows you to use plain SQL and stored procedures less and keep focus on your application logic instead. Learning the best practices for a NHibernate-based application will help you avoid problems and ensure that your project is a success.

The book will take you from the absolute basics of NHibernate through to its most advanced features, showing you how to take full advantage of each concept to quickly create amazing database applications. You will learn several techniques for each of the four core NHibernate tasks—configuration, mapping, session and 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 by the end of the book.

You will also 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 features, you will learn creative ways to extend the NHibernate core, as well as gaining techniques to work with the NHibernate search, shards, spatial, envers, and validation projects.

Table of Contents

Chapter 1: The Configuration and Schema
Introduction
Installing NHibernate
Configuring NHibernate with hibernate.cfg.xml
Configuring NHibernate with App.config or Web.config
Configuring NHibernate with code
Configuring NHibernate with Fluent NHibernate
Configuring NHibernate logging
Generating the database
Scripting the database
Updating the database
Using NHibernate schema tool
Chapter 2: Models and Mappings
Mapping a class with XML
Creating class hierarchy mappings
Creating class components
Mapping a one-to-many relationship
Mapping a many-to-many relationship
Mapping collections of elements and components
Setting up a base entity class
Handling versioning and concurrency
Mapping by code
Mapping by convention
Creating mappings fluently
Bidirectional one-to-many class relationships
Mapping enumerations
Immutable entities
Mapping relations to non-primary keys
Using lazy properties
Mapping joins
Using calculated properties
Using serializable values
Dynamic components
Mapping <subselect>
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
Save entities to the database
Using session.Merge
Using session.Refresh
Handle concurrency using session.Lock
There's more…
Using dictionaries as entities
Using NHibernate with transaction scope
Chapter 4: Queries
Introduction
Query entities by ID
Using LINQ to NHibernate
Using CriteriaQueries
Using QueryOver
Using QueryOver projections and aggregates
Using the Hibernate Query Language
Using native SQL
Eager loading with LINQ
Eager loading with Criteria
Eager loading with QueryOver
Eager loading with HQL
Eager loading with SQL
Using named queries
Using detached queries
Using HQL for bulk data changes
Filtering collections
Using result transformers
Extra lazy collections
Chapter 5: Improving Performance
Reducing application startup time
Using MultiCriteria
Using MultiQuery
Using Futures
Eager loading child collections
Using stateless sessions
Using read-only entities
Use the second-level cache
Configuring the second-level cache with code
Sharding databases for performance
Chapter 6: Testing
Introduction
Using NHibernate Profiler
Profiling NHibernate with Glimpse
Fast testing with the SQLite in-memory database
Preloading data with SQLite
Using Fluent NHibernate persistence testing
Using the Ghostbusters test
Chapter 7: 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 8: Extending NHibernate
Introduction
Creating an encrypted string type
Creating a money type
Using well-known instance types
Using dependency injection with entities
Creating an audit-event listener
Creation and change stamping of entities
Generating trigger-based auditing
Implementing a soft-delete pattern
Setting Microsoft SQL's Context_Info
Using dynamic connection strings
Using custom dialect functions
Using custom functions in LINQ
Extending the LINQ provider
Chapter 9: NHibernate Contribution Projects
Introduction
Property validation with attributes
Creating validator classes
Setting up full-text searches
Auditing data with Envers
Using NHibernate Spatial

What You Will Learn

  • Create a persistent object model to move 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
  • 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
  • Implement entity validation, auditing, full-text search, horizontal partitioning (sharding), and spatial queries using NHibernate Contrib projects

Authors

Table of Contents

Chapter 1: The Configuration and Schema
Introduction
Installing NHibernate
Configuring NHibernate with hibernate.cfg.xml
Configuring NHibernate with App.config or Web.config
Configuring NHibernate with code
Configuring NHibernate with Fluent NHibernate
Configuring NHibernate logging
Generating the database
Scripting the database
Updating the database
Using NHibernate schema tool
Chapter 2: Models and Mappings
Mapping a class with XML
Creating class hierarchy mappings
Creating class components
Mapping a one-to-many relationship
Mapping a many-to-many relationship
Mapping collections of elements and components
Setting up a base entity class
Handling versioning and concurrency
Mapping by code
Mapping by convention
Creating mappings fluently
Bidirectional one-to-many class relationships
Mapping enumerations
Immutable entities
Mapping relations to non-primary keys
Using lazy properties
Mapping joins
Using calculated properties
Using serializable values
Dynamic components
Mapping <subselect>
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
Save entities to the database
Using session.Merge
Using session.Refresh
Handle concurrency using session.Lock
There's more…
Using dictionaries as entities
Using NHibernate with transaction scope
Chapter 4: Queries
Introduction
Query entities by ID
Using LINQ to NHibernate
Using CriteriaQueries
Using QueryOver
Using QueryOver projections and aggregates
Using the Hibernate Query Language
Using native SQL
Eager loading with LINQ
Eager loading with Criteria
Eager loading with QueryOver
Eager loading with HQL
Eager loading with SQL
Using named queries
Using detached queries
Using HQL for bulk data changes
Filtering collections
Using result transformers
Extra lazy collections
Chapter 5: Improving Performance
Reducing application startup time
Using MultiCriteria
Using MultiQuery
Using Futures
Eager loading child collections
Using stateless sessions
Using read-only entities
Use the second-level cache
Configuring the second-level cache with code
Sharding databases for performance
Chapter 6: Testing
Introduction
Using NHibernate Profiler
Profiling NHibernate with Glimpse
Fast testing with the SQLite in-memory database
Preloading data with SQLite
Using Fluent NHibernate persistence testing
Using the Ghostbusters test
Chapter 7: 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 8: Extending NHibernate
Introduction
Creating an encrypted string type
Creating a money type
Using well-known instance types
Using dependency injection with entities
Creating an audit-event listener
Creation and change stamping of entities
Generating trigger-based auditing
Implementing a soft-delete pattern
Setting Microsoft SQL's Context_Info
Using dynamic connection strings
Using custom dialect functions
Using custom functions in LINQ
Extending the LINQ provider
Chapter 9: NHibernate Contribution Projects
Introduction
Property validation with attributes
Creating validator classes
Setting up full-text searches
Auditing data with Envers
Using NHibernate Spatial

Book Details

ISBN 139781784396428
Paperback448 pages
Read More

Read More Reviews

Recommended for You

.NET Design Patterns Book Cover
.NET Design Patterns
$ 31.99
$ 10.00
C# 7 and .NET Core: Modern Cross-Platform Development - Second Edition Book Cover
C# 7 and .NET Core: Modern Cross-Platform Development - Second Edition
$ 39.99
$ 10.00
Angular Test-Driven Development - Second Edition Book Cover
Angular Test-Driven Development - Second Edition
$ 31.99
$ 10.00
Multithreading with C# Cookbook - Second Edition Book Cover
Multithreading with C# Cookbook - Second Edition
$ 39.99
$ 10.00
NHibernate 3.0 Cookbook Book Cover
NHibernate 3.0 Cookbook
$ 26.99
$ 10.00
C# 6 and .NET Core 1.0: Modern Cross-Platform Development Book Cover
C# 6 and .NET Core 1.0: Modern Cross-Platform Development
$ 39.99
$ 10.00