Mapping sql Time type to TimeSpan

8 posts, 1 answers
  1. Christian
    Christian avatar
    2 posts
    Member since:
    Dec 2012

    Posted 21 Oct 2013 Link to this post

    I'm working with Time type in SQL Server, and when I map this field to OpenAccess it creates a DateTime field. Is there any way to map this as TimeSpan?
    Thanks
  2. Chris
    Chris avatar
    13 posts
    Member since:
    Oct 2010

    Posted 23 Oct 2013 Link to this post

    I'm having the same issue. Using MySQL's time data type gets interpreted as DateTime. I can manually change the generated code to be c# TimeSpan type but anytime I change the rlinq map it gets overwritten.
  3. DevCraft banner
  4. Answer
    Ady
    Admin
    Ady avatar
    588 posts

    Posted 24 Oct 2013 Link to this post

    Hi Christian,

     After generating the domain model from the database you can select the particular property in the designer and change the CLR type of this property to 'TimeSpan' in the properties window. 'TimeSpan' is not listed there but you can just type it in.
    Querying for data should then give you TimeSpan values.

    @Chris - You should change the CLR type in the designer and save the rlinq file. This will generate the right CLR type in the code. Do not change the generated code directly because this is always regenerated everytime you save the rlinq file.

    Regards,
    Ady
    Telerik
    OpenAccess ORM Q3 2013 Beta is available for immediate download in your account. Get it now and play with the latest bits. See what's new >>
  5. Chris
    Chris avatar
    13 posts
    Member since:
    Oct 2010

    Posted 24 Oct 2013 Link to this post

    Thanks Ady! That worked. It wasn't one of the options in the drop down but I see now you can free type your CLR data type. Great stuff.
  6. Christian
    Christian avatar
    2 posts
    Member since:
    Dec 2012

    Posted 25 Oct 2013 Link to this post

    Thanks Ady, it worked! 
    Do I have to change it every time I regenerate the Domain Model? 
  7. Ady
    Admin
    Ady avatar
    588 posts

    Posted 30 Oct 2013 Link to this post

    Hi Christian,

     Glad to know that it works for you. 
    No, you do not need to set it every time. Its like any other property - you need to set it only once.

    Regards,
    Ady
    Telerik
    OpenAccess ORM Q3 2013 simplifies your model operations even further providing you with greater flexibility. Check out the list of new features shipped with our latest release!
  8. Evo
    Evo avatar
    2 posts
    Member since:
    Feb 2014

    Posted 08 Oct 2014 in reply to Ady Link to this post

    Hi Ady,

    I'm having troubles when SaveChanges is called with TimeSpan (the field is mapped in the database as Time)

    Additional information: Insert of 'xxxx-' failed: Telerik.OpenAccess.RT.sql.SQLException: Operand type clash: int is incompatible with time
    Statement(s) could not be prepared. ---> System.Data.SqlClient.SqlException: Operand type clash: int is incompatible with time

    Is there something I'm not mapping correctly?

    Thanks in advance.
  9. Ady
    Admin
    Ady avatar
    588 posts

    Posted 10 Oct 2014 Link to this post

    Hi Evaristo,

    I was able to reproduce the error and have created a bug entry for the same. Unfortunately there is no workaround for this problem.

    You can use the 'System.DateTime' as the CLR type for a 'time' column or map the 'TimeSpan' field to a 'datetime' column.

    Regards,
    Ady
    Telerik
     
    OpenAccess ORM is now Telerik Data Access. For more information on the new names, please, check out the Telerik Product Map.
     
Back to Top
DevCraft banner