zoukankan      html  css  js  c++  java
  • Entity Framework Code-First(9.7):DataAnnotations

    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.

    dataannotations table attribute

    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.

    dataannotations table attribute

  • 相关阅读:
    dw2018修改为中文
    C# 响应一个html页面
    layui 时间控件 单击 年直接赋值
    js 正则 测试
    python之读取和写入csv文件
    python安装与配置
    hive支持sql大全
    HiveQL与SQL区别
    Hadoop插件安装
    简单算法学习之快速排序详解
  • 原文地址:https://www.cnblogs.com/purplefox2008/p/5644177.html
Copyright © 2011-2022 走看看