oreilly.comSafari Books Online.Conferences.


AddThis Social Bookmark Button

Object-Oriented Data Programming: C# Meets Caché
Pages: 1, 2, 3, 4, 5, 6, 7, 8, 9

Create a Query for Each Class

For each class we'll add a query that we can use to find every object in the class. Click on the fourth button from the left (as shown highlighted in Figure 5) to create a new query and name it FindAllRoutes. Click on Next twice and then use the buttons to copy both %ID (generated by Caché) and RouteName to the right-hand box. Click Finish, and a query is generated for the class (which will become a method in C#).

Query FindAllRoutes() As %SQLQuery(CONTAINID = 1)
   SELECT %ID,RouteName FROM Route

Continue Adding Classes

To add your second (and subsequent) classes, click on the + sign next to Classes in the Workspace window to expand it, then expand User (to see the Route class). Right-click on User and choose Create New Class as shown in Figure 6.

create new class
Figure 6. Creating another new class

Create the Medication class and give it a string property MedicationName.

Next, create the Prescription class, and add the two string properties Dosage and DispensingInfo. Then add a third property, Route, but when you click Next you'll choose "Relationship" rather than "A single value or type." In C# the Prescription class will have a single object of type Route, but in Caché we'll create a one:one relation between instances of Prescription and instances of Route. On the next page of the wizard, click the radio button indicating that we are creating a one:one relationship, browse to the User.Route object, and name the corresponding property not by choosing an existing property in Route, but by typing in a name for the relationship: PrescriptionToRoute as indicated in Figure 7.

Relationship Wizard
Figure 7. Choosing a one:one relationship

Accept the two selected choices in the next page of the wizard and click Finish. The Prescription class adds a Relationship:

Relationship Route As User.Route [ Cardinality = one, Inverse = PrescriptionToRoute ];

Next we want to create the Person class, and give that class two string properties: Name and PhoneNumber.

Pages: 1, 2, 3, 4, 5, 6, 7, 8, 9

Next Pagearrow