2. More About the Object Relational Model
* Virtual Attributes
<< * Early Binding of Related Objects   |   Back to Main   |   * Type Tables >>

View Source
will open in a new window
Non-Table Bound Attributes
Occasionally you may need to create custom database queries which retrieve other columns or values which are not in the table itself. This may be a one-off column in another table, a calculated value, etc.

You can utlize the generated data object to easily retrieve these virtual attributes from the object, itself, as long as you code your custom database query correctly. In short, if you prefix any additional or non-table bound columns with a double-underscore ("__"), the generated object will read in the column as a virtual attribute. You can then use the generated GetVirtualAttribute method to retrieve the value of the data.

In our example below, we create a custom SQL query which uses SQL's COUNT function and subselects to calculate the number of team member for each project.

By utilizing Virtual Attributes, complex queries with calculated values, subselects, etc. can be retrieved in a single database query, and all the values can be stored in the data object, itself.

List All the Projects and Its Team Member Count

ACME Website Redesign has 5 team members.
State College HR System has 6 team members.
Blueman Industrial Site Architecture has 5 team members.
ACME Payment System has 7 team members.