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 ...
随机推荐
- USB-Blaster CPLD FPGA Intel 驱动安装不上的问题,文件的哈希值不在指定的目录文件中,的解决办法,其实很简单
intel的官网的驱动安装文档: https://www.intel.com/content/www/us/en/programmable/support/support-resources/down ...
- opencv —— 读取并播放视频 VideoCapture capture("C:/1.mp4");
VideoCapture 读入视频的方法有两种: ①先实例化再初始化:VideoCapture capture:capture.open("C:/Users/齐明洋/Desktop/1.mp ...
- 位运算基础知识及简单例题(待补全Hamilton)
位运算 +++ 1 : 0000000000...01 2 : 0000000000...10 3 : 0000000000...11 补码 1 + x = 0000000000...00 1 + 1 ...
- Uva12034 (组合数取模)
题意:两匹马比赛有三种比赛结果,n匹马比赛的所有可能结果总数 解法: 设答案是f[n],则假设第一名有i个人,有C(n,i)种可能,接下来还有f(n-i)种可能性,因此答案为 ΣC(n,i)f(n-i ...
- nginx 配置 强制访问https
使用nginx的301状态码 server { listen ; if ($scheme = 'http') { return 301 https://$server_name$requ ...
- 程序里面带有浮点数,默认会自动转换为double类型存储
带有浮点数,默认会转换为double类型存储. #include "common.h" #include <stdio.h> #include <stdlib.h ...
- 论文阅读笔记(十一)【ICCV2017】:Jointly Attentive Spatial-Temporal Pooling Networks for Video-based Person Re-Identification
Introduction (1)Motivation: 当前采用CNN-RNN模型解决行人重识别问题仅仅提取单一视频序列的特征表示,而没有把视频序列匹配间的影响考虑在内,即在比较不同人的时候,根据不同 ...
- 在页面布局中,CSS如何实现左侧宽度固定,右侧宽度自适应的布局?
首先给出DOM结构 <divclass="box"> <divclass="box-left"></div> <div ...
- StarUML 2下载、安装、破解全过程
StarUML官方下载地址: http://staruml.io/download 破解: 1.使用Editplus或者Notepad++等特殊的文本编辑器打开 安装位置下/www/lic ...
- 【Linux02】LInux初始入门
1.LInux操作系统发展与演变 ENIARC: CUP:运算器.控制器.寄存器.缓存 存储器:内存.RAM Input:指令+数据 Output:结果 程序:指令+数据 算法+数据结构 字节是 ...