Database Schema Definition in C#

As explained in the C# Quick Start, the C# API uses the C# class syntax, with attributes. At run-time, C# reflection is used to discover the classes with their attributes and build up an eXtremeDB database dictionary. Note that the attribute[Persistent] marks a C# class to be managed by the eXtremeDB runtime in an In-Memory Database. (If the database is to be stored on persistent storage, the attribute modifier [Persistent(disk=true)] must be added.)

Note that whether objects are stored in-memory or on-disk (where “disk” means a file system, regardless of the physical media) is a function of these properties (i.e. the C# class definition) and the Database.Parameter specification used when calling Database.Open(). The logic is as follows:

A similar set of rules apply to attribute [Persistent(large)] and [Persistent(compact)] and the related property Parameters.compactClassesByDefault.

The classes defined to be managed by eXtremeDB are passed into the runtime as an array of objects of the class Class (see next section). C# classes that are not passed into the runtime but are referenced within database classes will be treated as eXtremeDB structure fields.

Please refer to the C# Schema Reference Guide for detailed explanations of the usage of C# attributes to define the Database, Class, Field and Index characteristics.

Persistent Databases

For persistent database applications the database classes are defined exactly as for in-memory databases except for the class attribute [Persistent(Disk=true)] for all classes that will be stored on persistent media. For example:

 
    [Persistent(Disk=true)] 
    class Obj
    {
        public int i4;
    };
     

If all classes are to be stored on persistent media, an alternative is to use the Database.Parameters property DiskClassesByDefault for the parameters passed to the Database method Open(). For example:

 
    Database.Parameters parameters = new Database.Parameters();
    parameters.Classes = new Type[] { typeof(Obj) };
    ...
    parameters.DiskClassesByDefault = true;
            
    ...