Mapping associations

Association between two classes is a very simple concept to understand. If you want to have association between ClassA and ClassB, then you can add a property of type ClassB on ClassA. This is the most basic form of association.

Associations come in four different forms as described next:

  • One-to-many: One end of the association has single instance of the entity while the other end has multiple instances. In code, this is represented by a property of the Collection type. For example, IList<T>, [], ICollection<T> ,IEnumerable<T>. and so on
  • Many-to-one: Opposite of one-to-many.
  • One-to-one: Both ends of associations have one single instance of entities.
  • Many-to-many: Both ends of associations have multiple instances of entities.

Get Learning NHibernate 4 now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.