使用Nhibernate和MS sql server插入查询的C#日期时间异常

保存时出现异常

实体 -

 public class AuditCaseAccess : BaseClass
        {
            public virtual int UserID { get; set; }
            public virtual int CaseID { get; set; }
            public virtual DateTime CaseAccessTime { get; set; }
        }

Mapper -

 class AuditCaseAccessMap : ClassMap<AuditCaseAccess>
    {
        public AuditCaseAccessMap()
        {
            Id(x => x.ID);

            Map(x=>x.UserID);
            Map(x=>x.CaseID);
            Map(x=>x.CaseAccessTime);

            Table("tbl_AuditCaseAccess");
        }
    }

保存方法 -

  public bool Save(T persistableEntity)
        {
            if (persistableEntity != null)
            {
                session.BeginTransaction();
                session.Save(persistableEntity);
                session.Transaction.Commit();
                return true;
            }
            return false;
        }

SqlDateTime溢出。 必须介于1/1/1753 12:00:00 AM和12/31/9999 11:59:59 PM之间。

但在Sql profiler插入查询似乎是正确的 -

exec sp_executesql N'INSERT INTO dbo.tbl_AuditCaseAccess (UserID, CaseID, CaseAccessTime) VALUES (@p0, @p1, @p2); select SCOPE_IDENTITY()',N'@p0 int,@p1 int,@p2 datetime',@p0=1060,@p1=16205,@p2='2016-03-29 17:30:58'
链接地址: http://www.djcxy.com/p/26975.html

上一篇: C# datetime Exception on insert query using Nhibernate and MS sql server

下一篇: NHibernate Sqldatetime must be between 1/1/1753 and 12/31/9999