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 ...
随机推荐
- bootstraptable的 showFooter属性
如果想在表格最下面显示统计的信息可以使用这个属性 首先 先在表格加上这个属性 showFooter:true, 然后 在需要的列里面新增属性 footerFormatter 设置列的名称 然后在需 ...
- 51nod 1525 && CF566D
题意:给定n个元素,现在有2种合并操作和1种询问操作 1.单独合并两个元素所在的集合 2.合并一个区间内的元素所在的集合 询问:两个元素是否属于统一集合 神犇题解 感觉又涨了新姿势啊..我们最恼火的是 ...
- EntityFramework 学习 一 Entity Framework结构体系
Entity Framework 架构 EDM(Entity Data Model)EDM由3个主要部分组成 Conceptual model , Mapping and Storage model. ...
- castle windsor学习----- CastleComponentAttribute 特性注册
[CastleComponent("GenericRepository", typeof(IRepository<>), Lifestyle = LifestyleTy ...
- 内存表 ClientDataSet CreateDataSet
unit Form_Main; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, F ...
- input 限制输入
只能输入数字 :<input type="text" onkeyup="value=value.replace(/[^\d]/g,'')" /> 只 ...
- hdu-5642 King's Order(数位dp)
题目链接: King's Order Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Othe ...
- 解决jquery动态创建元素绑定事件失效问题
存在问题 在我们使用jquery动态创建元素后往往会遇到一些问题,如: 给.button按钮绑定了点击时间,执行alert:(1); 点击事件代码如下: <script>$("# ...
- 【leetcode刷题笔记】Reverse Linked List II
Reverse a linked list from position m to n. Do it in-place and in one-pass. For example:Given 1-> ...
- 【二叉树的递归】06填充每个节点中的下一个正确的指针【Populating Next Right Pointers in Each Node】
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 给定一个二叉树 struct Tr ...