Skip to main content

This is documentation for Caché & Ensemble. See the InterSystems IRIS version of this content.Opens in a new tab

For information on migrating to InterSystems IRISOpens in a new tab, see Why Migrate to InterSystems IRIS?

コレクション : リレーションシップ

このコード例では、複数の子オブジェクトに反復処理を行っています。Provider.ContactPhoneNumbers プロパティは、RelationshipObject プロパティです。これは、指定した Contact インスタンスの子である Provider.PhoneNumber インスタンスが含まれたコレクションです。また、このコードでは、using 文を使用して、オブジェクトに関連付けられたリソースが解放されるようにしています。


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

次のコードでは、Provider.PhoneNumber を開き、Contact プロパティを使用して、その親である Provider.Contact にアクセスしています。


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

上記の例のどちらの場合も、cnCache は、開いている CacheConnection インスタンスを表します。

FeedbackOpens in a new tab