Entity Framework Code-First(9.8):DataAnnotations - Column Attribute
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的更多相关文章
- Entity Framework Code-First(9.6):DataAnnotations - StringLength Attribute
DataAnnotations - StringLength Attribute: StringLength attribute can be applied to a string type pro ...
- Entity Framework Code-First(9.5):DataAnnotations - MaxLength Attribute
DataAnnotations - MaxLength Attribute: MaxLength attribute can be applied to a string or array type ...
- Entity Framework Code-First(9.10):DataAnnotations - NotMapped Attribute
DataAnnotations - NotMapped Attribute: NotMapped attribute can be applied to properties of a class. ...
- Entity Framework Code-First(9.9):DataAnnotations - ForeignKey Attribute
DataAnnotations - ForeignKey Attribute: ForeignKey attribute can be applied to properties of a class ...
- Entity Framework Code-First(9.7):DataAnnotations - Table Attribute
DataAnnotations - Table Attribute: Table attribute can be applied to a class. Default Code-First con ...
- 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 ...
- Entity Framework Code-First(9.2):DataAnnotations - TimeStamp Attribute
DataAnnotations - TimeStamp Attribute: TimeStamp attribute can be applied to only one byte array pro ...
- Entity Framework Code-First(9.1):DataAnnotations - Key Attribute
DataAnnotations - Key Attribute: Key attribute can be applied to properties of a class. Default Code ...
- Entity Framework Code-First(9.3):DataAnnotations - ConcurrencyCheck Attribute
ConcurrencyCheck Attribute: ConcurrencyCheck attribute can be applied to a property of a domain clas ...
随机推荐
- 【leetcode刷题笔记】Implement strStr()
Implement strStr(). Returns a pointer to the first occurrence of needle in haystack, or null if need ...
- Linux查看硬盘使用情况
df df - report file system disk space usage df是查看文件系统磁盘使用情况的命令.如: # df -h Filesystem Size Used Avail ...
- 斯坦福机器学习视频笔记 Week1 线性回归和梯度下降 Linear Regression and Gradient Descent
最近开始学习Coursera上的斯坦福机器学习视频,我是刚刚接触机器学习,对此比较感兴趣:准备将我的学习笔记写下来, 作为我每天学习的签到吧,也希望和各位朋友交流学习. 这一系列的博客,我会不定期的更 ...
- systemd基本使用
参考金步国翻译的systemd中文手册: http://www.jinbuguo.com/systemd/index.html 金步国翻译质量都很高, 非常适合做参考 原文:https://wiki. ...
- C# Stopwatch与TimeSpan详解
http://www.cnblogs.com/newstart/archive/2012/09/21/2696884.html
- java的远程访问接口的实例
被别人远程调用和自己远程调用别人接口的理解: 被别人调用接口:其实没有什么神秘的,就是我们写一个正常的方法提供一个访问路径. 调用别人的接口:本质时一个Request请求,实际要使用到javax.ne ...
- php: 0跟字符串做比较永远是true。 php大bug。
php: 0跟字符串做比较永远是true. php大bug. 如: $a = 0; if( $a == 'excel') { echo "yes"; }else{ echo &qu ...
- 用一句SQL取出第 m 条到第 n 条记录的方法
1 --从Table 表中取出第 m 条到第 n 条的记录:(Not In 版本)2 3 SELECT TOP n-m+1 * 4 FROM Table 5 WHERE (id NOT IN (SEL ...
- Hibernate学习---第八节:继承关系的映射配置
1.单表继承 (1).实体类,代码如下: package learn.hibernate.bean; import java.util.Date; /** * 持久化类设计 * 注意: * 持久化类通 ...
- JQuery表单验证插件EasyValidator
本插件的宗旨是:用户无需写一行JS验证代码,只需在要验证的表单中加入相应的验证属性即可,让验证功能易维护,可扩展,更容易上手. DEMO中已经包含了常用的正则表达式,可以直接复用,为了考虑扩展性,所以 ...