Mimer SQL Data Provider help
Selecting user defined type into application class
Mimer SQL Data Provider > Overview > Working with user defined types > Selecting user defined type into application class

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:

  1. The class inherits from MimerUserDefinedType. This is mandatory as ADO.NET uses this class to store and retrieve the actual data.
  2. The constructor without arguments is used when fetching data from database (see below). The call base(2) tells MimerUserDefinedType that the type has two attributes (street and streetnumber).
  3. The class hides the indexing of the user-defined type within the class.
  4. The casting to and from object are also hidden from the rest of the application.

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.

See Also

Basic select
Inserting user defined type from application class