【译】第17节---数据注解-Column
Column属性可以应用于类的属性。 默认Code First约定创建与名称相同的列名称。 Column 属性覆盖此默认约定。 EF Code-First将在给定属性的Column属性中创建一个具有指定名称的列。
请看以下示例:
using System.ComponentModel.DataAnnotations.Schema; public class Student
{
public Student()
{ }
public int StudentID { get; set; } [Column("Name")]
public string StudentName { get; set; } }
如上例所示,Column属性应用于Student类的StudentName属性。 因此,Code-First将覆盖默认约定,并在Student表中创建Name列而不是StudentName列,如下所示:

你还可以使用Column属性指定列的顺序和类型,如下所示:
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; } }
上面的代码创建了一个varchar类型的Name列作为Student中的第一列,如下所示:

【译】第17节---数据注解-Column的更多相关文章
- 【译】第10节---数据注解-Key
原文:http://www.entityframeworktutorial.net/code-first/key-dataannotations-attribute-in-code-first.asp ...
- 【译】第20节---数据注解-InverseProperty
原文:http://www.entityframeworktutorial.net/code-first/inverseproperty-dataannotations-attribute-in-co ...
- 【译】第19节---数据注解-NotMapped
原文:http://www.entityframeworktutorial.net/code-first/notmapped-dataannotations-attribute-in-code-fir ...
- 【译】第18节---数据注解-ForeignKey
原文:http://www.entityframeworktutorial.net/code-first/foreignkey-dataannotations-attribute-in-code-fi ...
- 【译】第16节---数据注解-Table
原文:http://www.entityframeworktutorial.net/code-first/table-dataannotations-attribute-in-code-first.a ...
- 【译】第15节---数据注解-StringLength
原文:http://www.entityframeworktutorial.net/code-first/stringlength-dataannotations-attribute-in-code- ...
- 【译】第14节---数据注解-MaxLength/MinLength
原文:http://www.entityframeworktutorial.net/code-first/maxlength-minlength-dataannotations-attribute-i ...
- 【译】第13节---数据注解-Required
原文:http://www.entityframeworktutorial.net/code-first/required-attribute-dataannotations-in-code-firs ...
- 【译】第12节---数据注解-ConcurrencyCheck
原文:http://www.entityframeworktutorial.net/code-first/concurrencycheck-dataannotations-attribute-in-c ...
随机推荐
- python type的用法
目录 描述 语法 用法 type和isinstance Type和Object 描述 python的 type 函数有两个用法,当只有一个参数的时候,返回对象的类型.当有三个参数的时候返回一个类对象. ...
- 转:C#清除回收站
SHEmptyRecycleBin是一个内核API方法,该方法能够清空回收站中的文件,该方法在C#中需要手动的引入方法所在的类库.该方法在C#中的声明语法如下: [DllImportAttrbute( ...
- POJ 1018 Communication System (动态规划)
We have received an order from Pizoor Communications Inc. for a special communication system. The sy ...
- GoldenGate实时投递数据到大数据平台(6)– HDFS
GoldenGate可以实时将RDBMS的数据投递到HDFS中,在前面的文章中,已经配置过投递到kafka, mongodb等数据平台,本文通过OGG for bigdata的介质中自带的示例演示实时 ...
- sping的quartz设置定时任务
除了spring相关的jar包之外,还需要引入quartz-all-1.8.6.jar 下载地址:http://www.quartz-scheduler.org/downloads/ spring配置 ...
- String小案例(**)、包装类型和普通数据类型的转换(拆装箱)
###String用法: package StringTest; /**功能: * 判断Java文件名是否正确,判断邮箱格式是否正确 * 其中:合法的文件名应该以.java结尾 * 合法的邮箱名至少包 ...
- 微信h5支付“网站域名ICP备案主体与商户号主体不一致”的解决方法,H5微信支付 授权函下载
如下图所示: 微信h5支付“网站域名ICP备案主体与商户号主体不一致”: 需提交H5微信支付 授权函 下载地址:https://download.csdn.net/download/a72400815 ...
- php 获取顶级域名
/** * 获取顶级域名 * @param $url * @return string */ public static function getDoMain($url){ if(empty($url ...
- Linux 搭建安装Maven环境
1.前提条件: 1)下载并安装好JDK .在终端输入命令“java -version”,如果出现类似如下信息说明JDK安装成功. $ java -version java version " ...
- 【Python57--正则1】
一.正则表达式匹配IP地址 1.search()方法:用于在字符串中搜索正则表达式模式第一次出现的位置 >>> import re >>> re.search(r' ...