Have you ever noticed that out of the box NHibernate’s DateTime type will truncate/ignore your milliseconds for DateTime fields? If you do not believe me check out this post. If you think about why it does this it will become clear, NHibernate runs against MANY databases and each one of them stores DateTime values slightly different. However all of them store basic YYYY-MM-DD : HH:MM:SS.
If you google how to resolve this issue you will find a few a post that suggests you create a custom User Type (IUserType). Although I am sure this will work, this just seems like such overkill for the problem.
What I was able to do was setup my mapping in FluentNHibernate as such
Map( x => x.MyField, "My_Field" ).CustomTypeIs("timestamp");
By adding the .CustomTypeIs attribute (i tried CustomSqlTypeIs but this did not work) NHibernate was able to save my DateTime property into a DateTime (not Timestamp or DateTime2) field with the milliseconds inplace.
Hope this helps,
Till next time,
02-22-2010 4:47 PM