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;}
精彩评论