Search code examples
servicestackormlite-servicestack

Composite Index In Servicestack.Ormlite


Is there a way to create a composite non-unique index in Servicestack's implementation of Ormlite?

For example, a single index that would cover both Field1 and Field2 in that order.

public class Poco
{
    [AutoIncrement]
    public int Id { get; set; }
    ...

    public string Field1 { get; set; }
    public string Field2 { get; set; }
}

Solution

  • You can use the CompositeIndexAttribute, e.g:

    [CompositeIndex("Field1", "Field2")]
    public class Poco
    {
        [AutoIncrement]
        public int Id { get; set; }
    
        public string Field1 { get; set; }
        public string Field2 { get; set; }
    }