2010-08-16 64 views
0

我在使用PostgreSQL 8.4的项目中使用ActiveRecord/NHibernate进行ORM映射。 我有以下问题ActiveRecord/NHibernate DateTime问题

对于类映射

[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,但我更喜欢不需要编写自定义类型的解决方案。

+0

顺便说一句,你可能想使这些属性的虚拟,使延迟加载 – 2010-08-16 14:34:48

回答

2

使用Timestamp NHibernate的类型(similar questiondocs

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