13.07.2015 Views

Using the Caché Managed Provider for .NET - InterSystems ...

Using the Caché Managed Provider for .NET - InterSystems ...

Using the Caché Managed Provider for .NET - InterSystems ...

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>Using</strong> Proxy Objects5.3 <strong>Using</strong> Proxy Objects<strong>Caché</strong> proxy objects can be used to per<strong>for</strong>m most of <strong>the</strong> standard operations on instances in a database.This section describes how to open and read an instance, how to create or delete instances, and howto alter and save existing instances.5.3.1 Opening and Reading ObjectsUse <strong>the</strong> OpenId() method to access an instance by ID (instances can also be accessed through SQLqueries, as discussed later in <strong>Using</strong> <strong>Caché</strong> Queries). OpenId() is a static class method, qualified with<strong>the</strong> type name ra<strong>the</strong>r than an instance name:Sample.Person person = Sample.Person.OpenId(CacheConnect, "1");Once <strong>the</strong> object has been instantiated, you can use standard dot notation to read and write <strong>the</strong> personin<strong>for</strong>mation:string Name = person.Namestring ID = person.Id();person.Home.City = "Smallville";person.Home.State = "MN";In this example, person.Home is actually an embedded Sample.Address object. It is automaticallycreated or destroyed along with <strong>the</strong> Sample.Person object.For a working example, see <strong>the</strong> Proxy_1_ReadObject() method in <strong>the</strong> bookdemos sample program(see The <strong>Caché</strong> .<strong>NET</strong> Sample Programs).5.3.2 Creating and Saving Objects<strong>Caché</strong> proxy object constructors use in<strong>for</strong>mation in a CacheConnection object to create a link between<strong>the</strong> proxy object and a corresponding object on <strong>the</strong> <strong>Caché</strong> server:Sample.Person person = new Sample.Person(CacheConnect);person.Name = "Luthor, Lexus A.";person.SSN = "999-45-6789";Use <strong>the</strong> Save() method to create a persistent instance in <strong>the</strong> database. Once <strong>the</strong> instance has been saved,<strong>the</strong> Id() method can be used to get <strong>the</strong> newly generated ID number:CacheStatus sc = person.Save();Display.WriteLine("Save status: " + sc.IsOK.ToString());string ID = person.Id();Display.WriteLine("Saved id: " + person.Id());The ExistsId() class method can be used to test whe<strong>the</strong>r or not an instance exists in <strong>the</strong> database:<strong>Using</strong> <strong>the</strong> <strong>Caché</strong> <strong>Managed</strong> <strong>Provider</strong> <strong>for</strong> .<strong>NET</strong> 37

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!