数据注解特性是.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. linuxWeb环境安装——小皮面板不错的面板

    安装环境为最新的:CentOS8.1.1911  linux的web环境安装,说白了,弄明白了就不难.为此阅读了多部文献,最先的是linux教程,重理论轻实践:之后,看了鸟哥的私房菜,有2本,每本都8 ...

  2. jQuery---事件解绑与事件触发

    事件解绑与事件触发 $("p").off("click"); $("#btn").on("click", functio ...

  3. MySQL架构和MySQL索引

    1.  MySQL架构 1.1         逻辑架构图 1.1.1   Connection Pool: 连接池 * 管理缓冲用户连接,线程处理等需要缓存的需求. * 负责监听对 MySQL Se ...

  4. 剑指offer-面试题43-1~n整数中1出现的次数-归纳法

    /* 题目: 求出1~13的整数中1出现的次数,并算出100~1300的整数中1出现的次数? 为此他特别数了一下1~13中包含1的数字有1.10.11.12.13因此共出现6次,但是对于后面问题他就没 ...

  5. [USACO19DEC]Tree Depth P

    题意 求逆序对为\(k\)的\(n\)排列中,生成的笛卡尔数,每个位置的深度和.\(n\le 300\) 做法 设\(f_{k}\)为\(n\)排列中逆序对为\(k\)的个数,其生成函数为:\[\pr ...

  6. Hibernate注释

    Hibernate注释映射一.PO类的基本注释1.@Entity:将pojo类标记成实体,可以指定一个name属性,指定实体类的名称.默认一该类的类名作为实体类的名称 2.@Table:注释改持久化类 ...

  7. vue自学入门-6(vue jsx)

    目录: vue自学入门-1(Windows下搭建vue环境) vue自学入门-2(vue创建项目) vue自学入门-3(vue第一个例子) vue自学入门-4(vue slot) vue自学入门-5( ...

  8. springboot web - 建立路由

    一. 测试代码 @RestController @RequestMapping("/book") public class BookController { @PostMappin ...

  9. Postman使用技巧

    Postman是什么 Postman是chrome的一款插件,用于做接口请求测试,无论是前端,后台还是测试人员,都可以用postman来测试接口,用起来非常方便. Postman安装 官网下载(翻墙) ...

  10. 【Spring】事务(transactional)之初步理解

    一. 场景 有一个定时器,做数据库表数据同步. 把数据库A的表table(DB_A_TABLE)同步到数据库B的表table(DB_B_TABLE). 对于DB_A_TABLE的每行数据要做一定的逻辑 ...