To provide further integration with your application it is possible to create your own class to store and retrieve data from a user defined type. The advantage of this is that it is possible to hide indexing of the user defined class within the class.
Suppose the user defined class and table have the following definitions:
create type address as (street varchar(30), streetnumber integer);
create table person(personid int, home address);
A class that wraps this user defined type looks as follows:
public class myaddress : MimerUserDefinedType
{
//
// Constructor to create an empty instance of the type
//
public myaddress() : base(2)
{
}
//
// Constructor to create an instance with values of the type. The actual data
// is stored by the base class
//
public myaddress(string street, int streetno) : base(new object[] { street, streetno })
{
}
//
// Property to set and get the street name
//
public string street
{
get { return (string) base[0]; }
set { base[0] = value; }
}
//
// Property to set and get the street number
//
public int streetno
{
get { return (int) base[1]; }
set { base[1] = value; }
}
}
The example highlights a number of things:
MimerConnection conn = new MimerConnection(connectionString);
try {
conn.Open();
MimerCommand comm1 = new MimerCommand("select * from person", conn);
//
// Create an instance of the wrapper class
//
myaddress myaddr = new myaddress();
MimerDataReader reader = comm1.ExecuteReader();
while (reader.Read()) {
int personsId = reader.GetInt32(0);
reader.GetUserDefinedType(1, myaddr);
//
// We can access each part of the user defined type through the properties
//
string streetname = myaddr.street;
int streetnum = myaddr.streetno;
//
// Work with data...
//
}
reader.Close();
In the example an instance of the myaddress class is passed into the MimerDataReader.GetUserDefinedType(Int32,Object) method. The values in the database are passed into the class when this happens.