首页 > 数据库技术 > 详细

[EntityFramework] 对 DateTime 类型使用 SQL 服务器时间或者字段默认值

时间:2014-09-11 16:54:12      阅读:301      评论:0      收藏:0      [点我收藏+]

DateTime 类型在 SQL 服务器上如果设置了默认值,在 EntityFramework 添加新行的时候想使用该默认值,则不能对新增加的实体的 DateTime 字段赋值。

但是如果新增加的实体 DateTime 不设置,会出现错误如下:

System.Data.Entity.Infrastructure.DbUpdateException - An error occurred while updating the entries. See the inner exception for details.
System.Data.Entity.Core.UpdateException - An error occurred while updating the entries. See the inner exception for details.
System.Data.SqlClient.SqlException - The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value.
The statement has been terminated.

解决方案:

定位到edmx文件,选中该 DateTime 类型的字段,在属性窗口中,将 StoreGeneratePattern 从 None 改为 Computed 即可。

[EntityFramework] 对 DateTime 类型使用 SQL 服务器时间或者字段默认值

原文:http://www.cnblogs.com/lionetchen/p/3966520.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!