Entity Framework Code-First(9.7):DataAnnotations - Table Attribute
DataAnnotations - Table Attribute:
Table attribute can be applied to a class. Default Code-First convention creates a table name same as the class name. Table attribute overrides this default convention. EF Code-First will create a table with a specified name in Table attribute for a given domain class.
Consider the following example.
using System.ComponentModel.DataAnnotations.Schema;
[Table("StudentMaster")]
public class Student
{
public Student()
{
}
public int StudentID { get; set; }
public string StudentName { get; set; }
}
As you can see in the above example, Table attribute is applied to Student class. So, Code First will override default conventions and create StudentMaster table instead of Student table as shown below.

You can also specify a schema for the table using Table attribute as shown below.
using System.ComponentModel.DataAnnotations.Schema;
[Table("StudentMaster", Schema="Admin")]
public class Student
{
public Student()
{
}
public int StudentID { get; set; }
public string StudentName { get; set; }
}
Code-First will create StudentMaster table in Admin schema as shown below.

Entity Framework Code-First(9.7):DataAnnotations - Table Attribute的更多相关文章
- Entity Framework Code-First(9.6):DataAnnotations - StringLength Attribute
DataAnnotations - StringLength Attribute: StringLength attribute can be applied to a string type pro ...
- Entity Framework Code-First(9.5):DataAnnotations - MaxLength Attribute
DataAnnotations - MaxLength Attribute: MaxLength attribute can be applied to a string or array type ...
- Entity Framework Code-First(9.10):DataAnnotations - NotMapped Attribute
DataAnnotations - NotMapped Attribute: NotMapped attribute can be applied to properties of a class. ...
- Entity Framework Code-First(9.9):DataAnnotations - ForeignKey Attribute
DataAnnotations - ForeignKey Attribute: ForeignKey attribute can be applied to properties of a class ...
- Entity Framework Code-First(9.8):DataAnnotations - Column Attribute
DataAnnotations - Column Attribute: Column attribute can be applied to properties of a class. Defaul ...
- Entity Framework Code-First(9.2):DataAnnotations - TimeStamp Attribute
DataAnnotations - TimeStamp Attribute: TimeStamp attribute can be applied to only one byte array pro ...
- Entity Framework Code-First(9.1):DataAnnotations - Key Attribute
DataAnnotations - Key Attribute: Key attribute can be applied to properties of a class. Default Code ...
- Entity Framework Code-First(9.4):DataAnnotations - Required Attribute
Required attribute can be applied to a property of a domain class. EF Code-First will create a NOT N ...
- Entity Framework Code-First(9.3):DataAnnotations - ConcurrencyCheck Attribute
ConcurrencyCheck Attribute: ConcurrencyCheck attribute can be applied to a property of a domain clas ...
随机推荐
- 【leetcode刷题笔记】Anagrams
Given an array of strings, return all groups of strings that are anagrams. Note: All inputs will be ...
- RabbitMQ之Exchange Direct模式
场景: 生产者发送消息到交换机并指定一个路由key, 消费者队列绑定到交换机时要指定路由key(key匹配就能接受消息,key不匹配就不能接受消息) 例如:我们可以把路由key设置为insert ,那 ...
- Jquery的load()
我一直认为jquery的load函数是以GET方式请求另一个文件并加载到当前DOM里的.当我带参数加载一个ASP脚本时是这样做: $("#showData").load(" ...
- JavaWeb -- 会话, Cookie 和 Session
1. 会话 •Cookie是客户端技术,服务器把每个用户的数据以cookie的形式写给用户各自的浏览器.当用户使用浏览器再去访问服务器中的web资源时,就会带着各自的数据去.这样,web资源处理的就是 ...
- php数据结构课程---4、栈(是什么)
php数据结构课程---4.栈(是什么) 一.总结 一句话总结: 栈(stack),它是一种运算受限的线性表.其限制是仅允许在表的一端进行插入和删除运算. 1.栈的链表实现? 定义node,设置属性d ...
- Delphi TcxComboBox控件说明
属性: Text:ComboBox 的文本信息 EditText: 也是给ComboBox 的文本信息赋值,但不同的是 给Text赋值会 触发 Change事件,也会触发 EditvaluesChan ...
- Nginx 0.7.x + PHP 5.2.6(FastCGI)+ MySQL 5.1 在128M小内存VPS服务器上的配置优化
对其用户和应用程序来讲,每一个VPS平台的运行和管理都与一台独立主机完全相同,因为每一个VPS均可独立进行重启并拥有自己的root访问权限.用户.IP地址.内存.过程.文件.应用程序.系统函数库以及配 ...
- vi 常用编辑命令
什么是vi: vi是Linux/Unix底下最常用的文本编辑器,可以理解为和Windows下的txt一样,咱们一般操作linux服务器的时候都是没有图形化界面的, 怎么移动光标,到哪个位置,替换修改什 ...
- 【leetcode刷题笔记】Binary Tree Level Order Traversal II
Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left ...
- openfire存储中文字符乱码解决办法
转载于: Xmpp问题总结:处理Openfire 中文乱码问题(2) openfire是一个非常不错的IM服务器,而且是纯Java实现,具有多个平台的版本,他的数据存储可以采用多种数据库,如MySQL ...