数据注解特性是.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. EF Core For Oracle11中Find FirstOrDefault等方法执行失败

    问题描述 最近在使用ef core连接oracle的发现Find.FirstOrDefault.Skip Task分页等等方法执行失败.使用的是docker安装的oracle11,错误如下图: 解决办 ...

  2. Vue(八)---组件(Component)

    组件(Component)是 Vue.js 最强大的功能之一.组件可以扩展 HTML 元素,封装可重用的代码. 注册一个全局组件语法格式如下: Vue.component(tagName, optio ...

  3. CentOS7安装docker和docker-compose

    1.安装docker # 使用yum安装docker yum -y install docker # 启动 systemctl start docker.service # 设置为开机自启动 syst ...

  4. vc6 保存文件卡住

    解决办法:删除工程文件中的三个文件,分别是:*.ncb  * .opt   * .plg引用链接:https://blog.csdn.net/lvxianlong123/article/details ...

  5. Maven快速入门使用

    1. Maven 介绍 1.1 为什么使用 Maven 由于 Java 的生态非常丰富,无论你想实现什么功能,都能找到对应的工具类,这些工具类都是以 jar 包的形式出现的,例如 Spring,Spr ...

  6. ng-简介

    Angular 是什么 Angular(读音['æŋgjʊlə])是一套用于构建用户界面的 JavaScript 框架.由 Google 开发和维护,主要被用来开发单页面应用程序. 类似于 Vue.j ...

  7. Redis缓存数据库(一)

    先导知识:Memcache Memcache是一个高性能的分布式内存对象缓存系统,代码类似于Hash. 已经有了Memcache,为什么还要用Redis呢? 下面Memcache的缺点: 不支持数据持 ...

  8. centos7安装显示中文

    系统通过环境变量LANG设置语言格式编码 查看当前语言环境 echo $LANG 查看是否安装中文语言,Linux中通过locale来设置程序运行的不同语言环境 locale -a | grep 'z ...

  9. xadmin使用

    xadmin使用 官方 使用参考

  10. UVA1395 (最苗条的最小生成树)

    链接 https://vjudge.net/problem/UVA-1395 代码 #include<bits/stdc++.h> using namespace std; #define ...