Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
NHibernate 4.x Cookbook
NHibernate 4.x Cookbook

NHibernate 4.x Cookbook: Over 90 incredible and powerful recipes to help you efficiently use NHibernate in your application , Second Edition

Arrow left icon
Profile Icon Jason Dentler Profile Icon Zaytsev Profile Icon Darshan Joshi Profile Icon Liljas
Arrow right icon
$54.99
Full star icon Full star icon Full star icon Full star icon Full star icon 5 (1 Ratings)
Paperback Jan 2017 448 pages 2nd Edition
eBook
$29.99 $43.99
Paperback
$54.99
Subscription
Free Trial
Renews at $19.99p/m
Arrow left icon
Profile Icon Jason Dentler Profile Icon Zaytsev Profile Icon Darshan Joshi Profile Icon Liljas
Arrow right icon
$54.99
Full star icon Full star icon Full star icon Full star icon Full star icon 5 (1 Ratings)
Paperback Jan 2017 448 pages 2nd Edition
eBook
$29.99 $43.99
Paperback
$54.99
Subscription
Free Trial
Renews at $19.99p/m
eBook
$29.99 $43.99
Paperback
$54.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Shipping Address

Billing Address

Shipping Methods
Table of content icon View table of contents Preview book icon Preview Book

NHibernate 4.x Cookbook

Chapter 2. Models and Mappings

In this chapter, we will cover the following topics:

  • 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
  • Mappings enumerations
  • Immutable entities
  • Mapping relations to non-primary keys
  • Using lazy properties
  • Mapping joins
  • Using calculated properties
  • Using serializable values
  • Dynamic components
  • Mapping <subselect>

Mapping a class with XML

The suggested first step in any new NHibernate application is mapping the model. The mapping describes how objects O should be retrieved and stored as relational data R in the database. In the simplest scenarios, this is merely a straightforward mapping between classes in the code and tables in the database. Still, the structure of the code or of the database will usually require careful mapping in order to get correct behavior and optimal performance.

Note

Most of the recipes in this chapter utilize a custom library called NH4CookbookHelpers, which makes it possible to visualize the results and behaviors of the mappings described. For convenience, we use NuGet to reference this library, but feel free to download the source code from https://github.com/gliljas/NH4CookbookHelpers if you want to modify its functionality or just see how it works.

Getting ready

Before we begin mapping, let's get our Visual Studio solution set up. Follow these steps to set up your...

Creating class hierarchy mappings

It's common to have an inheritance hierarchy of subclasses. In this example, we will show you one method for mapping inheritance with NHibernate, called table-per-class hierarchy.

Getting ready

Complete the previous Mapping a class with XML example.

How to do it…

  1. Create a new class named Book with the following code:
    namespace Eg.Core
    {
      public class Book : Product
      {
    
        public virtual string ISBN { get; set; }
        public virtual string Author { get; set; }
    
      }
    }
  2. Create a new class named Movie with the following code:
    namespace Eg.Core
    {
      public class Movie : Product 
      {
    
        public virtual string Director { get; set; }
    
      }
    }
  3. Change the Product mapping to match the XML shown in the following code:
    <?xml version="1.0" encoding="utf-8" ?>
    <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
        assembly="Eg.Core"
        namespace="Eg.Core">
      <class name="Product">
      ...

Creating class components

There are cases where a set of properties are used repeatedly. These properties may even have their own business logic, but they do not represent an entity in your application. They are value objects. In this recipe, we will tell you how to separate these properties and business logic into a component class without creating a separate entity.

Getting ready

Complete the Getting ready instructions at the beginning of this chapter.

How to do it…

  1. Add a folder named Components to the MappingRecipes project.
  2. In the folder, add an Address class with the following properties:
    public virtual Guid Id { get; protected set; }
    public virtual string Lines { get; set; }
    public virtual string City { get; set; }
    public virtual string State { get; set; }
    public virtual string ZipCode { get; set; }
  3. Add a Customer class with the following properties:
    public virtual string Name { get; set; }
    public virtual Address BillingAddress { get; set; }
    public virtual Address ShippingAddress ...

Mapping a one-to-many relationship

It's usually necessary to relate an entity to other entities. For example, an order can be related to many order lines and to a customer. In this example, we'll show you how to map a one-to-many relationship between Movie and a new entity class, ActorRole.

Getting ready

Complete the previous Creating class hierarchy mappings recipe.

How to do it…

  1. In Eg.Core, create a new class named ActorRole with the following code:
    namespace Eg.Core
    {
      public class ActorRole : Entity 
      {
    
        public virtual string Actor { get; set; }
        public virtual string Role { get; set; }
    
      }
    }
  2. Create an embedded resource mapping for ActorRole with the following XML:
    <?xml version="1.0" encoding="utf-8" ?>
    <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
        assembly="Eg.Core"
        namespace="Eg.Core">
      <class name="ActorRole">
        <id name="Id">
          <generator class...

Mapping a many-to-many relationship

A student often attends many classes and hopefully every class is attended by more than one student. This type of relationship is called many-to-many and in a relational database, an intermediate table usually represents it, with at least two columns referencing the keys of the participating entities.

NHibernate supports many-to-many relationships and does so without having to expose the intermediate table to the code.

Getting ready

Complete the Getting ready instructions at the beginning of this chapter.

How to do it…

  1. Create a new folder named ManyToMany in the MappingRecipes project.
  2. Add a new class Student to the folder:
    public class Student
    {
        public virtual Guid Id { get; protected set; }
        public virtual string Name { get; set; }
    }
  3. Create an embedded resource mapping named Student.hbm.xml (in the same folder) with the following XML:
    <?xml version="1.0" encoding="utf-8" ?>
    <hibernate-mapping xmlns="urn:nhibernate...

Mapping collections of elements and components

So far, we've shown how to use collections where an entity relates to a set of other entitities. However, a collection can also hold simple values, such as strings or components, that is, objects with properties but no id.

Getting ready

Complete the Getting ready instructions at the beginning of this chapter.

How to do it…

  1. Add a new folder named ComponentCollections to the MappingRecipes project.
  2. Add a new class named Customer to the folder:
    public class Customer
    {
        public Customer()
        {
            Addresses=new List<Address>();
            Tags=new HashSet<string>();
        }
        public virtual Guid Id { get; protected set; }
        public virtual string Name { get; set; }
        public virtual IList<Address> Addresses { get; set; }
        public virtual ISet<string> Tags { get; set; }
    }
  3. Add a new class named Address to the folder:
    public class Address
    {
        public string AddressLine1 { get; set; }
        public string AddressLine2...

Mapping a class with XML


The suggested first step in any new NHibernate application is mapping the model. The mapping describes how objects O should be retrieved and stored as relational data R in the database. In the simplest scenarios, this is merely a straightforward mapping between classes in the code and tables in the database. Still, the structure of the code or of the database will usually require careful mapping in order to get correct behavior and optimal performance.

Note

Most of the recipes in this chapter utilize a custom library called NH4CookbookHelpers, which makes it possible to visualize the results and behaviors of the mappings described. For convenience, we use NuGet to reference this library, but feel free to download the source code from https://github.com/gliljas/NH4CookbookHelpers if you want to modify its functionality or just see how it works.

Getting ready

Before we begin mapping, let's get our Visual Studio solution set up. Follow these steps to set up your solution...

Creating class hierarchy mappings


It's common to have an inheritance hierarchy of subclasses. In this example, we will show you one method for mapping inheritance with NHibernate, called table-per-class hierarchy.

Getting ready

Complete the previous Mapping a class with XML example.

How to do it…

  1. Create a new class named Book with the following code:

    namespace Eg.Core
    {
      public class Book : Product
      {
    
        public virtual string ISBN { get; set; }
        public virtual string Author { get; set; }
    
      }
    }
  2. Create a new class named Movie with the following code:

    namespace Eg.Core
    {
      public class Movie : Product 
      {
    
        public virtual string Director { get; set; }
    
      }
    }
  3. Change the Product mapping to match the XML shown in the following code:

    <?xml version="1.0" encoding="utf-8" ?>
    <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
        assembly="Eg.Core"
        namespace="Eg.Core">
      <class name="Product">
        <id name="Id">
          <generator class="guid.comb" />
        &lt...

Creating class components


There are cases where a set of properties are used repeatedly. These properties may even have their own business logic, but they do not represent an entity in your application. They are value objects. In this recipe, we will tell you how to separate these properties and business logic into a component class without creating a separate entity.

Getting ready

Complete the Getting ready instructions at the beginning of this chapter.

How to do it…

  1. Add a folder named Components to the MappingRecipes project.

  2. In the folder, add an Address class with the following properties:

    public virtual Guid Id { get; protected set; }
    public virtual string Lines { get; set; }
    public virtual string City { get; set; }
    public virtual string State { get; set; }
    public virtual string ZipCode { get; set; }
  3. Add a Customer class with the following properties:

    public virtual string Name { get; set; }
    public virtual Address BillingAddress { get; set; }
    public virtual Address ShippingAddress { get; set...

Mapping a one-to-many relationship


It's usually necessary to relate an entity to other entities. For example, an order can be related to many order lines and to a customer. In this example, we'll show you how to map a one-to-many relationship between Movie and a new entity class, ActorRole.

Getting ready

Complete the previous Creating class hierarchy mappings recipe.

How to do it…

  1. In Eg.Core, create a new class named ActorRole with the following code:

    namespace Eg.Core
    {
      public class ActorRole : Entity 
      {
    
        public virtual string Actor { get; set; }
        public virtual string Role { get; set; }
    
      }
    }
  2. Create an embedded resource mapping for ActorRole with the following XML:

    <?xml version="1.0" encoding="utf-8" ?>
    <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
        assembly="Eg.Core"
        namespace="Eg.Core">
      <class name="ActorRole">
        <id name="Id">
          <generator class="guid.comb" />
        </id>
        <property name="Actor" not-null="true" /&gt...

Mapping a many-to-many relationship


A student often attends many classes and hopefully every class is attended by more than one student. This type of relationship is called many-to-many and in a relational database, an intermediate table usually represents it, with at least two columns referencing the keys of the participating entities.

NHibernate supports many-to-many relationships and does so without having to expose the intermediate table to the code.

Getting ready

Complete the Getting ready instructions at the beginning of this chapter.

How to do it…

  1. Create a new folder named ManyToMany in the MappingRecipes project.

  2. Add a new class Student to the folder:

    public class Student
    {
        public virtual Guid Id { get; protected set; }
        public virtual string Name { get; set; }
    }
  3. Create an embedded resource mapping named Student.hbm.xml (in the same folder) with the following XML:

    <?xml version="1.0" encoding="utf-8" ?>
    <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
        assembly="MappingRecipes...

Mapping collections of elements and components


So far, we've shown how to use collections where an entity relates to a set of other entitities. However, a collection can also hold simple values, such as strings or components, that is, objects with properties but no id.

Getting ready

Complete the Getting ready instructions at the beginning of this chapter.

How to do it…

  1. Add a new folder named ComponentCollections to the MappingRecipes project.

  2. Add a new class named Customer to the folder:

    public class Customer
    {
        public Customer()
        {
            Addresses=new List<Address>();
            Tags=new HashSet<string>();
        }
        public virtual Guid Id { get; protected set; }
        public virtual string Name { get; set; }
        public virtual IList<Address> Addresses { get; set; }
        public virtual ISet<string> Tags { get; set; }
    }
  3. Add a new class named Address to the folder:

    public class Address
    {
        public string AddressLine1 { get; set; }
        public string AddressLine2 { get; set...

Setting up a base entity class


In this recipe, we'll show how to set up a base class for your entities. The purpose of this class is to provide base implementations of potentially tricky Equals and GetHashCode methods.

How to do it…

  1. We create a base class, where the type of Id is specified using a generic argument, as shown:

    public abstract class Entity<TId>
    {
    
      public virtual TId Id { get; protected set; }
    
      public override bool Equals(object obj)
      {
        return Equals(obj as Entity<TId>);
      }
    
      private static bool IsTransient(Entity<TId> obj)
      {
        return obj != null &&
               Equals(obj.Id, default(TId));
      }
    
      private Type GetUnproxiedType()
      {
        return GetType();
      }
    
      public virtual bool Equals(Entity<TId> other)
      {
        if (other == null)
          return false;
    
        if (ReferenceEquals(this, other))
          return true;
    
        if (!IsTransient(this) &&
            !IsTransient(other) &&
            Equals(Id, other.Id))
        {
          var otherType...

Handling versioning and concurrency


For any multiuser transactional system, you must decide how to handle concurrent updates and possible versioning issues. In this recipe, we will show you how to set up versioning and optimistic concurrency with NHibernate.

Getting ready

Complete the Getting ready instructions at the beginning of this chapter.

How to do it…

  1. Add a new folder named Versioning to the MappingRecipes project.

  2. Add a new class named VersionedProduct to the folder:

    public class VersionedProduct
    {
        public virtual int Id { get; protected set; }
        public virtual int Version { get; protected set; }
        public virtual string Name { get; set; }public virtual string Description { get; set; }}
  3. Add an embedded mapping named VersionProduct.hbm.xml:

    <?xml version="1.0" encoding="utf-8" ?>
    <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
        assembly="MappingRecipes"
        namespace="MappingRecipes.Versioning">
        <class name="VersionedProduct">
            <id name="Id"...

Mapping by code


XML files have been NHibernate's default approach to mapping since its inception. It's a platform neutral, flexible and easily parsed format. The mapping syntax for Java's Hibernate is virtually identical to NHibernate's.

NHibernate also allows you to specify the mappings using nothing but code. This gives us a couple of advantages, since the mapping code gets intricately connected to the classes it should map. There is no risk of misspelled class or property names and you can use runtime logic to customize the mappings.

Getting ready

Complete the Getting ready instructions given at the beginning of this chapter.

The recipe uses the entity classes that we created in Eg.Core in the preceding recipes of this chapter. However, for convenience, NH4CookbookHelpers also provide the same class model and we will use that model here. Feel free to modify the code (changing the using statements) to use Eg.Core, if that suits you better. You may have to add a version property (integer) to...

Mapping by convention


In large object models, you will notice that many aspects of the mappings are repetitive. Maybe the Comb generator should generate all POIDs or all properties referencing a class without an Id property should be treated as a component mapping. By setting up mapping conventions, you can potentially avoid all explicit mappings and instead let the code structure do the work for you.

Getting ready

Complete the Getting ready instructions at the beginning of this chapter.

How to do it…

  1. Add a folder named MappingByConvention to the MappingRecipes project.

  2. Add a class named MyModelMapper to the folder:

    using System.Collections.Generic;
    using System.Linq;
    using System.Reflection;
    using NH4CookbookHelpers.Mapping.Model;
    using NHibernate.Mapping.ByCode;
    
    namespace MappingRecipes.MappingByConvention
    {
      public class MyModelMapper : ConventionModelMapper
      {
        public MyModelMapper()
        {
          IsEntity((t, declared) => 
            typeof(Entity).IsAssignableFrom(t) && 
       ...

Creating mappings fluently


Even before NHibernate added the possibility to provide mappings in code, the Fluent NHibernate project (FNH) delivered a strongly-typed, fluent syntax, as an alternative to XML mappings. It remains very popular and many NHibernate articles online show examples using FNH mappings. In this recipe, we will show you how to map our product model using Fluent NHibernate.

Getting ready

Complete the Getting ready instructions at the beginning of this chapter.

How to do it…

  1. Add a new folder named MappingWithFluent to the MappingRecipes project.

  2. Add a reference to the FluentNHibernate package using Nuget package manager console.

  3. Create a new class named ProductMap with the following code:

    using NH4CookbookHelpers.Mapping.Model;
    using FluentNHibernate.Mapping;
    
    
    namespace MappingRecipes.MappingWithFluent
    {
     public class ProductMap : ClassMap<Product>
     {
      public ProductMap()
      {
       Id(p => p.Id).GeneratedBy.GuidComb();
       Version(x => x.Version);
       NaturalId().Property...

Bidirectional one-to-many class relationships


It's often very useful to have a bidirectional relationship between entities. It also simplifies matters for NHibernate, which can often produce more efficient persistence queries when both sides of a relationship are involved.

In this recipe, we will show you how to set up a bidirectional one-to-many relationship between two entity classes.

How to do it…

  1. Add a new folder named Bidirectional to the MappingRecipes project.

  2. Add the following Order class:

    public class Order
    {
      private ISet<OrderItem> _items;
      private ISet<Project> _projects;
    
      public virtual Guid Id { get; protected set; }
    
      public Order()
      {
        _items = new HashSet<OrderItem>();
        _projects = new HashSet<Project>();
      }
    
    
      public virtual IEnumerable<OrderItem> Items
      {
        get
        {
          return _items;
        }
      }
    
      public virtual IEnumerable<Project> Projects
      {
        get
        {
          return _projects;
        }
      }
    
      public virtual bool AddItem...

Mapping enumerations


An improperly mapped enumeration can lead to unnecessary updates. In this recipe, we'll discuss why and show you how to map an enumeration property to a string field.

How to do it…

  1. Add a new folder named Enumerations to the MappingRecipes project.

  2. Add the following AccountTypes enum to the folder:

    public enum AccountTypes
    {
      Consumer,
      Business,
      Corporate,
      NonProfit
    }
  3. Add the following Account class:

    public class Account
    {  
      public virtual Guid Id { get; set; }
      public virtual AccountTypes AcctType { get; set; }
      public virtual string Number { get; set; }
      public virtual string Name { get; set; }
    }
  4. Add an embedded NHibernate mapping document named Account.hbm.xml with the following class mapping:

    <class name="Account">
      <id name="Id">
        <generator class="guid.comb" />
      </id>
      <natural-id>
        <property name="Number" not-null="true"  />
      </natural-id>
      <property name="Name" not-null="true" />
      <property name...

Immutable entities


An immutable entity is an entity that never changes once it has been created. An example could be entries in event log. New log entries may be added all the time; however, once saved, they are not supposed to be modified.

This behavior could of course be enforced in code, or perhaps even in the database, but if we tell NHibernate to treat specific classes as immutable, we can both enforce the immutability and allow NHibernate optimize performance a bit.

Getting ready

Complete the Getting ready instructions at the beginning of this chapter.

How to do it…

  1. Add a new folder named ImmutableEntities to the MappingRecipes project.

  2. Add a new class named LogEntry to the folder:

    using System;
    
    namespace MappingRecipes.ImmutableEntities
    {
      public class LogEntry
      {
        public virtual Guid Id { get; protected set; }
        public virtual string Message { get; set; }
      }
    }
  3. Add a new embedded mapping named LogEntry.hbm.xml to the folder:

    <?xml version="1.0" encoding="utf-8" ?>
    <hibernate...

Mapping relations to non-primary keys


In legacy databases, sometimes data is stored in ways that doesn't quite map to an object model. One such scenario is when the relation between for example a Customer and its ContactPersons is controlled by a column other than the primary key in the Customer table. NHibernate provides a way to handle these relations, using the property-ref mapping attribute.

Getting ready

Complete the Getting ready instructions at the beginning of this chapter.

How to do it…

  1. Add a new folder named PropertyRefs to the MappingRecipes project.

  2. Add a class named Customer to the folder:

    using System.Collections.Generic;
    
    namespace MappingRecipes.PropertyRefs
    {
      public class Customer
      {
        public Customer()
        {
          ContactPersons=new HashSet<ContactPerson>();
        }
        public virtual int Id { get; protected set; }
        public virtual string Name { get; set; }
        public virtual ISet<ContactPerson> ContactPersons 
     { 
       get; 
       set; 
     }
        public virtual int...
Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Master the full range of NHibernate features through detailed example recipes that you can quickly apply to your own applications
  • Reduce hours of application development time and get a better application architecture and improved performance
  • Create, maintain, and update your database structure automatically with the help of NHibernate

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.

Who is this book for?

This book is written for .NET developers who want to use NHibernate and those who want to deepen their knowledge of the platform. Examples are written in C# and XML. Some basic knowledge of SQL is assumed. If you build .NET applications that use relational databases, this book is for you.

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
Estimated delivery fee Deliver to Argentina

Standard delivery 10 - 13 business days

$12.95

Premium delivery 3 - 6 business days

$40.95
(Includes tracking information)

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Jan 31, 2017
Length: 448 pages
Edition : 2nd
Language : English
ISBN-13 : 9781784396428
Category :
Tools :

What do you get with Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Shipping Address

Billing Address

Shipping Methods
Estimated delivery fee Deliver to Argentina

Standard delivery 10 - 13 business days

$12.95

Premium delivery 3 - 6 business days

$40.95
(Includes tracking information)

Product Details

Publication date : Jan 31, 2017
Length: 448 pages
Edition : 2nd
Language : English
ISBN-13 : 9781784396428
Category :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total $ 153.97
NHibernate 4.x Cookbook
$54.99
Learning NHibernate 4
$54.99
.NET Design Patterns
$43.99
Total $ 153.97 Stars icon
Banner background image

Table of Contents

10 Chapters
1. The Configuration and Schema Chevron down icon Chevron up icon
2. Models and Mappings Chevron down icon Chevron up icon
3. Sessions and Transactions Chevron down icon Chevron up icon
4. Queries Chevron down icon Chevron up icon
5. Improving Performance Chevron down icon Chevron up icon
6. Testing Chevron down icon Chevron up icon
7. Data Access Layer Chevron down icon Chevron up icon
8. Extending NHibernate Chevron down icon Chevron up icon
9. NHibernate Contribution Projects Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Full star icon Full star icon 5
(1 Ratings)
5 star 100%
4 star 0%
3 star 0%
2 star 0%
1 star 0%
codemuncher Jan 02, 2021
Full star icon Full star icon Full star icon Full star icon Full star icon 5
If your looking to learn about nhibernate this a great book and it gives most examples in both XML and c# code. It covers a variety of basic and advanced subjects and I fully recommend it
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is the delivery time and cost of print book? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela
What is custom duty/charge? Chevron down icon Chevron up icon

Customs duty are charges levied on goods when they cross international borders. It is a tax that is imposed on imported goods. These duties are charged by special authorities and bodies created by local governments and are meant to protect local industries, economies, and businesses.

Do I have to pay customs charges for the print book order? Chevron down icon Chevron up icon

The orders shipped to the countries that are listed under EU27 will not bear custom charges. They are paid by Packt as part of the order.

List of EU27 countries: www.gov.uk/eu-eea:

A custom duty or localized taxes may be applicable on the shipment and would be charged by the recipient country outside of the EU27 which should be paid by the customer and these duties are not included in the shipping charges been charged on the order.

How do I know my custom duty charges? Chevron down icon Chevron up icon

The amount of duty payable varies greatly depending on the imported goods, the country of origin and several other factors like the total invoice amount or dimensions like weight, and other such criteria applicable in your country.

For example:

  • If you live in Mexico, and the declared value of your ordered items is over $ 50, for you to receive a package, you will have to pay additional import tax of 19% which will be $ 9.50 to the courier service.
  • Whereas if you live in Turkey, and the declared value of your ordered items is over € 22, for you to receive a package, you will have to pay additional import tax of 18% which will be € 3.96 to the courier service.
How can I cancel my order? Chevron down icon Chevron up icon

Cancellation Policy for Published Printed Books:

You can cancel any order within 1 hour of placing the order. Simply contact [email protected] with your order details or payment transaction id. If your order has already started the shipment process, we will do our best to stop it. However, if it is already on the way to you then when you receive it, you can contact us at [email protected] using the returns and refund process.

Please understand that Packt Publishing cannot provide refunds or cancel any order except for the cases described in our Return Policy (i.e. Packt Publishing agrees to replace your printed book because it arrives damaged or material defect in book), Packt Publishing will not accept returns.

What is your returns and refunds policy? Chevron down icon Chevron up icon

Return Policy:

We want you to be happy with your purchase from Packtpub.com. We will not hassle you with returning print books to us. If the print book you receive from us is incorrect, damaged, doesn't work or is unacceptably late, please contact Customer Relations Team on [email protected] with the order number and issue details as explained below:

  1. If you ordered (eBook, Video or Print Book) incorrectly or accidentally, please contact Customer Relations Team on [email protected] within one hour of placing the order and we will replace/refund you the item cost.
  2. Sadly, if your eBook or Video file is faulty or a fault occurs during the eBook or Video being made available to you, i.e. during download then you should contact Customer Relations Team within 14 days of purchase on [email protected] who will be able to resolve this issue for you.
  3. You will have a choice of replacement or refund of the problem items.(damaged, defective or incorrect)
  4. Once Customer Care Team confirms that you will be refunded, you should receive the refund within 10 to 12 working days.
  5. If you are only requesting a refund of one book from a multiple order, then we will refund you the appropriate single item.
  6. Where the items were shipped under a free shipping offer, there will be no shipping costs to refund.

On the off chance your printed book arrives damaged, with book material defect, contact our Customer Relation Team on [email protected] within 14 days of receipt of the book with appropriate evidence of damage and we will work with you to secure a replacement copy, if necessary. Please note that each printed book you order from us is individually made by Packt's professional book-printing partner which is on a print-on-demand basis.

What tax is charged? Chevron down icon Chevron up icon

Currently, no tax is charged on the purchase of any print book (subject to change based on the laws and regulations). A localized VAT fee is charged only to our European and UK customers on eBooks, Video and subscriptions that they buy. GST is charged to Indian customers for eBooks and video purchases.

What payment methods can I use? Chevron down icon Chevron up icon

You can pay with the following card types:

  1. Visa Debit
  2. Visa Credit
  3. MasterCard
  4. PayPal
What is the delivery time and cost of print books? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela