Using .NET and the ADO.NET Managed Provider with Caché
Introduction
|
|
This book describes how to use the
CacheClient .NET assembly, which provides two different but complimentary ways to access Caché from a .NET application:
This combination is unique in that it provides a .NET application with simultaneous relational and object access to data, using a common API and without requiring any object-to-relational mapping. The
CacheClient assembly is implemented using .NET managed code throughout, making it easy to deploy within a .NET environment. It is thread-safe and can be used within multithreaded .NET applications.
This section provides specifies requirements and provides instructions for installing Caché and configuring Visual Studio.
-
The .NET Framework, versions 2.0, 3.0, or 4.0.
-
-
Visual Studio 2008 or 2010. Visual Studio 2010 is required when using .NET 4.0.
Caché is not required on computers that run your Caché .NET client applications, but they must have a TCP/IP connection to the Caché Server and must be running a supported version of the .NET Framework.
-
-
If Caché has been installed with security level 2, open the Management Portal and go to
[System Administration] > [Security] > [Services], select
%Service_CallIn, and make sure the
Service Enabled box is checked. If you installed Caché with security level 1 (minimal) it should already be checked.
All Caché assemblies for .NET are installed to the .NET GAC (Global Assembly Cache) when Caché is installed.
This chapter describes how to set up a Visual Studio project using the
CacheClient assembly, and how to add the Caché Object Binding Wizard to Visual Studio. The following topics are covered:
Configuring a Visual Studio Project
-
-
-
-
Add Using Statements to the Application
using InterSystems.Data.CacheClient;
using InterSystems.Data.CacheTypes;
namespace DotNetSample {
...
}
Adding the Object Binding Wizard to Visual Studio
To add the Caché Object Binding Wizard to the
Tools menu:
-
-
The Caché Object Binding Wizard now will be displayed as an option on the Visual Studio
Tools menu.
The Caché .NET binding gives .NET applications a way to interoperate with objects contained within a Caché server. These objects can be persistent objects stored within the Caché object database or they can be transient objects that perform operations within a Caché server.
The Caché .NET Binding consists of the following components:
-
The Caché Object Server a high performance server process that manages communication between .NET objects and a Caché database server using standard networking protocols (TCP/IP). Caché uses a common server for .NET, C++, Java, Perl, Python, ODBC, and JDBC access.
-
The InterSystems.Data.CacheClient assembly a set of .NET classes that implement all the functionality of the .NET classes created by the Caché Proxy Generator. It also provides a set of proxy classes for a few Object Server classes that are projected differently to make them fit into the framework of the .NET standard library.
-
The Proxy Generator can create .NET proxy classes for any class in the Caché Class Dictionary. The proxy classes contain only managed .NET code, which the Proxy Generator creates by inspecting the class definitions found in the Caché Class Dictionary. Instances of the .NET proxy classes on the client communicate at runtime (using TCP/IP sockets) with their corresponding Caché objects on a Caché server. This is illustrated in the following diagram:
Caché .NET Binding Client/Server Architecture
The basic mechanism works as follows:
-
You define one or more classes within Caché. These can be persistent objects stored within the Caché database or transient objects that run within a Caché server.
-
The Caché Proxy Generator creates .NET proxy classes that correspond to your Caché classes. These classes contain stub methods and properties that correspond to Caché object methods and properties on the server.
-
At runtime, your .NET application connects to a Caché server. It can then create instances of .NET proxy objects that correspond to objects within the Caché server. You can use these proxy objects as you would any other .NET objects. Caché automatically manages all communications as well as client-side data caching.
The runtime architecture consists of the following:
-
A Caché database server (or servers).
-
A .NET client application into which your generated and compiled .NET proxy classes have been linked.
At runtime, the .NET application connects to Caché using an object connection interface (provided by the
CacheConnection class). All communication between the .NET application and the Caché server uses the standard TCP/IP protocol.
-
adoform A simple program to access and manipulate the
Sample.Person database. The same program is presented in three different Visual Studio languages: C#, Basic, and C++.
-
-
console A console program that demonstrates the bare minimum requirements for a Caché .NET project.
-
-
objbind Similar to
adoform, but demonstrates how to write code that uses both ADO.NET Managed Provider classes and Caché Object Binding classes in a complementary fashion.
All of these projects use classes from the
Sample package in the
SAMPLES namespace. You can use Studio to examine the ObjectScript code for these classes.
Note:
Most of these samples are written only in C#. If you decide to convert a sample to Visual Basic, bear in mind that a new Visual Basic .NET project will have a default namespace that contains every class defined by the project. If this is ignored, code such as:
Dim p As New Sample.Person
p = p.OpenId(CacheConnection, "1")
will fail because the root namespace has not been referenced. This can be easily corrected by disabling the "Root namespace" option in the Visual Studio project preferences.