DataAnnotations - Column Attribute:

Column attribute can be applied to properties of a class. Default Code First convention creates a column name same as the property name. Column attribute overrides this default convention. EF Code-First will create a column with a specified name in Column attribute for a given property.

Consider the following example.

using System.ComponentModel.DataAnnotations.Schema;

public class Student
{
public Student()
{ }
public int StudentID { get; set; } [Column("Name")]
public string StudentName { get; set; } }

As you can see in the above example, Column attribute is applied to StudentName property of Student class. So, Code-First will override default conventions and create Name column instead of StudentName column in the Student table, as shown below.

You can also specify an order and type of the column using Column attribute, as shown below.

using System.ComponentModel.DataAnnotations.Schema;

public class Student
{
public Student()
{ }
public int StudentID { get; set; } [Column("Name", Order=, TypeName="varchar")]
public string StudentName { get; set; } }

The above code creates Name column of varchar type as a first column in Student, as shown below.

Entity Framework Code-First(9.8):DataAnnotations - Column 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.7):DataAnnotations - Table Attribute

    DataAnnotations - Table Attribute: Table attribute can be applied to a class. Default Code-First con ...

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

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

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

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

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

  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. ps 切片 蓝色 灰色 小标志 什么意思

    切片颜色 区分自动切片与用户切片和基于图层的切片.默认情况下,用户切片和基于图层的切片带蓝色标记,而自动切片带灰色标记.-----用户切片就是你需要的切片,其他区域会形成自动切片,可以视为自己不要的, ...

  2. android6.0 外部存储设备插拔广播以及获取路径(U盘)【转】

    本文转载自:https://blog.csdn.net/zhouchengxi/article/details/53982222 这里我将U盘作为例子来说明解析. android4.1版本时U盘插拔时 ...

  3. java入门了解09

    1.JDK5新功能 (一).静态导入 import static java.lang.System.out; 使用时:直接写调用out()方法 (二).增强的for循环 只能用在数组:或是实现了Ite ...

  4. js操作url的常用函数

    1. //替换指定传入参数的值,paramName为参数,replaceWith为新值 function replaceParamVal(oUrl,paramName, replaceWith) { ...

  5. Javascript中 节流函数 throttle 与 防抖函数 debounce

    问题的引出 在一些场景往往由于事件频繁被触发,因而频繁地进行DOM操作.资源加载,导致UI停顿甚至浏览器崩溃. 在这样的情况下,我们实际上的需求大多为停止改变大小n毫秒后执行后续处理:而其他事件大多的 ...

  6. Linux各个文件夹的主要作用 (源地址

    (源地址blog.csdn.net/lonelysky/article/details/5374230,侵删) linux下的文件结构,看看每个文件夹都是干吗用的 /bin 二进制可执行命令 /dev ...

  7. [转载]C++Assert()函数

    assert宏的原型定义在<assert.h>中,其作用是如果它的条件返回错误,则终止程序执行,原型定义: #include <assert.h> void assert( i ...

  8. C易位构词(华师网络赛)(错排)

    Time limit per test: 2.0 seconds Memory limit: 256 megabytes 易位构词 (anagram),指将一个单词中的字母重新排列,原单词中的每个字母 ...

  9. 孤独地、凄惨地AK

    一个\(OIer\)要写多少\(for\) 才能被称为一个\(OIer\) 一位巨佬要爆过多少次零 才能在省选逆袭 手指要多少次掠过键盘 才能安心地休息 \(OI\)啊 我的朋友 在风中\(AK\) ...

  10. windows7下c++11环境搭建

    1.安装codeblocks 13.12 2.下载安装tdm-gcc-4.8.1-3 3.配置coldblocks的编译器(settings->compiler->compiler set ...