EF6 增加索引

Entity Framework 6提供了Index属性来创建数据库中特定列的Index,如下所示:

class Student
{
    public Student()
    {
    }
    public int Student_ID { get; set; }
    public string StudentName { get; set; }
       
    [Index]
    public int RegistrationNumber { get; set; }
}

默认情况下,索引名称将为IX_ {属性名称}。 当然你也可以更改索引名称。

可以通过指定IsClustered = true和唯一索引来指定IsUnique = true来使其成为聚簇索引。

[Index( "IX_Student_RegistrationNumber", IsClustered=true, IsUnique=true )]
public int RegistrationNumber { get; set; }

posted @ 2018-04-26 09:54  violety  阅读(604)  评论(0)    收藏  举报