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?

新規オブジェクトの作成

ここでは、以下のような .NET のサンプル・コードを扱います。

  1. Provider.Contact の新しいインスタンスを作成します。

  2. 新しい Contact インスタンスの Name プロパティと ContactType プロパティに値を割り当てます。

  3. 新しい Contact インスタンスを保存します。

  4. Save から返される CacheStatus インスタンスを使用して、オブジェクトの保存が成功したかどうかを判断します。

  5. Contact インスタンスが保存されている場合は、新しいオブジェクトの ID 値がコンソールに出力されます。Caché オブジェクトは、最初に保存されたときにのみ、オブジェクト ID を取得します。

  6. Contact インスタンスが保存されなかった場合は、コンソールにエラー・メッセージを出力します。


try
{
    Provider.Contact contact = new Provider.Contact(cnCache);
    contact.Name = "Smith,John";
    contact.ContactType = "Business";
    CacheStatus status = contact.Save();
    if (status.IsOK)
    {
      Console.WriteLine("Id is: {0}" , contact.Id());
    }
    else
    {
      Console.WriteLine("Error creating object");
    }
}
catch (Exception e) { }     
  

cnCache は、開いている CacheConnection インスタンスを表します。

FeedbackOpens in a new tab