I have a class Contact (base class),a class called Customer and a class called Supplier. Customer and supplier class both derive from Contact.
Customer has a 0..n relation with Order. I want to have a Collection property on customer and have it mapped in NHibernate to its corresponding table.
How is this done in NHibernate (version 2.0.1 GA) ?
(ps: using .NET 3.5 SP1, VS2008 SP1)
This is done like this:
Create your class like this:
in your mapping, you specify this:
Since you use inheritance, you should definitly have a look at the different posibilities regarding inheritance-mapping in NHibernate, and choose the strategy that is best suited for your situation:
inheritance mapping
Regarding set & bag semantics:
– when you map a collection as a set, you can be sure that all the entities in the mapped collection, are unique. That is, NHibernate will make sure that, while reconstituting an instance, the collection will not contain duplicates.
– when you map the collection as a bag, it is possible that your collection will contain the same entity more then once when loading the object from the DB.
objects considered as a whole. A
valid example of a set (of letters)
is: { a, b, c, d }. Each letter
occurs exactly once.
member of a bag can have more than
one membership while each member of a
set has only one membership. A valid
example of a bag is { a, a, a, b, c,
c, d, …}. The letters a and c
appear more than once in the Bag.