如何使用Entity Framework来管理GetDate() [英] How to manage GetDate() with Entity Framework

查看:172
本文介绍了如何使用Entity Framework来管理GetDate()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的数据库表1中有一列这样的列。

I have a column like this in 1 of my database tables

DateCreated, datetime, default(GetDate()), not null

我正在尝试使用实体框架在这个表上插入这样.. 。

I am trying to use the Entity Framework to do an insert on this table like this...

        PlaygroundEntities context = new PlaygroundEntities();

        Person p = new Person
        {
            Status = PersonStatus.Alive,
            BirthDate = new DateTime(1982,3,18),
            Name = "Joe Smith"
        };

        context.AddToPeople(p);
        context.SaveChanges();

当我运行此代码时,我收到以下错误

When i run this code i get the following error

The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value.\r\nThe statement has been terminated.

所以我试着设置StoreGeneratedPattern来计算...同样的事情,然后身份...同样的事情。任何想法?

So i tried setting the StoreGeneratedPattern to computed... same thing, then identity... same thing. Any ideas?

推荐答案

将DateCreated的类型更改为datetime2可能会解决问题。

Changing type of DateCreated to datetime2 might solve the problem.

datetime 2007-05-08 12:35:29.123

datetime 2007-05-08 12:35:29.123

datetime2 2007-05-08 12:35:29。 12345

datetime2 2007-05-08 12:35:29. 12345

参考: http://technet.microsoft.com/en-us/library/bb677335.aspx67

这篇关于如何使用Entity Framework来管理GetDate()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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