Skip to content

SQL Server time data type is mapped to DateTime #516

@michal-duda

Description

@michal-duda

Description

I have a problem with SQL Server time type. SQLProvider is mapping this type to DateTime but per SQL Server Data Type Mappings it should be mapped to TimeSpan. When I try to select column of time type I get System.InvalidCastException.

System.InvalidCastException
HResult=0x80004002
Message=Object must implement IConvertible.
Source=mscorlib
StackTrace:
at System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider)
at System.Convert.ChangeType(Object value, Type conversionType)
at FSharp.Data.Sql.Common.SqlEntity.GetColumn[T](String key)
at XYZ.DataAccess.load@49.Invoke(SqlEntity trip)
at Microsoft.FSharp.Primitives.Basics.List.map[T,TResult](FSharpFunc2 mapping, FSharpList1 x)
at Microsoft.FSharp.Collections.ListModule.Map[T,TResult](FSharpFunc2 mapping, FSharpList1 list)

Repro steps

  1. Create table with column of time type
  2. Try to load data of this column with SQLProvider -> System.InvalidCastException

Known workarounds

I have forked repo and changed type for time to TimeSpan and everything works fine. Change is visible here.

getDbType:

        if providerType = 31
        then p.SqlDbType <- SqlDbType.DateTime
        else if providerType = 32
        then p.SqlDbType <- SqlDbType.Time

mappings:

        else if oleDbType = "time"
        then  typeof<TimeSpan>.ToString()

I can create PR for this but I don't know if this is general solution for all SQL server versions.

Related information

I am using Microsoft SQL Azure (RTM) - 12.0.2000.8

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions