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 ...
随机推荐
- shell脚本默认变量值
脚本参数相关: $# 是传给脚本的参数个数 $ 是脚本本身的名字 $ 是传递给该shell脚本的第一个参数 $ 是传递给该shell脚本的第二个参数 $@ 是传给脚本的所有参数的列表 $* 是以一个单 ...
- 斯坦福机器学习视频笔记 Week2 多元线性回归 Linear Regression with Multiple Variables
相比于week1中讨论的单变量的线性回归,多元线性回归更具有一般性,应用范围也更大,更贴近实际. Multiple Features 上面就是接上次的例子,将房价预测问题进行扩充,添加多个特征(fea ...
- 自底向上归并排序(Merge Sort)
一.思路 另一种实现归并排序的方法是,先归并微型数组,再成对归并得到的子数组,直到将整个数组归并在一起. 我们先进行1-by-1归并,然后2-by-2归并,4-by-4归并,如此下去. 在最后一次归并 ...
- CSS: iPhone Custom CSS
1. [代码][CSS]代码 <style type="text/css" media="screen"> /* iPhone 4@media on ...
- jQuery学习(2)
<script type="text/javascript"> //给网页中所有的<p>元素添加onclick事件 $("p").cli ...
- php数据结构课程---2、链表(php中 是如何实现单链表的(也就是php中如何实现对象引用的))
php数据结构课程---2.链表(php中 是如何实现单链表的(也就是php中如何实现对象引用的)) 一.总结 一句话总结: php是弱类型语言,变量即可表示数值,也可表示对象:链表节点的数据域的值就 ...
- php: xampp安装对应的phalcon版本(3.2.2-php5.6):比如redis-php5.6, php_igbinary-5.6
php: xampp安装对应的phalcon版本(3.2.2-php5.6):比如redis-php5.6, php_igbinary-5.6 一.php安装redis扩展 1.使用phpinfo ...
- 问题杂烩(scrollTop/背景透明度动画)
今天给同学找我帮忙写js,是公司里的活..我是不是应该跟他要钱哈哈,不过一顿饭肯定是免不了的了. 言归正传,今天写了三个小东西,因为兼容性的问题,用jq写的(很是别扭的说,但是没办法啊,一边看api一 ...
- Python-unittest参数化
做接口测试的时候,同一个接口,输入的参数一样,参数值不一样,这时候,写多个case就是冗余的,就可以用参数化来实现,第三方模块有这个实现参数化的功能,安装pip install nose-param ...
- L106 Three things we learned from day one at the World Cup
Hosts Russia got the World Cup off to a flying start by hammering Saudi Arabia 5-0 in the opening ga ...