流利Nhiberhate和失踪毫秒 [英] Fluent Nhiberhate And Missing Milliseconds

查看:130
本文介绍了流利Nhiberhate和失踪毫秒的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Fluent Nhibernate和Nhibernate来处理当前的项目。我需要把时间记录到毫秒。我有这个用于我的映射
$ b $ pre $ code Map(x => x.SystemDateTime)
.CustomType(Timestamp )
.Not.Nullable();

我生成了hbm.xml文件,行如下:

 < property name =SystemDateTimetype =Timestamp> 
< column name =SystemDateTimenot-null =true/>
< / property>

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

谢谢

解决方案

和你一样的方法,它正确地存储毫秒。如果你并不总是这样做,尽管你的旧记录将会失去毫秒。



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

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




$ p现在你的映射可以是:


$ b $

  Map(x => x.SystemDateTime).Not.Nullable(); 


I am using Fluent Nhibernate and Nhibernate for my current project. I need to record the time to the millisecond. I have this for my mapping

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

I genertaed the hbm.xml files and the line is the following:

<property name="SystemDateTime" type="Timestamp">
  <column name="SystemDateTime" not-null="true" />
</property>

I have read this is the fix, but the records in the database do not have the milliseconds. Has anyone solved this issue. And I have tried CustomSqlType also.

Thanks

解决方案

We use the same approach as you and it does correctly store the milliseconds. If you weren't always doing it that way though your old records will have lost their milliseconds.

Assuming you want to store milliseconds for all of your DateTime fields, you could use a convention:

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

Your mappings can now just be:

Map(x => x.SystemDateTime).Not.Nullable();

这篇关于流利Nhiberhate和失踪毫秒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆