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 ...
随机推荐
- python学习笔记20160413
1. type(val) #查看val的类型. 2. 出现错误的时候, 读懂错误信息.3. raw_input('xxx') #读取用户输入都是string类型数据.4. ValueError: in ...
- poj 1144 Network 【求一个网络的割点的个数 矩阵建图+模板应用】
题目地址:http://poj.org/problem?id=1144 题目:输入一个n,代表有n个节点(如果n==0就结束程序运行). 在当下n的这一组数据,可能会有若干行数据,每行先输入一个节点a ...
- SQL 优化案例
create or replace procedure SP_GET_NEWEST_CAPTCHA( v_ACCOUNT_ID in VARCHAR2, --接收短信的手机号 v_Tail_num i ...
- 算法(Algorithms)第4版 练习 2.2.11(1)
实现关键代码: private static void sort(Comparable[] input, int lo, int hi) { if((lo+CUTOFF-1) >= hi) { ...
- adobe flash player 下载地址
1. https://www.adobe.com/cn/products/flashplayer/distribution3.html
- intel dpdk api interrupt module 中断模块介绍
声明:此文档只做学习交流使用,请勿用作其他商业用途 author:朝阳_tonyE-mail : linzhaolover@gmail.comCreate Date: 2013-7-12 11:46: ...
- kreuz-frankfurt-sample-generic-2019-02-08.xodr文件解读
第1行:xml语法所遵循的版本. L2:文件封装标记. L3:Opendrive的主要修订编号 次要修订编号 供应商. L4:记录有关地理参考坐标系的参数,投影-横轴墨卡托 a-地球椭球长半 ...
- Sobel边缘检测
Sobel算子:[-1 0 1 -2 0 2 -1 0 1] 用此算子与原图像做卷积,可以检测出垂直方向的边缘.算子作用在图像的第二列,结果是:200,200,200:作用在第三列,结果是 ...
- Mysql5.5 InnoDB存储引擎配置和优化
环境为CentOS系统,1G内存,Mysql5.5.30.在/etc/my.cnf内添加: 复制代码代码如下: skip-external-lockingskip-name-resolvemax_co ...
- 13 Python 函数进阶
代码在运行伊始,创建的存储“变量名与值的关系”的空间叫做全局命名空间,在函数的运行中开辟的临时的空间叫做局部命名空间 命名空间和作用域 命名空间的本质:存放名字与值的绑定关系 >>> ...