Uploaded image for project: 'NHibernate'
  1. NHibernate
  2. NH-2661

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

    Details

    • Type: Bug
    • Status: Closed
    • Priority: 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.

        Gliffy Diagrams

          Issue Links

            Activity

            Hide
            ngroot Neal Groothuis added a comment -

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

            Show
            ngroot Neal Groothuis added a comment - Unit test illustrating the problem. This includes a custom TimeType which works around the problem in NH-2660 .
            Hide
            ngroot 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
            ngroot 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
            fabiomaulo 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
            fabiomaulo 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
            ngroot 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
            ngroot 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
            fabiomaulo 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
            fabiomaulo 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
            fabiomaulo 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
            fabiomaulo 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
            fabiomaulo Fabio Maulo added a comment -

            Implementing a new Drive for MsSQL2008

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

            Closed after final release of NH3.2.0GA

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

              People

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

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Who's Looking?