一个DATETIME2数据类型到datetime数据类型的转换导致超出范围的值 [英] The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value

查看:665
本文介绍了一个DATETIME2数据类型到datetime数据类型的转换导致超出范围的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我在哪里编辑现有的数据库更新paticular场ASP.NET MVC应用程序,的DateTime 。我的数据库有4个领域,其中两个是的 dateCreated会 DateModified 。当我尝试更新的领域,我想保持的 dateCreated会的时间是相同的,没有理由去更新它的创建日期,我使用 DateTime.Now

I have an ASP.NET MVC application where I am editing an existing database to update a paticular field, DateTime. My database has 4 fields, two of which are DateCreated and DateModified. When I try to update the field, I want to keep DateCreated time the same, no reason to update the date it was created, and I change the DateModified time to the current time using DateTime.Now

下面是给定的code只是在情况下,我做错了什么。这是使用ASP.NET MVC所以要温柔我的第一次。我看到其他的答案,其中上下文叫,但我找不到它的任何引用。当我运行该应用程序我在标题收到错误消息和 contractEntity.SaveChanges()是红色的。

Here is the given code just in-case I am doing something wrong. This is my first time using ASP.NET MVC so go gentle. I have seen other answers where Context is called, but I can't find any reference to it. When I run the application I receive the error message in the title and the contractEntity.SaveChanges() is in red.

public ActionResult Edit(Contract editContract) {
var contract = (from c in contractEntity.Contracts where c.Id == editContract.Id select c).First();
if (!ModelState.IsValid)
    return View(contract);
// editContract.DateCreated = contract.DateCreated;
// editContract.DateModified = DateTime.Now;
  contractEntity.ApplyCurrentValues(contract.EntityKey.EntitySetName, editContract);
  contractEntity.SaveChanges();
  return RedirectToAction("Index");
}

请,任何帮助是AP preciated。谢谢你。

Please, any help is appreciated. Thanks.

推荐答案

看完<一个href=\"http://www.ifunky.net/blog/post/Type-datetime2-is-not-a-defined-system-type-Entity-Framework.aspx\">this网站我发现打开.edmx文件为我的数据库,并更改:

After reading this website I found to open the .edmx file for my database and change:

<...Provider="System.Data.SqlClient" ProviderManifestToken="2008".../>

<...Provider="System.Data.SqlClient" ProviderManifestToken="2005".../>

这是可接受的,或者有更好的方法来修复该错误?

Is this acceptable or is there a better approach to fixing that error?

这篇关于一个DATETIME2数据类型到datetime数据类型的转换导致超出范围的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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