ComponentOne True DataControl 8.0
One-to-One Links

In many cases, two data sources have common "ID" fields, but different "detail" fields. For example, suppose that an inventory database contains ProductID and Quantity fields, and a product database contains ProductID, Name, and UnitPrice fields. Since each inventory record has exactly one counterpart in the product database, this is commonly known as a one-to-one relationship.

In a database context, such relationships are best implemented using SQL multi-table joins. However, since True DataControl can manage non-SQL data sources, including memory-resident data, it supports one-to-one links between two TData controls. Setting up a one-to-one link is similar to setting up a master-detail relationship.

IMPORTANT: For performance reasons, the use of one-to-one links between TData controls in data source mode is discouraged, as SQL JOINs accomplish the same result with far greater efficiency. However, one-to-one links are ideal for memory-based data sources, as demonstrated in Tutorial 13.

In a one-to-one link, a dependent TData control always has at most one record for each record of its master control. Under such circumstances, you can add linked fields to the master control, associating a linked field in master control with a field in the dependent control (linked control). Linked fields appear in the master’s records along with "normal" data and calculated fields; they can participate in expressions and can even be modified. A TData control can have multiple linked controls.

One-to-one links are unavailable in the Lite version.

Creating a one-to-one link involves the following steps:

  1. Create a special TData control and declare it to be a linked control by setting its LinkType property to 1 - Outer or 2 - Inner (the default setting is 0 - None), and its Master property to the name of the principal TData control.

  2. Set up a master-detail relationship using range conditions, dynamic SQL with parameters, or filter conditions. Make sure that the linked control has at most one record for each master record. (If that is not true, True DataControl will simply take the first record and ignore all the rest.)

  3. Add linked fields to the master TData control and associate each linked field with a field of the linked TData control. See LinkedControl,LinkedField properties in Field properties.

A linked control cannot be used as an independent TData control because it is managed in all respects by its master control. This means that data-aware controls cannot be bound to it. If you set the LinkType property of a TData control to a value other than 0 - None, the functionality of the control will be restricted accordingly. For example, all of its fields must be data fields, not calculated or linked fields. In essence, a linked TData control is an addition to its master control.

An outer link allows master records for which there is no corresponding record in the linked control. In this case, all linked fields are empty and cannot be modified. An inner link filters out such master records, excluding them from the recordset. These terms are consistent with the definitions of outer and inner joins in SQL.

 

 


Copyright (c) GrapeCity, inc. All rights reserved.

Product Support Forum  |  Documentation Feedback