Often times in the course of developing or maintaining a project, the scope will change and you will have to change your object definitions to accommodate new data. Fortunately, Siaqodb handles object changes without much input from the developer. Typical changes that Siaqodb can handle are adding and removing fields.

Adding New Fields


For example, we will use the Company class from the getting started tutorial:

public class Company
{
    public int OID { get; set; }
    public string Name { get; set; }
    public string Address { get; set; }
    public string Phone { get; set; }   
}
and we have stored our objects:
Siaqodb siaqodb = new Siaqodb ("[path]");
Company company = new Company();
company.Name = "MyCompany";
company.Address = "1 Test Way";
company.Phone = "302-365-5385";
siaqodb.StoreObject(company);


Our application has been running for some time and has many 'Company' records, but now the users need some new fields to be added. This is not a problem! Simply change your object definition to add the new fields that are required:
public class Company
{
    public int OID { get; set; }
    public string Name { get; set; }
    public string Address { get; set; }
    public string Phone { get; set; }   

    public string CellPhone { get; set; }
    public string Fax { get; set; }
}


Now that the new fields CellPhone and Fax have been added, we can run our application (against an existing database) and the new fields will be set to default values.
foreach (var company in (from c in siaqodb select c))
{
    company.Name; // Existing field: will be the value we set previously "MyCompany"
    company.CellPhone; // New field: will be default value; "" for string.
    company.CellPhone = "302-555-5555";  // set the new field value
    siaqodb.StoreObject(company);  // new and old values will be stored properly
}


Removing Fields

The same is true for removing fields. If we wanted to remove the Phone field from our object, simply remove the field and it will be gone! Be warned though that if you remove a field and run your application, the data that was stored in that field will truely be done and cannot be recovered!
public class Company
{
    public int OID { get; set; }
    public string Name { get; set; }
    public string Address { get; set; }
    //public string Phone { get; set; }  // Field removed; next load query will not load this field

    public string CellPhone { get; set; }
    public string Fax { get; set; }
}


Unsupported Migrations

Unfortunately, some types of changes are not handled automatically in Siaqodb. When an object is changed in an unsupported way, you will receive the runtime exception TypeChangedException. The following changes cannot be handled automatically, however we offer some suggestions in order to handle the migrations manually.

Type Change
You cannot change the type of an object member (for example, from string to int). We suggest you create a new object member instead. If you must use the value in your new object member, you can simply create a custom get method to help convert the object:
public class Company
{
    public string Phone { get; set; }  // existing field that we want to be an int now

    private int? _iphone;
    public int IntPhone
    {
        get
        {
            if(!_iphone.HasValue)
            {
                try
                {
                    _iphone = Convert.ToInt32(this.Phone);
                }
                catch { }
            }
            return _iphone;
        }

        set 
        {
            _iphone = value;
        }
    }
}


String Lengths
From the supported types page, Siaqodb stores strings either as fixed character type or a variable length text block. The default length for fixed character Fields is 100 characters. You cannot change the MaxLength or Text attributes of strings after they have been stored in the database. We suggest you create a new member instead and again, possibly copy the old member down when calling 'get' on that member in order to have a smooth migration.