[EntityFramework] 对 DateTime 类型使用 SQL 服务器时间或者字段默认值
2024-10-19 06:29:38
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 即可。
最新文章
- [LeetCode] Single Number II 单独的数字之二
- Java关键字介绍
- js 进度条,可实现结束和重新开始
- Android studio -VSN 使用笔记
- Nginx-限制汇总
- HDU 2222 Keywords Search(查询关键字)
- Shell Script Tutorials (0 ~ 62)
- BZOJ 1934: [Shoi2007]Vote 善意的投票 最小割
- windows Oracle DBases auto backUp
- POJ 3233 Matrix Power Series(矩阵高速功率+二分法)
- SHOI2008仙人掌图(tarjan+dp)
- Java 之 Web前端(二)
- python之流程控制与运算符
- 二层协议--MPLS协议总结
- 开始写博客,学习Linq(5)
- CSS全局居中
- es中的停用词
- luogu Eat the Trees
- 移动端效果之ScrollList
- UVa 557 汉堡
热门文章
- Eclipse打不开 提示an error has occurred.see the log file
- Android 开发工具类 13_ SaxService
- Spring MVC 实现web Socket向前端实时推送数据
- ActiveMQ安全机制设置
- [转]ng-grid Auto / Dynamic Height
- 解决 windows npm ERR! asyncWrite is not a function 问题
- 用fullPage来实现全屏滚动效果
- Java:使用DOM4j来实现读写XML文件中的属性和元素
- IDEA 中将已有项目放到 GitHub 上去
- MyBatis入门(一)—— 入门案例