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
€18.99 per month
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
€22.99 €32.99
Paperback
€41.99
Subscription
Free Trial
Renews at €18.99p/m
Arrow left icon
Profile Icon Jason Dentler Profile Icon Zaytsev Profile Icon Darshan Joshi Profile Icon Liljas
Arrow right icon
€18.99 per month
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
€22.99 €32.99
Paperback
€41.99
Subscription
Free Trial
Renews at €18.99p/m
eBook
€22.99 €32.99
Paperback
€41.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
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

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 a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

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
€18.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
€189.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
€264.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 116.97
NHibernate 4.x Cookbook
€41.99
Learning NHibernate 4
€41.99
.NET Design Patterns
€32.99
Total 116.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 included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.