开发者

ActiveRecord/NHibernate DateTime problem

开发者 https://www.devze.com 2023-01-12 05:26 出处:网络
I\'m using ActiveRecord/NHibernate for ORM mapping in my project with PostgreSQL 8.4. I have following issue

I'm using ActiveRecord/NHibernate for ORM mapping in my project with PostgreSQL 8.4. I have following issue

For class mapping

 [ActiveRecord(Schema = "public", Table = "test_bean")]
 public class TestBean
 {
  [PrimaryKey(SequenceName = "test_bean_id_seq", Generator = PrimaryKeyType.Sequence)]
  public int ID { get; set; }开发者_如何学C

  [Castle.ActiveRecord.Property("time")]
  public DateTime Time { get; set; }
 }

and SQL DDL

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

When I save objects in DB ActiveRecord/NHibernate will truncate/ignore milliseconds component of DateTime field. I have made some research and found this post but I would prefer solution that doesn't require writing custom type.


Use a Timestamp NHibernate type (similar question, docs)

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

精彩评论

暂无评论...
验证码 换一张
取 消