C#EF6保存datetimeoffset

时间:2016-03-24 14:36:09

标签: c# sql-server asp.net-mvc entity-framework-6

我有简单对象

class SimpleObject
{
   public int id { get; set;}
   public System.DateTimeOffset timestamp { get; set; }
}

Controler中的方法

private dbEntities db = new dbEntities();
public object SaveSO()
    {
        SimpleObject so = new SimpleObject();
        DateTimeOffset ts = DateTimeOffset.Now;
        try
        {
            so.timestamp = ts;
            db.SimpleObject.Add(so);
            db.SaveChanges();
            return View("index");
        }
        catch (Exception ex)
        { 
            Debug.Write (ts + " ---> " + ex);
            return View("index");
        }
    }

Controler在DB中保存对象,但时间为空。为什么呢?

0 个答案:

没有答案