2010-08-16 58 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;}