EF Code First教程-02 约定配置
示例:
public class Phone { [Key] //主键 public int Id { get; set; } [Required] //不能为空 [MinLength(2),MaxLength(20)] //最小长度2,最大长度20 public string Name { get; set; } [StringLength(50)] //字符串长度为50 public string Number { get; set; } public DateTime CreateDate { get; set; } public bool IsValid { get; set; } public string Carrieroperator { get; set; } }
更多的约定配置,可以参考这里:http://www.cnblogs.com/Gyoung/archive/2013/01/17/2864150.html