This is a migrated thread and some comments may be shown as answers.

Mapping sql Time type to TimeSpan

7 Answers 777 Views
Databases and Data Types
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Christian
Top achievements
Rank 1
Christian asked on 21 Oct 2013, 03:00 PM
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

7 Answers, 1 is accepted

Sort by
0
Chris
Top achievements
Rank 1
answered on 24 Oct 2013, 02:01 AM
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.
0
Accepted
Ady
Telerik team
answered on 24 Oct 2013, 10:28 AM
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 >>
0
Chris
Top achievements
Rank 1
answered on 24 Oct 2013, 02:37 PM
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.
0
Christian
Top achievements
Rank 1
answered on 25 Oct 2013, 01:37 PM
Thanks Ady, it worked! 
Do I have to change it every time I regenerate the Domain Model? 
0
Ady
Telerik team
answered on 30 Oct 2013, 02:05 PM
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!
0
Evo
Top achievements
Rank 1
answered on 08 Oct 2014, 11:32 PM
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.
0
Ady
Telerik team
answered on 10 Oct 2014, 10:31 AM
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.
 
Tags
Databases and Data Types
Asked by
Christian
Top achievements
Rank 1
Answers by
Chris
Top achievements
Rank 1
Ady
Telerik team
Christian
Top achievements
Rank 1
Evo
Top achievements
Rank 1
Share this question
or