9.6 翻译系列:数据注解之Index特性【EF 6 Code-First系列】

原文链接:https://www.entityframeworktutorial.net/entityframework6/index-attribute-in-code-first.aspx
EF 6提供了Index特性,用来在特定的列上面创建索引。

class 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; }

每天学一点,每天积累一天,进步就不止一点点!PS:好记性不如烂笔头,学会总结,学会思考~~~ ----要飞翔,必须靠自己!

猜你喜欢

转载自www.cnblogs.com/caofangsheng/p/10675987.html
9.6
今日推荐