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的更多相关文章

  1. Entity Framework Code-First(9.6):DataAnnotations - StringLength Attribute

    DataAnnotations - StringLength Attribute: StringLength attribute can be applied to a string type pro ...

  2. Entity Framework Code-First(9.5):DataAnnotations - MaxLength Attribute

    DataAnnotations - MaxLength Attribute: MaxLength attribute can be applied to a string or array type ...

  3. Entity Framework Code-First(9.10):DataAnnotations - NotMapped Attribute

    DataAnnotations - NotMapped Attribute: NotMapped attribute can be applied to properties of a class. ...

  4. Entity Framework Code-First(9.9):DataAnnotations - ForeignKey Attribute

    DataAnnotations - ForeignKey Attribute: ForeignKey attribute can be applied to properties of a class ...

  5. Entity Framework Code-First(9.8):DataAnnotations - Column Attribute

    DataAnnotations - Column Attribute: Column attribute can be applied to properties of a class. Defaul ...

  6. Entity Framework Code-First(9.2):DataAnnotations - TimeStamp Attribute

    DataAnnotations - TimeStamp Attribute: TimeStamp attribute can be applied to only one byte array pro ...

  7. Entity Framework Code-First(9.1):DataAnnotations - Key Attribute

    DataAnnotations - Key Attribute: Key attribute can be applied to properties of a class. Default Code ...

  8. 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 ...

  9. Entity Framework Code-First(9.3):DataAnnotations - ConcurrencyCheck Attribute

    ConcurrencyCheck Attribute: ConcurrencyCheck attribute can be applied to a property of a domain clas ...

随机推荐

  1. jQuery图片水平滑动延迟加载动画

    在线演示 本地下载

  2. Docker 架构篇

    Docker 的核心组件包括: Docker 客户端 - Client Docker 服务器 - Docker daemon Docker 镜像 - Image Registry Docker 容器 ...

  3. Android之史上最全最简单最有用的第三方开源库收集整理

    Android开源库 自己一直很喜欢Android开发,就如博客签名一样, 我是程序猿,我为自己代言 . 在摸索过程中,GitHub上搜集了很多很棒的Android第三方库,推荐给在苦苦寻找的开发者, ...

  4. SQL2005 2008配置错误,无法识别的配置节 system.serviceModel machine.config配置文件有问题

    当装上2008的时候,你以前的程序突然报出你的machine.config配置文件有问题,比如 “/” 应用程序中的服务器错误. 配置错误 说明 : 在处理向该请求提供服务所需的配置文件时出错.请检查 ...

  5. 解决Eclipse和myeclipse在进行 html,jsp等 页面编辑时,自动格式化变丑的问题

    在eclipse和myelipse写JAVA代码时中使用ctrl+shift+f 快捷键自动排版省时又省力,排版后的代码规范美观又层次性,但在我们写jsp或html代码时,使用这个快捷键排版简直奇丑无 ...

  6. django学习笔记(四)表单

    1.若用户刷新一个包含POST表单的页面,那么请求将会重新发送造成重复. 这通常会造成非期望的结果,比如说重复的数据库记录.如果用户在POST表单之后被重定向至另外的页面,就不会造成重复的请求了.我们 ...

  7. L1-039 古风排版(20 分)

    中国的古人写文字,是从右向左竖向排版的.本题就请你编写程序,把一段文字按古风排版. 输入格式: 输入在第一行给出一个正整数N(<100),是每一列的字符数.第二行给出一个长度不超过1000的非空 ...

  8. bzoj 2300: [HAOI2011]防线修建 凸包

    题目大意: http://www.lydsy.com/JudgeOnline/problem.php?id=2300 题解 这道题让我们维护一个支持动态删除点的上凸壳 并且告诉了我们三个一定不会被删除 ...

  9. backbonejs学习

    文章: http://www.cnblogs.com/yexiaochai/archive/2013/07/27/3219402.html http://blog.csdn.net/cony100/a ...

  10. Cloudera安装要点

    C方式是完全离线方式 https://www.cloudera.com/documentation/enterprise/5-10-x/topics/cm_ig_installing_configur ...