Fluent Nhiberhate And Missing Milliseconds

fluent-nhibernate, fluent-nhibernate-mapping, nhibernate

Solution

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();

Problem

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

Original source