EF CodeFirst数据注解特性详解
数据注解特性是.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数据注解特性详解的更多相关文章
- 9.10 翻译系列:EF数据注解特性之StringLength【EF 6 Code-First系列】
原文链接:https://www.entityframeworktutorial.net/code-first/stringlength-dataannotations-attribute-in-co ...
- 9.9 翻译系列:数据注解特性之--MaxLength 【EF 6 Code-First系列】
原文链接:https://www.entityframeworktutorial.net/code-first/maxlength-minlength-dataannotations-attribut ...
- 9.7 翻译系列:EF数据注解特性之--InverseProperty【EF 6 Code-First系列】
原文链接:https://www.entityframeworktutorial.net/code-first/inverseproperty-dataannotations-attribute-in ...
- 9.3 翻译系列:数据注解特性之Key【EF 6 Code-First 系列】
原文链接:http://www.entityframeworktutorial.net/code-first/key-dataannotations-attribute-in-code-first.a ...
- 9.翻译系列:EF 6以及EF Core中的数据注解特性(EF 6 Code-First系列)
原文地址:http://www.entityframeworktutorial.net/code-first/dataannotation-in-code-first.aspx EF 6 Code-F ...
- 9.1 翻译系列:数据注解特性之----Table【EF 6 Code-First 系列】
原文地址:http://www.entityframeworktutorial.net/code-first/table-dataannotations-attribute-in-code-first ...
- 9.8 翻译系列:数据注解特性之--Required 【EF 6 Code-First系列】
原文链接:https://www.entityframeworktutorial.net/code-first/required-attribute-dataannotations-in-code-f ...
- 9.11 翻译系列:数据注解特性之--Timestamp【EF 6 Code-First系列】
原文链接:https://www.entityframeworktutorial.net/code-first/TimeStamp-dataannotations-attribute-in-code- ...
- 9.12 翻译系列:数据注解特性之ConcurrencyCheck【EF 6 Code-First系列】
原文链接:https://www.entityframeworktutorial.net/code-first/concurrencycheck-dataannotations-attribute-i ...
随机推荐
- flutter常用插件(持续更新)
flutter插件官网地址:https://pub.dartlang.org/packages/ 1. image_picker 一个可以从图库选择图片,并可以用相机拍摄新照片的flutter插件 2 ...
- docker配置搭建gogs
参考文献: https://www.yeboyzq.com/linux/ruanjiananzhuangweihu/1012.html https://www.jianshu.com/p/d92fd4 ...
- php ftp 使用 以及 php_connect_nonb() failed: Operation now in progress (115)
设置 ftp_pasv($conn,true); 会出现下面错误 不设置 调用ftp 连接没问题 ftp_nlist ftp_put ftp_get 等函数都不成功 ftp_nb_fput( ...
- gulp常用插件之gulp-htmlmin使用
更多gulp常用插件使用请访问:gulp常用插件汇总 gulp-htmlmin这是一款HTML文件压缩插件. 更多使用文档请点击访问gulp-htmlmin工具官网. 安装 一键安装不多解释 npm ...
- 解决NahimicSvc32.exe与bilibili直播姬的音频不兼容的问题
某次测试哔哩哔哩直播姬的时候发现系统声音采集异常的错误 NahimicSvc32.exe是NahimicService下的程序,奇怪的是我的本本所有硬件没有一个微星有关系,怎么就装上了微星的服务程序? ...
- 假期学习【三】HDFS操作及spark的安装/使用
1.安装 Hadoop 和 Spark 进入 Linux 系统,参照本教程官网“实验指南”栏目的“Hadoop 的安装和使用”,完 成 Hadoop 伪分布式模式的安装.完成 Hadoop 的安装以后 ...
- java实现判断两个二叉树是否相同
1.定义树节点类:节点值.左节点.右节点.构造器 2.先判断树是否为空的情况 3.树不为空时,判断节点所指的值是否相等,若相等,则递归判断节点的左右节点是否相同,相同则返回true /** * Def ...
- The view or its master was not found or no view engine supports the searched locations
Error like:The view 'LoginRegister' or its master was not found or no view engine supports the searc ...
- hadoop 配置信息记录
ssh-keygen -t rsa -P '' 192.168.157.148 hadoop01192.168.157.149 hadoop02 mkdir /root/hadoopmk ...
- MySQL 中like的使用对于索引的影响
今天看了一篇对于like使用对索引的影响的文章,发现自己实践的跟文章得出结论不大一样.所以还是建议自己再看别人文章的时候自己亲自动手实践一下.以免学到不全面的知识. 列子: 先建立一张表: -- 创建 ...