数据注解特性--Column
2015-12-06 17:07
316 查看
Column特性可以用到类的属性中,Code-First默认的约定是使用属性名称作为列名.这个Column特性可以打破这个特性。
看下面的代码:
![](http://images2015.cnblogs.com/blog/745221/201512/745221-20151206165918097-233422060.jpg)
当然你还可以指定列的顺序【Order】和类型【Type】,请看:
看下面的代码:
using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using System.Linq; using System.Text; using System.Threading.Tasks; namespace EF2 { [Table("StudentMaster",Schema="WaHaHa")] public class Student { [Key] [Column(Order=1)] public int StudentKey1 { get; set; } [Key] [Column(Order=2)] public int StudentKey2 { get; set; } [MaxLength(20)] [ConcurrencyCheck] [Required] public string StudentName { get; set; } [NotMapped()] public int? Age { get; set; } [Column("StandardID")] public int StdId { get; set; } [ForeignKey("StdId")] public virtual Standard Standard { get; set; } } }
![](http://images2015.cnblogs.com/blog/745221/201512/745221-20151206165918097-233422060.jpg)
当然你还可以指定列的顺序【Order】和类型【Type】,请看:
using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using System.Linq; using System.Text; using System.Threading.Tasks; namespace EF2 { [Table("StudentMaster",Schema="WaHaHa")] public class Student { [Key] [Column(Order=1)] public int StudentKey1 { get; set; } [Key] [Column(Order=2)] public int StudentKey2 { get; set; } [MaxLength(20)] [ConcurrencyCheck] [Required] [Column("SName",Order=4,TypeName="varchar")] public string StudentName { get; set; } [NotMapped()] public int? Age { get; set; } [Column("StandardID",Order=3,TypeName="int")] public int StdId { get; set; } [ForeignKey("StdId")] public virtual Standard Standard { get; set; } } }
![](http://images2015.cnblogs.com/blog/745221/201512/745221-20151206170625472-1865726311.jpg)
相关文章推荐
- 装饰者模式(包装模式)
- Xcode真机调试遇到The identity used to sign the executable is no longer valid
- 编程成长日记――求最大公约数
- 虫师----随笔分类 -selenium
- 拓扑排序杭电 1285确定比赛名次
- 读书笔记 -- 005_数据挖掘_度量数据的相似性和相异性
- Android批量打包提速 - 1分钟900个市场不是梦
- linux下配置tomcat虚拟目录
- Java环境变量的作用
- linux中cat、more、less、tail、head命令的区别
- 写给一位期望做得更好的大学生
- Divideing Jewels
- NVIDIA CuDNN 安装说明
- BestCoder Round #65
- C++学习笔记33——友元
- Bootstrap中六种表格样式
- 网页设计的一些技巧
- Kmeans、Kmeans++和KNN算法比较
- 通过左右滑动缩放图片
- 黑苹果安装傻瓜教程