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

MSSQL enum TimeSpan field

7 Answers 102 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.
aasda
Top achievements
Rank 1
aasda asked on 09 Jul 2011, 11:29 AM
Hi, i was trying out openaccess with a test project and came accross something which i cannot solve.
I created a EntityDiagram with domain model wizard and used attributemetadata from an existing DB.
I have a field in table order which is float in Db but must be TimeSpan in clr.private int? _orderKind;
private double? _orderTime; [Column("OrderTime", OpenAccessType = OpenAccessType.Double, IsNullable = true, SqlType = "float")] [Storage("_orderTime")] public virtual double? OrderTime     get    {        return this._orderTime;    }    set    {        this._orderTime = value;    } }
and a column which is int in Db but must be enum in clr
private int? _orderKind;
[Column("OrderKind", OpenAccessType = OpenAccessType.Int32, IsNullable = true, SqlType = "int")]
[Storage("_orderKind")]
public virtual int? OrderKind 

   get
   {
       return this._orderKind;
   }
   set
   {
       this._orderKind = value;
   }
}
I tried to change the types from double->TimeSpan, int->enum  but then i get exception about some DoubleConverter.
I searched the help files forums but could not find anything that would help me.
Could you please guide me on how to map an int column to enum, and if possible double to TimeSpan (TimeSpan.FromSeconds() but works with attribute or something).
Or show me a way to map int to enums.
Thank you

7 Answers, 1 is accepted

Sort by
0
Damyan Bogoev
Telerik team
answered on 13 Jul 2011, 03:55 PM
Hello Aasda,

1. We will prepare a custom converter that will handle this scenario, to convert values between TimeSpan and Float. Once we implement it, we will provide it to you.
2. You could set the property’s type by doing the following steps:
- Select the property from the visual designer;
- Open the Properties Windows grid;
- Set the Type option to YourEnumType;
- Save the diagram;
Hope that helps.

Best wishes,
Damyan Bogoev
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
aasda
Top achievements
Rank 1
answered on 14 Jul 2011, 09:08 AM
thank you for your response.
I tried changing type in Visual designer but it did not work because my field is nullable. However if i do change my field to be not nullable, then it works with enum values. Just to let you know that it does not work when i have an(nullable) enumVlue? type.
I am waiting for that custom converter (float 2 Timespan), and thank you for your quick response.
0
Damyan Bogoev
Telerik team
answered on 14 Jul 2011, 02:17 PM
Hello Aasda,

I prepared a custom converter to convert values between TimeSpan and Float. You could find a sample application attached that demonstrates how to use the custom converter and handle the problem with nullable integer values mapped to an enumeration type that you face.
Hope that helps.

Greetings,
Damyan Bogoev
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
Christophla
Top achievements
Rank 1
answered on 12 Feb 2012, 01:11 AM
SQL 2008 supports a new datatype called 'time' which maps to a CLR TimeSpan. Do you have any plans to implement this in the future?
0
Ady
Telerik team
answered on 15 Feb 2012, 05:16 PM
Hello Christopher,

 Yes, it is definitely on our plans to support the 'TimeSpan' CLR type but I cannot provide you with an exact timeframe at the moment. Currently the 'time' column is default mapped to a DateTime CLR type.

Regards,
Ady
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
Bernd
Top achievements
Rank 2
answered on 17 Oct 2013, 09:23 AM
Hello.

Is this still the best practice to represent a time or timespan?

DateTime is bound to a specific date. I would need a neutral time of a weekday or day. Kind of default values for the scheduler.

Kind regards
Bernd
0
Ady
Telerik team
answered on 21 Oct 2013, 10:22 AM
Hi Bernd,

 Yes, you can represent the time value as a TimeSpan and would additionally need to store the day of the week as an enum (or string). You can map the the time value to a CLR TimeSpan value.


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 >>
Tags
Databases and Data Types
Asked by
aasda
Top achievements
Rank 1
Answers by
Damyan Bogoev
Telerik team
aasda
Top achievements
Rank 1
Christophla
Top achievements
Rank 1
Ady
Telerik team
Bernd
Top achievements
Rank 2
Share this question
or