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. 【Flask】模板继承

    # 模版继承笔记: ### 为什么需要模版继承:模版继承可以把一些公用的代码单独抽取出来放到一个父模板中.以后子模板直接继承就可以使用了.这样可以重复性的代码,并且以后修改起来也比较方便. ### 模 ...

  2. dedecms常用标签

    下面总结了58种常见的标签调用,包括关键描述调用.指定调用栏目.列表文章调用.频道栏目调用.当前栏目名称.栏目导航调用.模板路径调用.网站标题调用.友情链接调用.网站版权调用.网站备案调用.当前位置调 ...

  3. Android系统Recovery工作原理之使用update.zip升级过程分析(一)---update.zip包的制作【转】

    本文转载自:http://blog.csdn.net/mu0206mu/article/details/7399822 这篇及以后的篇幅将通过分析update.zip包在具体Android系统升级的过 ...

  4. 三维bfs

    胜利大逃亡 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submi ...

  5. Android 动态权限申请

    package com.dragon.android.permissionrequest; import android.Manifest; import android.content.Dialog ...

  6. 基于js的网页换肤(不需要刷新整个页面,只需替换css文件)

    1. [代码][JS]代码    <HTML><HEAD><link ID="skin" rel="stylesheet" typ ...

  7. node.js+express验证码的实现

    安装ccap库 npm install ccap var ccap = require(); var captcha = ccap({ width:190, height:50, offset:30, ...

  8. 如何在MySQL中查询当前数据上一条和下一条的记录

    如果ID是主键或者有索引,可以直接查找: 方法一: 查询上一条记录的SQL语句(如果有其他的查询条件记得加上other_conditions以免出现不必要的错误): select * from tab ...

  9. 初次接触Servlet3.0

    Servlet3.0 一.要求 MyEclipes10.0或以上版本! 发布到Tomcat7.0或以上版本!二.步骤 创建JavaEE6.0应用 --------------------------- ...

  10. Mybatis学习--Java API

    学习笔记,选自Mybatis官方中文文档:http://www.mybatis.org/mybatis-3/zh/java-api.html#directoryStructure 既然你已经知道如何配 ...