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

Posted caofangsheng

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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:好记性不如烂笔头,学会总结,学会思考~~~ ----要飞翔,必须靠自己!



以上是关于9.6 翻译系列:数据注解之Index特性EF 6 Code-First系列的主要内容,如果未能解决你的问题,请参考以下文章