Improve type autodiscovery for datetime2 column in CreateSQLQuery() (CustomLoader)

Description

When reading a value from a "datetime2" column via Session.CreateSQLQuery() the milliseconds are lost.
Same query using "Session.Query<T>()" 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.

Environment

None

Activity

Show:

Frédéric Delaporte July 20, 2018 at 12:18 PM

Moved here.

In NHibernate 5.0 (), the default DateTime type does no more cut fractional seconds. Moreover, with SQL Server 2008 dialect and later, the default DbType used for DateTime is DateTime2.

Alex Zaytsev April 20, 2017 at 10:43 PM

Moving to improvement.

Alex Zaytsev April 20, 2017 at 10:38 PM

Here is a simple workaround:

Obsolete

Details

Assignee

Reporter

Components

Affects versions

Priority

Who's Looking?

Open Who's Looking?
Created April 13, 2017 at 8:38 AM
Updated July 20, 2018 at 12:18 PM
Resolved July 20, 2018 at 12:18 PM
Who's Looking?