Siaqodb supports indexes for fields and/or automatic properties of primitive/basic types. Indexes ensure very fast retrieval for any given key: O(log n).

There are two ways to define an index:

1. By decorating the field or/and Automatic Property with the Index attribute:

public class Employee
{
    public int OID { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }

    [Index]
    DateTime hireDate;
    public DateTime HireDate
    {
        get { return hireDate; }
        set { hireDate = value; }
    }

    [Index]
    public int Age { get; set; }
}

The Age property and the hireDate field are indexed.

2. By adding indexes through SiaqodbConfigurator:

SiaqodbConfigurator.AddIndex("hireDate", typeof(Employee));
SiaqodbConfigurator.AddIndex("Age", typeof(Employee));

Indexes are detected automatically by Siaqodb's query engine. Once an index is defined, you don't have to do anything special to take advantage of it. For example, the query in the following example uses an indexed field for its where clause and therefore it will be very fast:

var q = from Employee emp in siaqodb
    where emp.Age > 30
    select emp;

Index values do not need to be unique and can accept multiple keys with the same value. Unique index values can be enforced by using the UniqueConstraint attribute, for example:

public class Employee
{
.....
    [Index]
    [UniqueConstraint]
    public Guid InternalID { get; set; }
}

All Employee instances will have Unique values for the indexed InternalID property.

Important: An Index is valid only if it is added to a field and/or to an automatic property. If you have a property with a backing field, be sure you put the index on the field and not on the Property, like in above examples.