Object’s Unique ID Mapping AND Disconnected Scenario

 

Each object that is stored in the database is assigned with a unique identification number (UID).

Eloquera database, starting from version 3.1, can automatically map value of the object’s unique ID into user’s field

 

public class SampleClassWithIDField

{

   [ID]

   internal long trueID;

 

   [ID]

   internal string notID;  // This will be ignored

 

   internal long looksLikeID;

       

   // [ID] - Oops, cannot use the attribute here, apply only to a field!

   internal long anotherOne { get; set; }

}

 

In the object above, on query, field trueID will be assigned object’s UID. Never assign manually UID, database takes ownership of the [ID] field.

 

This could be very useful in disconnected scenario      

   

db.OpenDatabase("original");

db.RefreshMode = ObjectRefreshMode.AlwaysReturnUpdatedValues;

 

SampleClassWithIDField someObj = new SampleClassWithIDField() { notID = "Some text here", anotherOne = -322, looksLikeID = 233 };

db.Store(someObj);//store object first time

 

//Any time, from now on, we get SampleClassWithIDField, trueID will contain UID

someObj = (SampleClassWithIDField)db.ExecuteScalar("SELECT SampleClassWithIDField WHERE notID = 'Some text here'");

Assert.AreEqual(db.GetUid(someObj), someObj.trueID);

 

db.Close();

 

 

db.OpenDatabase("original");

db.RefreshMode = ObjectRefreshMode.AlwaysReturnUpdatedValues;

 

someObj.notID = "Some other text"; //Modify object

db.Store(someObj.trueID, someObj);//Update object

 

db.Close();

 

 

db.OpenDatabase("original");

db.RefreshMode = ObjectRefreshMode.AlwaysReturnUpdatedValues;

 

//Whenever we get object back, trueID will contain UID

someObj = (SampleClassWithIDField)db.ExecuteScalar("SELECT SampleClassWithIDField WHERE notID = 'Some other text'");

Assert.AreEqual(db.GetUid(someObj), someObj.trueID);

 

db.Close();