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 即可。

最新文章

  1. [LeetCode] Single Number II 单独的数字之二
  2. Java关键字介绍
  3. js 进度条,可实现结束和重新开始
  4. Android studio -VSN 使用笔记
  5. Nginx-限制汇总
  6. HDU 2222 Keywords Search(查询关键字)
  7. Shell Script Tutorials (0 ~ 62)
  8. BZOJ 1934: [Shoi2007]Vote 善意的投票 最小割
  9. windows Oracle DBases auto backUp
  10. POJ 3233 Matrix Power Series(矩阵高速功率+二分法)
  11. SHOI2008仙人掌图(tarjan+dp)
  12. Java 之 Web前端(二)
  13. python之流程控制与运算符
  14. 二层协议--MPLS协议总结
  15. 开始写博客,学习Linq(5)
  16. CSS全局居中
  17. es中的停用词
  18. luogu Eat the Trees
  19. 移动端效果之ScrollList
  20. UVa 557 汉堡

热门文章

  1. Eclipse打不开 提示an error has occurred.see the log file
  2. Android 开发工具类 13_ SaxService
  3. Spring MVC 实现web Socket向前端实时推送数据
  4. ActiveMQ安全机制设置
  5. [转]ng-grid Auto / Dynamic Height
  6. 解决 windows npm ERR! asyncWrite is not a function 问题
  7. 用fullPage来实现全屏滚动效果
  8. Java:使用DOM4j来实现读写XML文件中的属性和元素
  9. IDEA 中将已有项目放到 GitHub 上去
  10. MyBatis入门(一)—— 入门案例