TechTalk Genome v4.2

<OneToManyCollection> Element

Defines the property as a one-to-many collection.

<Member name=" property ">
<OneToManyCollection [parentReference="parent-reference-property"] [ trackReference="true|false" ] [orderBy="order-by-clause"] />
</Member>
property
A property name specifying a property of type Collection<T> , representing the collection of a one-to-many (1:n) association.
parent-reference-property
The name of the property implementing the parent reference in the one-to-many association. If this is omitted, Genome tries to deduce parent-reference-property from the property types found in the associated type. If the associated type declares more than one reference to the current type, parent-reference-property has to be specified explicitly.
trackReference
If true or omitted, the updates of the parent-reference-property are tracked to update the appropriate collections automatically. If false, then setting the parent-reference-property does not affect any of the collections.
order-by-clause
Specifies the order of the items when enumerating the collection. The order-by-clause uses the same syntax as the OrderBy OQL method.

Remarks

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.

Examples

                      
  <Type name="Cage">

      <Member name="Inhabitants">
          <OneToManyCollection
              trackReference="true"
              parentReference="Cage"
              orderBy="[Name ascending]" />
      </Member>
      
  </Type>
              

Requirements

Type: TechTalk.Genome.Mapping.OneToManyCollectionXmlData

Assembly: TechTalk.Genome.dll

Version: 4.2.11

Editions: Professional, Evaluation, Express

Database Platforms: Microsoft SQL Server 2000, Microsoft SQL Server 2005, Oracle 9i Release 2, Oracle 10g Release 2

See Also

<ManyToManyCollection> Element | <NearObjectReference> Element | Member Mappings