note
VeloxDB is still in beta and APIs are subject to change. We are in the process of completing the documentation, so some sections may be incomplete or empty at this time.
Class HashIndexAttribute
Apply this attribute to a DatabaseObject class to define a hash index.
Inherited Members
Namespace: VeloxDB.ObjectInterface
Assembly: vlxdb.dll
Syntax
public sealed class HashIndexAttribute : IndexAttribute
Remarks
You can use HashIndexAttribute to create a hash index. Hash index allows you to quickly lookup an object using its properties. After you declare an index with HashIndexAttribute use GetHashIndex<T, TKey1>(String) to fetch a HashIndexReader<T, TKey1> which you can use for object lookup.
Hash index can also be used to enforce uniqueness constraint on a property. Use <xref:VeloxDB.ObjectInterface.HashIndexAttribute.IsUnique> to declare that index must be unique.
Support for composite keys is also available, you can specify up to 4 properties to be included in hash index's key.
Note
Hash index defined on a base class will also include all subclasses as well.
Examples
The following example demonstrates how to create a hash index.
[DatabaseClass]
[HashIndex("name", true, nameof(City.Name))]
public abstract class City : DatabaseObject
{
[DatabaseProperty]
public abstract string Name { get; set; }
[DatabaseReference]
public abstract ReferenceArray<WeatherStation> Stations {get; set;}
}
The following example demonstrates how to use a hash index.
HashIndexReader<City, string> reader = om.GetHashIndex<City, string>(nameof(City.Name));
City city = reader.GetObject(name);
if(city == null)
{
// City with given name not found.
return double.NaN;
}
return city.Stations[0].Temperature.Last();
Constructors
HashIndexAttribute(String, Boolean, String[])
Declaration
public HashIndexAttribute(string name, bool isUnique, params string[] properties)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | Index's name |
System.Boolean | isUnique | If true, VeloxDB will enforce hash index uniqueness. |
System.String[] | properties | Names of the properties that hash index should include. |
HashIndexAttribute(String, String, Boolean, Boolean, String[])
Declaration
public HashIndexAttribute(string name, string cultureName, bool caseSensitive, bool isUnique, params string[] properties)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | Index's name |
System.String | cultureName | The name of the culture to use to compare strings inside the index. |
System.Boolean | caseSensitive | Indicates whether string comparisons inside the index are case sensitive. |
System.Boolean | isUnique | If true, VeloxDB will enforce hash index uniqueness. |
System.String[] | properties | Names of the properties that hash index should include. |