Say I have the following model:
[Table("Record")]
public class RecordModel
{
[Key]
[DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
[Display(Name = "Record Id")]
public int RecordId { get; set; }
[StringLength(150)]
public string Name { get; set; }
[Required]
[StringLength(15)]
public string IMEI { get; set; }
}
Is it possible to add an index to the IMEI
column through using an attribute, data annotation, or something from the model?
UPDATE: Since the release of EF 6.1. (March 17th, 2014) there is indeed an
[Index]
attribute available.Functionality as:
comes out of the box.
PS: other properties are
Order
andIsClustered
.According to this link: http://blogs.msdn.com/b/adonet/archive/2014/02/11/ef-6-1-0-beta-1-available.aspx
It will be available in EF 6.1 as a standard DataAnnotation attribute.
According to this link: Creating Indexes via Data Annotations with Entity Framework 5.0 you should write some kind of extension code:
and the second class:
After it you can use your
index
this way: