7.7 数据注解特性--Table
大家可能注意到,有几个特性,我没有翻译,因为实在是太简单了,看一下就知道,之前也学过,现在只是系统学一下,所以就粗略的看一下就行了。
现在学习数据注解特性的--Table特性。
Table 特性可以被用到类中,Code--First默认的约定是使用类名称为我们创建表名,Table特性可以重写这个约定,只要我们指定名字,EF就会根据Table属性里面的名字,为我们创建数据表名称。
我们看一下下面的代码吧:
- using System;
- using System.Collections.Generic;
- using System.ComponentModel.DataAnnotations;
- using System.ComponentModel.DataAnnotations.Schema;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace EF2
- {
- [Table("StudentMaster")]
- public class Student
- {
- [Key]
- [Column(Order=)]
- public int StudentKey1 { get; set; }
- [Key]
- [Column(Order=)]
- public int StudentKey2 { get; set; }
- [MaxLength()]
- [ConcurrencyCheck]
- [Required]
- public string StudentName { get; set; }
- [NotMapped()]
- public int? Age { get; set; }
- public int StdId { get; set; }
- [ForeignKey("StdId")]
- public virtual Standard Standard { get; set; }
- }
- }
然后我们运行程序,看一下数据库:
我们看到生成的数据表是Studentmaster。
你同样可以指定 表的schema 请看:
- using System;
- using System.Collections.Generic;
- using System.ComponentModel.DataAnnotations;
- using System.ComponentModel.DataAnnotations.Schema;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace EF2
- {
- [Table("StudentMaster",Schema="WaHaHa")]
- public class Student
- {
- [Key]
- [Column(Order=)]
- public int StudentKey1 { get; set; }
- [Key]
- [Column(Order=)]
- public int StudentKey2 { get; set; }
- [MaxLength()]
- [ConcurrencyCheck]
- [Required]
- public string StudentName { get; set; }
- [NotMapped()]
- public int? Age { get; set; }
- public int StdId { get; set; }
- [ForeignKey("StdId")]
- public virtual Standard Standard { get; set; }
- }
- }
7.7 数据注解特性--Table的更多相关文章
- 9.1 翻译系列:数据注解特性之----Table【EF 6 Code-First 系列】
原文地址:http://www.entityframeworktutorial.net/code-first/table-dataannotations-attribute-in-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.翻译系列:EF 6以及EF Core中的数据注解特性(EF 6 Code-First系列)
原文地址:http://www.entityframeworktutorial.net/code-first/dataannotation-in-code-first.aspx EF 6 Code-F ...
- 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- ...
随机推荐
- 安卓初級教程(4):sqlite建立資料庫
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 ...
- C#线程入门---转载
C#中的线程(一)入门 文章系参考转载,英文原文网址请参考:http://www.albahari.com/threading/ 作者 Joseph Albahari, 翻译 Swanky Wu 中 ...
- 用DataGridView导入TXT文件,并导出为XLS文件
使用 DataGridView 控件,可以显示和编辑来自多种不同类型的数据源的表格数据.也可以导出.txt,.xls等格式的文件.今天我们就先介绍一下用DataGridView把导入txt文件,导出x ...
- 【转】Apache 配置虚拟主机三种方式
Apache 配置虚拟主机三种方式 原文博客http://www.cnblogs.com/hi-bazinga/archive/2012/04/23/2466605.html 一.基于IP 1. 假 ...
- 玩转JavaScript OOP[1]——复杂类型
概述 在JavaScript中,我们可以使用函数.数组.对象,以及日期.正则等一些内置类型的实例,它们都是复杂类型的表现.从本质上讲,这些复杂类型都是Object类型.本篇将主要介绍三种Object类 ...
- [.net 面向对象程序设计深入](4)MVC 6 —— 谈谈MVC的版本变迁及新版本6.0发展方向
[.net 面向对象程序设计深入](4)MVC 6 ——谈谈MVC的版本变迁及新版本6.0发展方向 1.关于MVC 在本篇中不再详细介绍MVC的基础概念,这些东西百度要比我写的全面多了,MVC从1.0 ...
- Java批处理ExecutorService/CompletionService
服务端接收一个请求,常常需要同时进行几个计算或者向其他服务发送请求,最后拼装结果返回上游.本文就来看下JDK提供几个并行处理方案,牵涉到ExcecutorService/CompletionServi ...
- 升级CentOS内核 - 2.6升级到3.10
*因为学习docker的需要,docker的官方推荐内核使用3.8以上,所以本人决定把CentOS内核升到长期稳定版的3.10. ##记得切换到root用户执行升级操作. [root@localhos ...
- css浮雕效果
浮雕效果 今天看百度地图看到了一个效果 感觉这个效果用在网页上应该蛮赞的,于是就学习了一下 浮雕效果需要用到伸缩盒的知识(flex) flex在chrome是完全支持的,要加-webkit-前缀,其他 ...
- linux java so 历险
一开始 -bash-4.1# java -cp "/usr/linkapp/bin/tomcat-master/webapps/ROOT/WEB-INF/lib/*":" ...