行为[MaxLength]和[StringLength]属性有什么区别?
据我所知(除了[MaxLength]可以验证数组的最大长度)这些是相同的,有点多余?
我遇到了一个令人困惑的问题,在我的编辑或创建操作结果方法中,EF4将抛出一个DbEntityValidationException,内部消息说明:
字段Body必须是字符串或数组类型,最大长度为"128".
有问题的模型如下所示:
[Table("tblArticles")]
public class Article
{
[Key]
public int ID { get; set; }
[Required(ErrorMessage="Title must be included")]
public string Title { get; set; }
[AllowHtml]
public string Body { get; set; }
[Required(ErrorMessage="Start Date must be specified")]
[Display(Name="Start Date")]
[DisplayFormat(DataFormatString="dd-mm-yyyy")]
public DateTime? StartDate { get; set; }
[Required(ErrorMessage = "End Date must be specified")]
[Display(Name = "End Date")]
public DateTime? EndDate { get; set; }
public int Priority { get; set; }
public bool Archived { get; …Run Code Online (Sandbox Code Playgroud)