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
This did not work for me:
while this did:
I have no idea why, though :/
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:
Your mappings can now just be:
Revisiting this, as previous answers were slightly incomplete.
Assuming you want all your DateTime fields stored with full details and millisecond precision, use
TIMESTAMP(6) WITH TIME ZONE
as the SQL column type. You'll need a property convention for FluentNHibernate:You then add this convention to your fluent configuration session factory building code: