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 ...
随机推荐
- Memory Layout (Virtual address space of a C process)
Memory Layout (Virtual address space of a C process) 分类: C语言基础2012-12-06 23:16 2174人阅读 评论(0) 收藏 举报 f ...
- Oracle创建函数
--创建函数语法 create [or replace] function [schema.]function_name (函数参数列表) --参数有IN.OUT.IN OUT三种类型:IN代表需要输 ...
- php深入浅出session
1. session概念 0 2. http协议与状态保持 0 3. 理解cookie 0 4. php中session的生成机制 2 5. php中session的过期回收机制 3 6. php中s ...
- 分享知识-快乐自己:Hadoop 常用基础命令
1): 查询目录下的文件 查询根目录: 查询文件夹下的文件: 2):创建文件夹 3):上传本地文件到HDFS中 上传多个文件: 4):删除文件 5):删除文件夹 6):从HDFS中复制文件到本地 7) ...
- HTTP-接触
[HTTP]http是基于TCP/IP协议的应用层协议,他不涉及数据包(packet)传输,主要规定了客户端和服务器之间的通信格式,默认端口是80端口. 不同版本http协议里的相关概念[Conten ...
- name lookup of 'res' changed for new ISO 'res' scoping
#include<iostream> using namespace std; int pow ( int val, int exp ); int main() { int val = 2 ...
- Hibernate映射--基本类映射和对象关系映射(转)
原文地址:http://blog.csdn.net/lovesummerforever/article/details/20901011 尊重原创,请访问原网址 回想一些我们在没有学习ssh的时候 ...
- appium-环境搭建(一)
adb命令 adb的全称为Android Debug Bridge,就是起到调试桥的作用.借助adb工具,我们可以管理设备或者手机模拟器的状态.还可以进行很多手机操作,如安装软件\系统升级\运行she ...
- Java_异常_02_java.lang.NoClassDefFoundError: org/apache/log4j/Level
总结:解析Json时,除了要导入json-lib-2.2-jdk15.jar外,还要导入: commons-beanutils.jar, commons-httpclient.jar, commons ...
- Linux基本语法
Shell编程 摘要: Shell历史 Shell的作用是解释用户的命令,用户输入一条命令,Shell就解释执行一条,这条方式称为交互式(interactive),Shell还有一种执行命令的方式称为 ...