views:

33

answers:

1

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.

+2  A: 

Use a Timestamp NHibernate type (similar question, docs)

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