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 the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.