Skip to main content

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){}

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){}

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

FeedbackOpens in a new tab