【译】第45节---EF6-索引属性

原文:http://www.entityframeworktutorial.net/entityframework6/index-attribute-in-code-first.aspx

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( "INDEX_REGNUM", IsClustered=true, IsUnique=true )]
public int RegistrationNumber { get; set; }
原文地址:https://www.cnblogs.com/talentzemin/p/7411209.html