Skip to main content

This is documentation for Caché & Ensemble.

For information on converting to InterSystems IRISOpens in a new window, see the InterSystems IRIS Migration Guide and Migrating to InterSystems IRIS, both available on the WRC Distributions pageOpens in a new window (login required).

Collections: Relationships

The following code example demonstrates iterating through a set of child objects. The PhoneNumbers property of Provider.Contact is a RelationshipObject property. It is a collection containing the Provider.PhoneNumber instances that are children of the specified Contact instance. Note that the code uses the using statement to ensure that resources associated with the objects are freed.


try
{
 Provider.Contact contact = Provider.Contact.OpenId(cnCache, "1");
 foreach (Provider.PhoneNumber pn in contact.PhoneNumbers) using(pn)
 {
   Console.WriteLine("Type {0}: Number {1}", pn.PhoneNumberType, pn.Number);
 }
}
catch (CacheException e){}
Copy code to clipboard

The following code opens an Provider.PhoneNumber and then accesses its Provider.Contact parent using the Contact property.


try
{
  Provider.PhoneNumber pn = Provider.PhoneNumber.OpenId(cnCache, "1||3");
  Provider.Contact contact = pn.Contact;
  Console.WriteLine("Parent ID is {0}", contact.Id());
}
catch (CacheException e){}
Copy code to clipboard

In both of the above examples cnCache represents an open CacheConnection instance.

FeedbackOpens in a new window