Knight Data Access Layer
Indexes VB.NET
Basic Tasks VB.NET > Mapping > Indexes VB.NET

Indexes are defined differently than primary keys or composite keys.  There are two options, TableIndex which consists of one or more columns for a table or a ColumnIndex which is simply an attribute on a Column.  Indexes are automatically created when the Table does not exist and a Setup command is issued.  If the table already exists and a new TableIndex or or ColumnIndex attribute is added, it will not be added to the table.  There are methods available to deal with indexes such as CreateIndex, IndexExists, and GetIndexesForTable.

Here is a table index consisting of First Name and Last Name

 

<TableIndex(isUnique: False, indexName: "IX_Prospects_FirstLast", commaDelimitedListOfColumns: "FirstName,LastName")>

Public Class Prospect

Public Property ProspectId() As Integer

Public Property FirstName() As String

Public Property LastName() As String

End Class

 

Here is a column index for just the column MovieName.  The default is non-unique ascending. You can specify the uniqueness, the acension, and the index name.

 

Public Class Movie

Public Property MovieId() As Integer

 

<ColumnIndex(isUnique: True, isAscending: True, indexName: "IX_Movies_MovieName")>

Public Property MovieName() As String

End Class