NHibernate
  1. NHibernate
  2. NH-2661

NHibernate cannot handle SQL Server TIME columns when built with the .NET 4 framework

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 3.1.0
    • Fix Version/s: 3.2.0.Alpha3
    • Component/s: Core
    • Labels:
      None

      Description

      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.

        Issue Links

          Activity

          Hide
          Neal Groothuis added a comment -

          Unit test illustrating the problem. This includes a custom TimeType which works around the problem in NH-2660.

          Show
          Neal Groothuis added a comment - Unit test illustrating the problem. This includes a custom TimeType which works around the problem in NH-2660 .
          Hide
          Neal Groothuis added a comment -

          I believe this can be fixed by having NHibernate.Driver.SqlClientDriver override InitializeParameter() and set the SqlDbType to Time if the DbType is Time.

          Show
          Neal Groothuis added a comment - I believe this can be fixed by having NHibernate.Driver.SqlClientDriver override InitializeParameter() and set the SqlDbType to Time if the DbType is Time.
          Hide
          Fabio Maulo added a comment -

          http://connect.microsoft.com/VisualStudio/feedback/details/381934/sqlparameter-dbtype-dbtype-time-sets-the-parameter-to-sqldbtype-datetime-instead-of-sqldbtype-time
          Microsoft said:
          "Thanks for reporting this issue. This is a bug in our product, but after carefully investigating the issue, we have decided not to fix the bug. Fixing this bug will cause a breaking change and in most of customer scenarios, they should be able to use SqlParameter.SqlDbType. Please let us know if this is a blocking issue for some of your major scenarios."

          Show
          Fabio Maulo added a comment - http://connect.microsoft.com/VisualStudio/feedback/details/381934/sqlparameter-dbtype-dbtype-time-sets-the-parameter-to-sqldbtype-datetime-instead-of-sqldbtype-time Microsoft said: "Thanks for reporting this issue. This is a bug in our product, but after carefully investigating the issue, we have decided not to fix the bug. Fixing this bug will cause a breaking change and in most of customer scenarios, they should be able to use SqlParameter.SqlDbType. Please let us know if this is a blocking issue for some of your major scenarios."
          Hide
          Neal Groothuis added a comment -

          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).

          Show
          Neal Groothuis added a comment - 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).
          Hide
          Fabio Maulo added a comment -

          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.

          Show
          Fabio Maulo added a comment - 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.
          Hide
          Fabio Maulo added a comment -

          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

          Show
          Fabio Maulo added a comment - 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
          Hide
          Fabio Maulo added a comment -

          Implementing a new Drive for MsSQL2008

          Show
          Fabio Maulo added a comment - Implementing a new Drive for MsSQL2008
          Hide
          Fabio Maulo added a comment -

          Closed after final release of NH3.2.0GA

          Show
          Fabio Maulo added a comment - Closed after final release of NH3.2.0GA

            People

            • Assignee:
              Unassigned
              Reporter:
              Neal Groothuis
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Who's Looking?