Description
Ralf1108 created an issue — 13th April 2017, 8:38:36:
When reading a value from a "datetime2" column via Session.CreateSQLQuery() the milliseconds are lost.
Same query using "Session.Query()" works.Error cause:
In class "CustomLoader" method "GetHibernateType()":"GetFieldType()" returns for a "datetime2" column "Datetime" which resolves to the "DateTimeType" from NHibernate which cuts the milliseconds.
If we use "GetDataTypeName()" for getting column type we get "datetime2" which then resolves correctly to "DateTime2Type".
So I think using "GetFieldType()" should only be used as a fallback if resolving via "GetDataTypeName()" didn't return a result.
Ralf1108 added a comment — 13th April 2017, 8:47:23:
see testcase in
3fe7e43
Alexander Zaytsev added a comment — 20th April 2017, 22:38:52:
Here is a simple workaround:
session.CreateSQLQuery("SELECT CreatedAt FROM LogEntry") .AddScalar("CreatedAt", NHibernateUtil.DateTime2) // Specify the desired type for the column. .UniqueResult<DateTime>()
Alexander Zaytsev added a comment — 20th April 2017, 22:43:03:
Moving to improvement.