数据注解特性是.NET特性,可以在EF或者EF Core中,应用于实体类上或者属性上,以重写默认的约定规则。

在EF 6和EF Core中,数据注解特性包含在System.ComponentModel.DataAnnotations命名空间和System.ComponentModel.DataAnnotations.Schema命名空间下。

这些特性不仅仅适用于EF,同样适用于ASP.NET MVC以及数据控件。

System.ComponentModel.DataAnnotations.Schema Attributes

[Table(string name,[Schema = string])]

name 想要定义的表名称

Schema 可选参数,数据库的模式名称

[Column(string name,[Order = int],[TypeName = string])]

name 列名

Order 可选参数,列的顺序,从0开始,注意必须为每个属性都设置(不可重复)才能生效、

TypeName 可选参数,列的数据类型

[NotMapped]  不将该属性映射到数据库的列

[ForeignKey(string name)]  设置外键3种方式

[Index(string name)] 为列创建索引

IsClustered用来创建聚合索引, IsUnique用来创建唯一索引。

[InverseProperty(string name)]  有多个对应关系时,指定关系

System.ComponentModel.DataAnnotations Attributes

[Key]  设为主键(EF Core中不能使用)

[Required]  设置列不为空

[MaxLength(int)]  设置最大长度,只能用在string类型和byte[]数组类型

EF CodeFirst数据注解特性详解的更多相关文章

  1. 9.10 翻译系列:EF数据注解特性之StringLength【EF 6 Code-First系列】

    原文链接:https://www.entityframeworktutorial.net/code-first/stringlength-dataannotations-attribute-in-co ...

  2. 9.9 翻译系列:数据注解特性之--MaxLength 【EF 6 Code-First系列】

    原文链接:https://www.entityframeworktutorial.net/code-first/maxlength-minlength-dataannotations-attribut ...

  3. 9.7 翻译系列:EF数据注解特性之--InverseProperty【EF 6 Code-First系列】

    原文链接:https://www.entityframeworktutorial.net/code-first/inverseproperty-dataannotations-attribute-in ...

  4. 9.3 翻译系列:数据注解特性之Key【EF 6 Code-First 系列】

    原文链接:http://www.entityframeworktutorial.net/code-first/key-dataannotations-attribute-in-code-first.a ...

  5. 9.翻译系列:EF 6以及EF Core中的数据注解特性(EF 6 Code-First系列)

    原文地址:http://www.entityframeworktutorial.net/code-first/dataannotation-in-code-first.aspx EF 6 Code-F ...

  6. 9.1 翻译系列:数据注解特性之----Table【EF 6 Code-First 系列】

    原文地址:http://www.entityframeworktutorial.net/code-first/table-dataannotations-attribute-in-code-first ...

  7. 9.8 翻译系列:数据注解特性之--Required 【EF 6 Code-First系列】

    原文链接:https://www.entityframeworktutorial.net/code-first/required-attribute-dataannotations-in-code-f ...

  8. 9.11 翻译系列:数据注解特性之--Timestamp【EF 6 Code-First系列】

    原文链接:https://www.entityframeworktutorial.net/code-first/TimeStamp-dataannotations-attribute-in-code- ...

  9. 9.12 翻译系列:数据注解特性之ConcurrencyCheck【EF 6 Code-First系列】

    原文链接:https://www.entityframeworktutorial.net/code-first/concurrencycheck-dataannotations-attribute-i ...

随机推荐

  1. 面试想拿 10K,HR 说你只值 7K,该怎样回答或者反驳?

    当HR压你价,说你只值7K时,你可以流畅地回答,记住,是流畅,不能犹豫. 礼貌地说:"7K是吗?了解了.嗯~其实我对贵司的面试官印象很好.只不过,现在我的手头上已经有一份11K的offer. ...

  2. 页面上icon较多,又不想使用臃肿的结构怎么办?

    [先看效果图] 例如这种排版,常规有两种情况 1.把[“ & ”]+ 白色背景切一起 2.写结构的时候复杂,例如:div>img*2 +文字标签 读到这里,可能有人说,第一种情况为什么两 ...

  3. PyQt5【入门-窗口】

    一.窗口 #设置窗口标题 setWindowTitle("标题") #设置窗口坐标和大小 setGeometry(0,0,800,600) """ 项 ...

  4. WinForm WebBrowser 设置IE版本

    public enum IeVersion { IE7 = , IE8 = , IE9 = , IE10 = , IE11 = }; /// <summary> /// 修改注册表信息来兼 ...

  5. tensor的维度扩张的手段--Broadcasting

    broadcasting是tensorflow中tensor维度扩张的最常用的手段,指对某一个维度上重复N多次,虽然它呈现数据已被扩张,但不会复制数据. 可以这样理解,对 [b,784]@[784,1 ...

  6. thinkphp5.0 insert添加数据

    首先引入文件:use think\Db; public function zhuce(){ $username = input("username");//手机号 $passwor ...

  7. xadmin使用

    xadmin使用 官方 使用参考

  8. win10中安装与配置maven

    原文链接:https://www.cnblogs.com/wkrbky/p/6350334.html Maven安装配置(Windows10) 想要安装 Apache Maven 在Windows 系 ...

  9. PAT (Advanced Level) Practice 1005 Spell It Right (20 分) (switch)

    Given a non-negative integer N, your task is to compute the sum of all the digits of N, and output e ...

  10. sql server针对字符串型数字排序(针对此字符串的长度不一致)

    对于不规则的字符串数字排序,无法按照数字大的大小排序的原因是,字符串数字在数据库中按照ASCII码排序,从字符的第一个数字对比,首先就会将为首个数字相同的排在一起,在从这些字符串里面对比第二个数字,如 ...