Entity Framework Code-First(9.8):DataAnnotations - Column Attribute
2016-07-05 16:37
369 查看
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=1, 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.
相关文章推荐
- Wireshark网络抓包工具--过滤
- 例题10-13 UVA - 580 Critical Mass 危险的组合(递推)
- impdp导入遇到的问题
- .net 单件模式(基类)
- 测试GMS内应用注意事项
- ThinkPHP3.2.3 - 课程总笔记
- android之图像的操作
- mysqld_multi 多实例启动工具
- JSON字符串转化为字典
- matlab排序函数
- CentOS学习:第一天
- 有关KeyStore的问题
- MySQL用户权限管理详解
- 2016年,文本分析、情感分析和社交分析的10大趋势
- C++ 类的静态成员
- hibernate之翻页的实现
- springmvc加载配置文件中的bean的方法
- JSON的简单应用
- 自测过程,开发要有足够细心和敏感度
- listView小总结