ComponentOne DataObjects for .NET
Creating and Modifying a Simple Relation
DataObjects for .NET (Enterprise Edition) > Schema Objects > Simple Relations > Creating and Modifying a Simple Relation

When you import database structure to a schema, C1DataObjects Import Wizard automatically creates simple relations for you based on foreign key information in the database. After the initial step of importing the database structure, you can delete redundant relations, create new relations and modify the existing relations.

To create a new simple relation, press the Add button or select Add from the context menu in the Relations window, which will create an empty relation and open it for editing in a new Relation Editor page.


The Relation Editor has two panes. The top pane contains the relation properties, the bottom pane contains Join Conditions defining the relation (such as Customers.CustomerID = Orders.OrderID).

Set the relation's Name either by setting the Name property or by renaming the newly added node in the Relations window.

Set the Parent property by selecting a simple table from the list of all simple tables available in the schema. Set the Child property by selecting a simple table from the list of all simple tables. Note that if you select a composite table for either Parent or Child, the relation will automatically become composite relations, which will be apparent by the elimination of the bottom panel, Join Conditions, which are not applicable to composite relations.

When creating a simple relation, it is your responsibility to assign the correct value to the Cardinality property, that determines whether this relation is one-to-one or one-to-many. DataObjects for .NET relies on and makes extensive use of relation cardinality, and it cannot derive its value from other relation properties, unless for relations it creates while importing structure from the database.

The recommended practice is to define all your simple relations as one-to-many (but make sure they are really one-to-many, DataObjects for .NET cannot check this). For example, if you need a relation between Customers and Orders, you may be uncertain as to which table to choose as parent and which as child. Both choices are possible, only Cardinality value depends on the choice. We recommend to make the choice that leaves Cardinality at one-to-many. So, in our example, Customers is the Parent, and Orders is the Child.

If you have a Customers – Orders relation, there is no need to define the inverse relation, Orders – Customers. In your code, you can always navigate in both directions, from parent to child and from child to parent. When you use this relation in a diagram (in Composite Tables or in Data Sets) to specify view relations, you can use it in direct or inverse direction, as needed.

The last step in defining a simple relation is specifying its join conditions, equalities connecting parent fields with child fields. For each parent/child field you need one join condition. To add a join condition, press the Add button or select Add from the context menu in the Join Conditions pane.


Then, in the properties grid on the right, select the ParentField and ChildField for this join condition.