【譯】第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; }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM