oreilly.comSafari Books Online.Conferences.


AddThis Social Bookmark Button

Object-Oriented Data Programming: C# Meets Caché
Pages: 1, 2, 3, 4, 5, 6, 7, 8, 9

Create a Windows C# project named OreillyCacheDemo. You'll need to install the Caché Object Binding Wizard into your Tools list as explained in the .NET documentation you downloaded for Caché. Run that tool and connect to your database. Choose Source Files, C# and check the Include Subclasses checkbox. To set the Output File name, use the navigation button (small button with ellipsis, indicated with a red arrow in Figure 11) to navigate to your Visual Studio project and name the file CacheClasses.cs. Click the + mark next to User and select every class except Patient (which will be included because you chose Include Subclasses), then click Generate, as shown in Figure 11.

Thumbnail, click for full-size image.
Figure 11. Generating a proxy class--click for full-size image.

Clicking Generate creates the proxy class named CacheClasses.cs in your project. Right-click on your project and choose Add Existing Item to add this proxy class to your project.

Let's start by creating some Routes and Medications so that when you create your Patient you can create Prescriptions that use these objects. To get started, add a menu with the following choices: Create Routes, Create Medications, and Create Patients, as shown in Figure 12.

Adding Menu
Figure 12. Adding a menu

(I've squeezed down my work environment to fit the prescribed width for O'Reilly images.)

Before you can begin, there are a few things you must do. First, you need a reference to the InterSystems.Data.CacheClient.dll that you'll find in the Bin directory of the DotNet directory you downloaded from InterSystems. Second, every form wants to include two using statements:

using InterSystems.Data.CacheClient;
using InterSystems.Data.CacheTypes;

Create a member variable CacheConnection and initialize it to establish the connection to the Caché database:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using InterSystems.Data.CacheClient;
using InterSystems.Data.CacheTypes;

namespace OreillyCacheDemo
    public partial class CacheDemo : Form
        private CacheConnection CacheConnection;

        public CacheDemo()


        private void CreateCacheConnection()
                CacheConnection = new CacheConnection();
                CacheConnection.ConnectionString = 
                    "Server = localhost;"
                   + " Port = 1972;"
                   + " Namespace = USER;"
                   + " Password = SYS;"
                   + " User ID = _system;";
            catch (Exception CacheConnException)
                    "Create Cache Connection failed " + 

For all subsequent forms, you'll pass the existing CacheConnection object into the form constructor, rather than reconnecting.

Create a second form, Add Routes, and add the controls shown in Figure 13:

Add Route Form
Figure 13. Creating the Add Routes form

Pages: 1, 2, 3, 4, 5, 6, 7, 8, 9

Next Pagearrow