The NDORelation attribute

This attribute is for placing information about relations in the source code that are needed by NDO.

Typed list classes have not been available in NET 1.x. If you use non-generic list classes, you have to specify the type of the elements the list contains:

class Employee
{
    // Type of object elements is unknown
    IList travels;
}

This is possible with the NDORelation attribute.

class Employee
{
    [NDORelation(typeof(Travel))]
    // Element objects are of type Travel
    IList travels;
}

A relation is of type association as long as it is not explicitly defined as composition with the help of an additional parameter of type RelationInfo.

class Employee

{

    [NDORelation(typeof(Travel), RelationInfo.Composite)]

    IList travels;

}

1:1-relations have to be marked with the attribute NDORelation, as shown in the following example with the class Address:

class Employee

{

    [NDORelation]
    Address address;

    [NDORelation(typeof(Travel), RelationInfo.Composite)]
    IList travels;

}

Relations are managed by NDO if they are declared using an NDO attribute. This is very powerful. If an object is loaded from the database, the child objects are automatically loaded, too. But the relation management goes even further: For example, if the field of a 1:1 composite relation is overwritten with Null (Nothing in Visual Basic), NDO takes care that the previously referenced object is removed from the database. Further information about this can be found in the chapter Relation Management in NDO.