9.翻译系列:EF 6以及EF Core中的数据注解特性(EF 6 Code-First系列)
原文地址:http://www.entityframeworktutorial.net/code-first/dataannotation-in-code-first.aspx
EF 6 Code-First系列文章目录:
- 1 翻译系列:什么是Code First(EF 6 Code First 系列)
- 2.翻译系列:为EF Code-First设置开发环境(EF 6 Code-First系列)
- 3.翻译系列:EF Code-First 示例(EF 6 Code-First系列)
- 4.翻译系列:EF 6 Code-First默认约定(EF 6 Code-First系列)
- 5.翻译系列:EF 6中数据库的初始化(EF 6 Code-First 系列)
- 6.翻译系列:EF 6 Code-First中数据库初始化策略(EF 6 Code-First系列
- 7.翻译系列:EF 6中的继承策略(EF 6 Code-First 系列)
- 8.翻译系列: EF 6中配置领域类(EF 6 Code-First 系列)
- 9.翻译系列:EF 6以及EF Core中的数据注解特性(EF 6 Code-First系列)
- 9.1 翻译系列:数据注解特性之----Table【EF 6 Code-First 系列】
- 9.2 翻译系列:数据注解特性之---Column【EF 6 Code First系列】
- 9.3 翻译系列:数据注解特性之Key【EF 6 Code-First 系列】
- 9.4 翻译系列:EF 6以及 EF Core中的NotMapped特性(EF 6 Code-First系列)
- 9.5 翻译系列:数据注解之ForeignKey特性【EF 6 Code-First系列】
- 9.6 翻译系列:数据注解之Index特性【EF 6 Code-First系列】
- 9.7 翻译系列:EF数据注解特性之--InverseProperty【EF 6 Code-First系列】
- 9.8 翻译系列:数据注解特性之--Required 【EF 6 Code-First系列】
- 9.9 翻译系列:数据注解特性之--MaxLength 【EF 6 Code-First系列】
- 9.10 翻译系列:EF数据注解特性之StringLength【EF 6 Code-First系列】
- 9.11 翻译系列:数据注解特性之--Timestamp【EF 6 Code-First系列】
- 9.12 翻译系列:数据注解特性之ConcurrencyCheck【EF 6 Code-First系列】
- 10.翻译系列:EF 6中的Fluent API配置【EF 6 Code-First系列】
- 10.1.翻译系列:EF 6中的实体映射【EF 6 Code-First系列】
- 10.2.翻译系列:使用Fluent API进行属性映射【EF 6 Code-First】
- 11.翻译系列:在EF 6中配置一对零或者一对一的关系【EF 6 Code-First系列】
- 12.翻译系列:EF 6 中配置一对多的关系【EF 6 Code-First系列】
- 13.翻译系列:Code-First方式配置多对多关系【EF 6 Code-First系列】
- 14.翻译系列:从已经存在的数据库中生成上下文类和实体类【EF 6 Code-First系列】
- 15.翻译系列:EF 6中的级联删除【EF 6 Code-First 系列】
- 16.翻译系列:EF 6 Code -First中使用存储过程【EF 6 Code-First系列】
- 17.翻译系列:将Fluent API的配置迁移到单独的类中【EF 6 Code-First系列】
- 18.翻译系列:EF 6 Code-First 中的Seed Data(种子数据或原始测试数据)【EF 6 Code-First系列】
- 19.翻译系列:EF 6中定义自定义的约定【EF 6 Code-First约定】
- 20.翻译系列:Code-First中的数据库迁移技术【EF 6 Code-First系列】
- 20.1翻译系列:EF 6中自动数据迁移技术【EF 6 Code-First系列】
- 20.2.翻译系列:EF 6中基于代码的数据库迁移技术【EF 6 Code-First系列】
- 21.翻译系列:Entity Framework 6 Power Tools【EF 6 Code-First系列】
数据注解特性是.NET特性,可以在EF或者EF Core中,应用于实体类上或者属性上,以重写默认的约定规则。
在EF 6和EF Core中,数据注解特性包含在System.ComponentModel.DataAnnotations命名空间和System.ComponentModel.DataAnnotations.Schema命名空间下。
这些特性不仅仅适用于EF,同样适用于ASP.NET MVC以及数据控件。数据注解特性,在EF 6和EFCore中工作方式都是相同的、效用一样的。
System.ComponentModel.DataAnnotations Attributes
| 特性 | 描述 |
| Key | 应用于实体的一个属性上,然后就生成表里面的主键 |
| Timestamp | 应用于实体的一个属性上,然后生成表的列的类型就是RowVersion |
| ConcurrencyCheck | 应用的属性上,然后相应的列就会生成一个乐观检查 |
| Required | 应用的属性上面,生成一个不为空的列,然后映射到数据库的列中 |
| MinLength | 定义最小字符串长度,然后映射到数据库的列中 |
| MaxLength | 定义最大字符串长度,然后映射到数据库的列中 |
| StringLength | 可以指定属性列允许的最大字符串长度,然后映射到数据库的列中 |
System.ComponentModel.DataAnnotations.Schema Attributes
| 特性 | 描述 |
| Table | 应用于实体,可以配置表名和模式名 |
| Column | 应用于实体的属性上,可以配置相应的列名,列顺序以及数据类型 |
| Index | 应用于实体的属性上,可以为列生成索引(EF 6.1以上的版本才支持) |
| ForeignKey | 应用于实体的属性上,然后生成外键属性 |
| NotMapped | 可以应用于实体或者实体的属性上,应用于实体上,就不会生成表,应用于属性上,就不会生成列 |
| DatabaseGenerated | 配置列自动生成,可以有三个选项:identity【自增】, computed【计算】 or none【无】 |
| InverseProperty | 应用于属性上。就是有相同的关系的时候,用于反转导航属性。【概念不好说,等会后面有例子讲解。】 |
| ComplexType | 在EF 6中标记类是复杂类型,注意:EF Core 2.0 中不支持这个Complex特性 |
我们在后面的子节中,来好好学习一个每个特性。
9.翻译系列:EF 6以及EF Core中的数据注解特性(EF 6 Code-First系列)的更多相关文章
- 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.2 翻译系列:数据注解特性之---Column【EF 6 Code First系列】
原文链接:http://www.entityframeworktutorial.net/code-first/column-dataannotations-attribute-in-code-firs ...
- 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 ...
随机推荐
- java加密工具类,可设置对应的加解密key
public class AesEncryptUtil { //使用AES-128-CBC加密模式,key需要为16位,key和iv可以相同! private static String KEY =& ...
- 【Java】 剑指offer(59-2) 队列的最大值
本文参考自<剑指offer>一书,代码采用Java语言. 更多:<剑指Offer>Java实现合集 题目 请定义一个队列并实现函数max得到队列里的最大值,要求函数ma ...
- 全排列-hdu1716
题目描述: 题目意思很简单,就是要我们输出全排列后的数据组成,但是要注意组成的数据是一个实数,并且千位数字相同的处在同一行中. 代码实现: #include<stdio.h> #inclu ...
- python获取公网ip,本地ip及所在国家城市等相关信息收藏
python获取公网ip的几种方式 from urllib2 import urlopen my_ip = urlopen('http://ip.42.pl/raw').read() ...
- 001.HAProxy简介
一 HAProxy简介 HAProxy是可提供高可用性.负载均衡以及基于TCP(从而可以反向代理mysql等应用)和HTTP应用的代理,支持虚拟主机,它是免费.快速并且可靠的一种解决方案.HAProx ...
- Java线程池深入理解
之前面试baba系时遇到一个相对简单的多线程编程题,即"3个线程循环输出ADC",自己答的并不是很好,深感内疚,决定更加仔细的学习<并发编程的艺术>一书,到达掌握的强度 ...
- kali 解决Metasploit拿到shell后显示中文乱码问题
拿到对方shell后显示的问题如下: 中文乱码解决: chcp 65001 然后 上传下载文件
- Loadrunner11的安装方法和破解
前提:我使用的是在虚拟机下安装32位win7系统,浏览器为IE8(为录制脚本做铺垫) LoadRunner,是一种预测系统行为和性能的负载测试工具.通过以模拟上千万用户实施并发负载及实时性能监测的方式 ...
- CF733F Drivers Dissatisfaction【链剖】【最小生成树应用】
F. Drivers Dissatisfaction time limit per test 4 seconds memory limit per test 256 megabytes input s ...
- mongodb.副本集配置方法(使用keyfile认证部署)
前提条件: - 已安装MongoDB, 版本以3.6为例 - 系统: Debian9 - 建议做副本集的话, 以3台以上为宜, 本文以1台主机2个服务为例 1.创建数据存放的目录, 并授权 sudo ...