代码之家  ›  专栏  ›  技术社区  ›  jethro

ActiveRecord/NHibernate日期时间问题

  •  0
  • jethro  · 技术社区  · 15 年前

    我在用 ActiveRecord / NHibernate 在我的项目中使用postgresql8.4进行ORM映射。 我有以下问题

     [ActiveRecord(Schema = "public", Table = "test_bean")]
     public class TestBean
     {
      [PrimaryKey(SequenceName = "test_bean_id_seq", Generator = PrimaryKeyType.Sequence)]
      public int ID { get; set; }
    
      [Castle.ActiveRecord.Property("time")]
      public DateTime Time { get; set; }
     }
    

    和SQL DDL

    CREATE TABLE test_bean
    (
      id serial NOT NULL,
      time timestamp without time zone NOT NULL,
      CONSTRAINT test_bean_pk PRIMARY KEY (id)
    )
    

    当我在DB ActiveRecord中保存对象时,NHibernate将截断/忽略 DateTime 现场。我做了一些研究,发现了这个 post

    1 回复  |  直到 15 年前
        1
  •  2
  •   Community CDub    8 年前

    使用 Timestamp NHibernate型( similar question docs )

    [Property(ColumnType = "Timestamp")]
    DateTime Time {get;set;}