public class Person
{
public int PersonID { get; set; }
public string PersonName { get; set; }
[Index]
public int Age { get; set; }
}
Creates a database index for a column or set of columns.
[Index("IX_Person_Age")]
public int Age { get; set; }
This creates an index with a specific name.
[Index(IsUnique = true)]
public int Age { get; set; }
This creates a unique index.
[Index("IX_Person_NameAndAge", 1)]
public int Age { get; set; }
[Index("IX_Person_NameAndAge", 2)]
public string PersonName { get; set; }
This creates a composite index using 2 columns. To do this you must specify the same index name and provide a column order.
Note: The Index attribute was introduced in Entity Framework 6.1. If you are using an earlier version the information in this section does not apply.