Entity Framework中System.Data.Entity.Validation.DbEntityValidationException

首页 | 新闻 | 交流 | 问吧 | 文档 | 手册 | 下载 | 博客

Entity Framework中System.Data.Entity.Validation.DbEntityValidationException

作者:  时间: 2011-05-27

        [Required(ErrorMessage = "*电话"), StringLength(30, MinimumLength = 6, ErrorMessage = "请输入电话6到30位数字")]
        public string Tel { get; set; }
        [Required(ErrorMessage = "*地址"), StringLength(150, MinimumLength = 10, ErrorMessage = "请输入家庭地址10到80位")]

如果model中使用了MinimumLength 来限制字段最小长度,在添加到时候没有按照此规则添加数据 就会得到下面的错误:

System.Data.Entity.Validation.DbEntityValidationException: Validation failed for one or more entities. See 'EntityValidationErrors' property for more details