C# applications use the
new
operator to instantiate an object and the assignment operator to modify the objects values. To create the database store of the object the Connection methodInsert()
is called within a transaction. For example:[Persistent] // Class Record will be stored in eXtremeDB database class Record { [Indexable(Unique=true)] // Create unique (tree) eXtremeDB index by "id" field public int id; public String str; } ... Connection con = new Connection(db); con.StartTransaction(Database.TransactionType.ReadWrite); // Start RW transaction Record rec = new Record(); rec.id = 3; rec.str = "Record 3"; con.Insert(rec); con.CommitTransaction();To update an object, it is first found with a Cursor navigation, then its fields are modified and the Cursor method
Update()
is called with the object handle. For example:cursor = new Cursor<Record>(con, "id"); // find record with id == 3 rec = cursor.Find(3); rec.str = "Updated string"; cursor.Update(); cursor.Close(); //release cursor con.CommitTransaction();To delete an object from the database, the object is first found with a Cursor navigation, then the Cursor method
Remove()
is called with the object handle. For example:cursor = new Cursor<Record>(con, "id"); // find record with id == 3 rec = cursor.Find(3); cursor.Remove(); // remove current object (pointed to by the cursor) cursor.Close(); //release cursor con.CommitTransaction();Nullable Fields
A C# class field can be explicitly declared nullable with the
[Nullable]
attribute, or using with the standard question mark ( eg.int? i;
) syntax. For example:class Record { [Indexable(Unique=true)] // Create unique (tree) eXtremeDB index by "id" field public int id; public int? age; [Nullable] public int weight; }Here both fields age and weight may have
null
values.Please see the Nullable Fields and Indexes page for an explanation of the behavior of nullable fields included in indexes.
Strings and Arrays
The
Length
property ofString
fields can be used to determine their actual size in bytes. Also, sincevectors
(aka dynamic arrays) in eXtremeDB are simply declared with the native language array syntax, the field'sLength
property gives the number ofvector
elements.In C# applications, the elements of
vector
(array) fields are accessed using the normal array element operator[]
and specifying the index of the desired element.Blob Support
C# applications use the
[Blob]
field attribute to define a BLOB field.Date, Time and Datetime Fields
Please refer to the Datetime FIelds page for a detailed description of the eXtremeDB
date
,time
anddatetime
database field types. The C# APIs for determining precision and accessingdate
,time
anddatetime
fields are described in the Managing Datetime Fields in C# page.