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. IE浏览器和CSS盒模型【转】

    总结:css盒模型在不同浏览器之间(例如:ie和其他浏览器 如火狐)的差异只存在于ie6之前的版本中,如ie5.在ie6下, Internet Explorer 在标准模式下渲染时使用了 CSS 规范 ...

  2. 20145229吴姗珊 《Java程序设计》第3周学习总结

    20145229吴姗珊 <Java程序设计>第3周学习总结 教材学习内容总结 第四章 认识对象 4.1类与对象 1.对象(Object):存在的具体实体,具有明确的状态和行为 2.类(Cl ...

  3. (转)Windows下面安装和配置MySQL(5.6.20)

    原文地址:http://www.cnblogs.com/qiyebao/p/3887055.html 1.首先到http://dev.mysql.com/ 上下载windows版mysql5.6免安装 ...

  4. crond

    Crond介绍 Crond是linux系统用来定期执行命令或程序的工具. 服务 /etc/init.d/crond 命令 crontab [root@rhel6 script]# crontab -h ...

  5. 修改push动画的方向

    CATransition *animation = [CATransition animation]; animation.duration = 0.4; animation.timingFuncti ...

  6. HDU2612 -暑假集训-搜索进阶N

     http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82828#problem/N这两天总是因为一些小错误耽误时间,我希望自己可以细心点.珍惜 ...

  7. C语言中的位操作(15)--确定log10(N)的整数部分

    本篇文章介绍一个整数的以10为底的对数的整数部分,即对于整数N,求log10(N)整数部分 方法一 : unsigned int v; //32位非0整数 int r; // r保存结果 int t; ...

  8. JQuery 常用代码

    1.选择器 1.根据标签名: $('p')  选择文档中的所有段落    2. 根据ID: $("#some-id")    3.类: $('.some-class') $('.t ...

  9. 分享知识-快乐自己:Caused by: org.hibernate.tool.schema.extract.spi.SchemaExtractionException: More than one table found in namespace (, ) : Dept (XXX)

    在命名空间(,)中找到多个表 - SchemaExtractionException? 问题: 尝试在Java应用程序中使用Hibernate将一些值保存到表中时,我一直面临着这个奇怪的异常. 但是, ...

  10. python MLP 神经网络使用 MinMaxScaler 没有 StandardScaler效果好

    MLP 64,2  preprocessing.MinMaxScaler().fit(X)                               test confusion_matrix:[[ ...