Versions Compared


  • This line was added.
  • This line was removed.
  • Formatting was changed.

Each anonymous type can be described with a DataType description. A DataType description is an instance, containing strict (and compact) definition of the anonymous type. An anonymous type and its DataType description are isomorphic - each anonymous type has one description and each description has one anonymous type. An anonymous type can be restored from its description; a description can be restored from its anonymous type.


Anonymous Type

DataType description









Dictionary<int, string>

DataType.Dictionary(DataType.Int32, DataType.String)

Slots<int, string, double>

DataType.Slots(DataType.Int32, DataType.String, DataType.Double)

Slots<Slots<int, string>, double>

DataType.Slots(DataType.Slots(DataType.Int32, DataType.String), DataType.Double)

Dictionary<int[], Slots<DateTime, String>

DataType.Dictionary(DataType.Array(DataType.Int32), DataType.Slots(DataType.DateTime, DataType.String))

Note that not only the anonymous types can have DataType descriptions – each STSdb 4.0 supported type can be described with DataType description (not all types - only supported by the engine). Unlike the anonymous types, the user types and their descriptions are not isomorphic - if we have a description we cannot recover the original user type (unless if it is anonymous).

Each table, no matter portable or direct, stores two descriptions - for the key and for the record. The descriptions are stored in the table descriptor (table meta-info). The DataType descriptions make possible opening a table with different but equivalent user types. The descriptions are used for internal checks, for fast and compact serialization and deserialization of the user types, for easy describing and querying the sub-types etc. In short, the DataType description is an anonymous definition of the supported database .NET type.

When the user opens a table with anonymous types he must provide key and record DataType descriptions:

Highlight c sharp
    ITable<IData, IData> table = engine.OpenXTablePortable("table1", DataType.Int64, DataType.Slots(DataType.String, DataType.DateTime, DataType.Double));

The above line will create a non-generic portable table with key type long and record type Slots<string, DateTimedouble> (a record with 3 primitive fields). Adding a record will look like:

Highlight c sharp
    IData key = new Data<long>(7);
    IData record = new Data<Slots<string, DateTime, double>(new Slots<string,DateTime,double>("EURUSD", DateTime.Now, 1.3615));
    table[key] = record;

When the user opens a table directly with his types, he does not need to provide key and record descriptions – they are internally created from the provided user types and are kept in the table’s descriptor.

For example, if we create a direct table with user type Tick:

Highlight c sharp
public class Tick
    public string Symbol { get; set; }
    public DateTime Timestamp { get; set; }
    public double Price { get; set; }
Highlight c sharp
    ITable<long, Tick> table = engine.OpenXTable<long, Tick>("table2");

Along with the original types – long and Tick, the table’s descriptor will keep the auto created DataType descriptors for the keys and for the records:

Highlight c sharp
    DataType.Slots(DataType.String, DataType.DateTime, DataType.Double)

Next prev