O'Reilly logo

NHibernate 4.x Cookbook - Second Edition by Jason Dentler, Alexander Zaytsev, Gunnar Liljas

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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>(); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required