gpt4 book ai didi

nhibernate - 流畅的 Nhiberhate 和缺失的毫秒

转载 作者:行者123 更新时间:2023-12-03 22:22:47 25 4
gpt4 key购买 nike

我在当前项目中使用 Fluent Nhibernate 和 Nhibernate。我需要将时间记录到毫秒。我有这个用于我的映射

            Map(x => x.SystemDateTime)
.CustomType("Timestamp")
.Not.Nullable();

我生成了 hbm.xml 文件,该行如下:
<property name="SystemDateTime" type="Timestamp">
<column name="SystemDateTime" not-null="true" />
</property>

我读过这是修复程序,但数据库中的记录没有毫秒。有没有人解决过这个问题。我也尝试过 CustomSqlType。

谢谢

最佳答案

我们使用与您相同的方法,它确实正确存储了毫秒。如果您不总是这样做,尽管您的旧记录将丢失毫秒。

假设您想为所有 DateTime 字段存储毫秒,您可以使用约定:

public class OurPropertyConventions : IPropertyConvention
{
public void Apply(IPropertyInstance instance)
{
Type type = instance.Property.PropertyType;
if (type == typeof(DateTime) || type == typeof(DateTime?))
instance.CustomType("Timestamp");
}
}

您的映射现在可以是:
Map(x => x.SystemDateTime).Not.Nullable();

关于nhibernate - 流畅的 Nhiberhate 和缺失的毫秒,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2874057/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com