Search code examples
c#nhibernatefluent-nhibernatenhibernate-mappingfluent-nhibernate-mapping

FluentNHibernate: Default precision of DateTime changed?


I am currently trying to migrate from FluentNHibernate 1.4 / NHibernate 3.4.1 to FluentNHibernate 2.1.2 / NHibernate 5.2.4. The used database is DB2 LUW 11.1, the .NET target framework is 4.61.

The problematic mapping line:

 Map(x => x.TimeStamp).Column("TS").Nullable();

I wrote a persistence test a long time ago that assures no milliseconds are persisted from the mapped DateTime property to the TIMESTAMP field. The test passes with the old assemblies, but fails with the new ones. I have to use DateTimeNoMsType as custom type now to get the old behaviour (thinking about using a convention to have it generally handled):

Map(x => x.TimeStamp).Column("TS").Nullable().CustomType<DateTimeNoMsType>();

My question: Am I right suggesting there was a change in the default handling of DateTime properties? I tried to look up the documentation / milestone descriptions of the various fluent nhibernate and nhibernate versions at GitHub, sadly, to no avail...


Solution

  • Found it, it is a breaking change from NHibernate 5.0.0.

    https://github.com/nhibernate/nhibernate-core/blob/5.1.5/releasenotes.txt

    • NHibernate type DateTimeType, which is the default for a .Net DateTime, does no longer cut fractional seconds. Use DateTimeNoMsType if you wish to have fractional seconds cut. It applies to its Local/Utc counterparts too.