DATETIME2和ProviderManifestToken实体框架 [英] datetime2 and ProviderManifestToken in Entity Framework

查看:110
本文介绍了DATETIME2和ProviderManifestToken实体框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用实体框架和SQL Server 2008数据库的MVC应用程序。我用EF向导生成我的数据模型。

I have an MVC app using Entity Framework and a SQL Server 2008 database. I used the EF wizard to generate my data model.

我有一个标准的的DateTime 列SQL Server表。该EF模型是使用的System.DateTime

I have a SQL Server table with a standard DateTime column. The EF model is using System.DateTime.

但是,当我尝试插入一个新的记录到从我的应用程序这个表,而不指定此日期时间列的值,我得到的错误:

But when I try to insert a new record into this table from my application, without specifying a value for this DateTime column, I get the error:

一个DATETIME2数据类型到datetime数据类型的转换导致超出范围的值。

The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value.

我用Google搜索了一下,发现那人编辑EDMX和改变 ProviderManifestToken 。 Ovbiously将被覆盖,所以有一个更加永久性的修复或方法来解决这个问题?

I Googled a bit and found that people are editing the edmx and changing the ProviderManifestToken. Ovbiously that will be overwritten, so is there a more permanent fix or way to fix this?

推荐答案

问题是因为,像你说的,你不上,导致其默认为0001-01的实体的DateTime属性设置任何值-01',这绝对是超出范围的 日期时间 SQL Server上的列。 DateTime类型日期范围的 1753年1月1日,到9999年12月31 的。
搜索结果
为了解决这个问题,你必须要么把它发送到SQL Server之前指定一个范围内的值,以该财产或改变你的数据库列类型的
DATETIME2 拥有的 0001-01-01至9999-12-31的日期范围

The problem is because, like you said, you're not setting any value for that DateTime property on the entity which causes it to default to '0001-01-01' which is definitely out of range for datetime column on SQL Server. The datetime type date range is January 1, 1753, through December 31, 9999.

To solve this, you have to either assign an in range value to that property before sending it to SQL Server, or change your DB column type to datetime2 which has a date range of 0001-01-01 through 9999-12-31.

这篇关于DATETIME2和ProviderManifestToken实体框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆