0

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; }

  [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.

Stefan Steinegger
  • 63,782
  • 15
  • 129
  • 193
jethro
  • 18,177
  • 7
  • 46
  • 42

1 Answers1

2

Use a Timestamp NHibernate type (similar question, docs)

[Property(ColumnType = "Timestamp")]
DateTime Time {get;set;}
Community
  • 1
  • 1
Mauricio Scheffer
  • 98,863
  • 23
  • 192
  • 275