See collection matching in the reference documentation. There are several ways to map an IList property.
A bag is an unordered, non-indexed collection that may contain the same item several times.
<bag name="Transactions" lazy="true" table="Transaction" > <key column="OrderId"/> <one-to-many class="Transaction"/> </bag>
A set is an unordered, unindexed set containing unique elements.
<set name="Transactions" lazy="true" table="Transaction" > <key column="OrderId"/> <one-to-many class="Transaction"/> </set>
A list is an ordered and indexed collection that can contain the same item multiple times.
<list name="Transactions" lazy="true" table="Transaction" > <key column="OrderId"/> <index column="ordering"/> <one-to-many class="Transaction"/> </list>
NHibernate can return unordered collections in sorted order using the sort attribute.
No discussion of the collection in which we are assembled mentions a cascade . This allows you to perform operations on the parent for collection objects.
- It usually doesn't make sense to include a cascade in the associations
<many-to-one> or <many-to-many> . The cascade is often useful for the associations <one-to-one> and <one-to-many> . - If the lifetime of the child is limited by the life of the parent, make it a lifecycle object by specifying cascade = "all-delete-orphan".
- Otherwise, you may not need a cascade. But if you think that you will often work with a parent and children together in the same transaction, and you want to keep some typing for yourself, consider using cascade = "persist, merge, save-update"
source share