ActiveRecord/NHibernate 日期时间问题
我在 PostgreSQL 8.4 项目中使用 ActiveRecord
/NHibernate
进行 ORM 映射。 我有以下问题:
对于类映射
[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 但我更喜欢不需要编写自定义类型的解决方案。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
Timestamp
NHibernate 类型 (类似问题,文档)Use a
Timestamp
NHibernate type (similar question, docs)