Defines the property as a one-to-many collection.
A one-to-many (1:n) association between two persistent classes is typically stored as a foreign key in the "child" table to the "parent" table. The foreign key itself can be abstracted as an object reference from the child type to the parent type, which can be mapped with the <NearObjectReference> element . Seeing the same association from the other direction, the parent has a collection of associated child objects.
The <OneToManyCollection> element is used to map the collection of type Collection<T> in a 1:n association to the database. The add and remove operations of the collection are implemented by setting the parent references of the child objects accordingly. If a child object is removed from the collection, its parent reference is set to null, but the child object is not deleted. If the association is to be a composite aggregation, the child object must be explicitly deleted. However, if a child object is deleted, it is automatically also removed from the collection(s).
If the <OneToManyCollection> element is used for an association, it is recommended to declare the parent reference as read-only (without a property setter). This approach explicitly expresses on the interface that the association is maintained though the collection. However, you can still choose to implement the parent reference setter. If trackReference is enabled, updates of the parent reference are tracked by Genome and the corresponding child collections are automatically updated. Reference tracking is enabled by default.
If the order-by-clause is specified for a collection, items are returned in the specified order when enumerating the collection. When populating the collection, Genome retrieves the items in the specified order from the database. Moreover, the order of the items is maintained even if the collection is changed in the context, e.g. when new objects are added to the collection. This process, however, requires client side evaluation of the order clause for the items, so it is advisable to use simple order expressions (e.g. direct persistent fields) in the order clause.
<Type name="Cage"> <Member name="Inhabitants"> <OneToManyCollection trackReference="true" parentReference="Cage" orderBy="[Name ascending]" /> </Member> </Type>
Editions: Professional, Evaluation, Express
Database Platforms: Microsoft SQL Server 2000, Microsoft SQL Server 2005, Oracle 9i Release 2, Oracle 10g Release 2