asp.net-mvc – EF 4.1 Code First:“非空值类型’DateTime’”
发布时间:2020-12-15 22:57:17 所属栏目:asp.Net 来源:网络整理
导读:在初始开发和测试之后,我已经将MVC3应用程序指向包含实时数据的现有数据库. 但是我收到与“datetime”类型的Date1类型相关的错误. The 'Date1' property on 'StaffAttachment' could not be set to a 'null' value. You must set this property to a non-nul
在初始开发和测试之后,我已经将MVC3应用程序指向包含实时数据的现有数据库.
但是我收到与“datetime”类型的Date1类型相关的错误. The 'Date1' property on 'StaffAttachment' could not be set to a 'null' value. You must set this property to a non-null value of type 'DateTime'. 这是告诉我,日期中的所有行都必须有日期,而不是空吗?如果我不想在特定行上设置日期,该怎么办? 任何人都可以提供解决这个问题的建议? 谢谢保罗 编辑1(过帐模型) public class StaffAttachment { [Key] public int AttachmentID { get; set; } public int? StaffID { get; set; } public int? TypeID { get; set; } [Required] [DisplayName("Proof of ID")] public int? AttachmentTypeID { get; set; } [Required] [DisplayName("ID Reference")] public string Reference1 { get; set; } public string Reference2 { get; set; } public string DateType { get; set; } [DisplayName("Expiry Date")] public DateTime Date1 { get; set; } [Required] public DateTime Date2 { get; set; } public DateTime Date3 { get; set; } public DateTime Date4 { get; set; } public string AttachmentPath { get; set; } public int? ValidatedUserID { get; set; } public DateTime ValidatedDate { get; set; } public int? CreatedUserID { get; set; } public DateTime CreatedDate { get; set; } public int? EditedUserID { get; set; } public DateTime EditedDate { get; set; } public TimeSpan TimeStamp { get; set; } public string FileName { get; set; } public byte[] FileImage { get; set; } public int AttachmentSection { get; set; } } 解决方法
它看起来像您指向的数据库具有Date1的空值.如果您确实不想为所有行设置日期,只需使您的Date1属性为空: public DateTime? Date1{get;set;} 或者,您可以为当前没有通过SQL设置datetime的所有行放置默认日期. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net – 如何在按下键盘上的“输入”键时将焦点转移到按
- asp.net-mvc – ASP.Net MVC – 重定向到路由提供Redirect
- asp.net – 获取Gridview中隐藏列的值
- asp.net-mvc-3 – 使用多个Web应用程序共享控制器和视图
- 使用ASP.NET MVC和JQuery表单插件/文件上传检测IsAjaxReque
- asp.net – 为什么压缩ScriptResource.axd,即使禁用了IIS压
- asp.net-mvc – 如何使用ASP.NET Core,2.0中的Razor Pages处
- asp.net – 如何在iTextSharp中显示水平线
- asp.net-mvc – 使用CORS和IE9(XDomainRequest对象)的ASP W
- 解决:目录不存在。<br>参数名: directoryVirtualPath)
推荐文章
站长推荐
热点阅读