SAMPLESネームスペースのBasTutorial.Presonクラスに1件追加を行うものです。実行して「Success」と表示されれば成功です。
追加されたデータの確認は、システム管理ポータルの[SQL - SQLの実行」の画面でSQLクエリに「SELECT * FROM BasTutorial.Person」と入力して、「クエリ実行」ボタンを押すことでできます。
また、動作には、ここで行っているCacheのインストールとユーザーの設定が別途必要です。サンプルファイルの「CacheSample\Person.cs」ファイルは、ここでの手順で作成されたファイルです。
あと、簡単にサンプルの説明をします。
「CacheSample\Program.cs」の内容は以下のようになります。
CacheSample\Program.cs
using System;
using InterSystems.Data.CacheClient;
namespace CacheSample
{
class Program
{
static void Main(string[] args)
{
CacheConnection CacheConnect = new CacheConnection();
CacheConnect.ConnectionString = "Server = localhost; "
+ "Port = 1972; " + "Namespace = SAMPLES; "
+ "Password = Sample; " + "User ID = Sample;";
CacheConnect.Open();
CosTutorial.Person person = new CosTutorial.Person(CacheConnect);
try
{
person.DOB = DateTime.Now;
person.Name = "Some person";
person.Phone = "Some phone";
person.Save();
Console.WriteLine("Success");
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
finally
{
person.Close();
CacheConnect.Close();
Console.ReadLine();
}
}
}
}
CacheConnectionは、「lib\InterSystems.Data.CacheClient.dll」のInterSystems.Data.CacheClient.CacheADOConnectionクラスです。
オープンの方法は他のSystem.Data.IDbConnectionの派生クラスと違いはありません。
これをCosTutorial.Personのコンストラクタの引数に渡します。
CosTutorial.Personのプロパティに値を設定してSave関数を実行すれば、データベースに保存されます。
Save関数は、InterSystems.Data.CacheTypes.CachePersistentクラスのものです。