When creating an association in ECO you are not guaranteed the order in which the objects at the end of the association will be presented. For this reason ECO provides a Boolean "ordered" property on association ends.
When you set Ordered = True in your model and then generate your database, ECO will create an additional column in your database identifying the sequence of the objects.
I have just been creating SalesInvoice / SalesInvoiceLine classes and chose to have an ordered association, basically because it is standard industry practise to identify each line of an Invoice/Order with a sequencial number, making it easily identifyable when discussing it.
It would have been nice if I could have used an OCL derived attribute with an expression similar to this:
this.SalesInvoice.lines->indexOf(self)
but unfortunately OCL doesn't seem to have a way to find the index of an object in a collection, so I had to resort to writing a code-derived attribute.
First I marked the attribute as Derived, and didn't enter any DerivationOCL for it. Then I added a public method to the class with the following signature
public Int32 LineNumberDeriveAndSubscribe(ISubscriber reEvaluateSubscriber, ISubscriber resubscribeSubscriber)
Finally, the code for the attribute had to do the following
- Subscribe to the SalesInvoice property
- The object has no SalesInvoice, return -1
- Subscribe to SalesInvoice.Lines
- Return the index of this object in SalesInvoice.Lines
public Int32 LineNumberDeriveAndSubscribe(ISubscriber reEvaluateSubscriber, ISubscriber resubscribeSubscriber)
{
AsIObject().Properties["SalesInvoice"].SubscribeToValue(resubscribeSubscriber);
if (this.SalesInvoice == null)
return -1;
else
{
SalesInvoice.AsIObject().Properties["Lines"].SubscribeToValue(resubscribeSubscriber);
return this.SalesInvoice.Lines.IndexOf(this) + 1;
}
}
For an explanation of the difference between ReEvaluate and ReSubscribe, take a look at this article.

Delicious
Digg
Google
Yahoo