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

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> ...

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