NHibernate cannot handle SQL Server TIME columns when built with the .NET 4 framework
Description
Environment
Attachments
is related to
Activity

Fabio Maulo July 30, 2011 at 2:11 PM
Closed after final release of NH3.2.0GA

Fabio Maulo April 25, 2011 at 5:12 AM
Implementing a new Drive for MsSQL2008

Fabio Maulo April 22, 2011 at 2:36 PM
Sorry I mean "we can't change".
To work with pure Time we have TimeAsTimeSpan.
I'll try to find a solution without break everything for those ppl using TimeType

Fabio Maulo April 22, 2011 at 2:20 PM
Neal, you can't change the TimeType that way because not all RDBMS may accepts a TimeSpan in the value of a parameter of DbType.Time.
In practice what you are looking for is something that use a DateTime in the domain and a TimeSpan for the DB.

Neal Groothuis April 21, 2011 at 7:43 AM
The exact code that I added to NHibernate.Driver.SqlClientDriver is:
protected override void InitializeParameter(IDbDataParameter
dbParam, string name, SqlType sqlType)
{
base.InitializeParameter(dbParam, name, sqlType);
if (sqlType.DbType == DbType.Time)
((SqlParameter) dbParam).SqlDbType = SqlDbType.Time;
}
I verified that the unit test passes after I made this change (and updated the type of the "Data" property to reference my included custom TimeType).
Details
Details
Assignee
Reporter

In .NET 4, setting a SqlParameter's DbType to Time does not work; it will be set to DateTime instead. (http://msdn.microsoft.com/en-us/library/system.data.dbtype%28v=VS.100%29.aspx , c.f. http://msdn.microsoft.com/en-us/library/system.data.dbtype%28v=VS.90%29.aspx ). To set a SqlParameter's DbType to Time, you actually have to set the SqlDbType property to SqlDbType.Time.
Unfortunately, this renders NHibernate unable to access TIME columns in the database if being used in .NET 4.0.