MSSQL enum TimeSpan field

8 posts, 0 answers
  1. aasda
    aasda avatar
    6 posts
    Member since:
    Aug 2008

    Posted 09 Jul 2011 Link to this post

    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
  2. Damyan Bogoev
    Admin
    Damyan Bogoev avatar
    581 posts

    Posted 13 Jul 2011 Link to this post

    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!

  3. DevCraft banner
  4. aasda
    aasda avatar
    6 posts
    Member since:
    Aug 2008

    Posted 14 Jul 2011 Link to this post

    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.
  5. Damyan Bogoev
    Admin
    Damyan Bogoev avatar
    581 posts

    Posted 14 Jul 2011 Link to this post

    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!

  6. Christophla
    Christophla avatar
    28 posts
    Member since:
    Jul 2012

    Posted 11 Feb 2012 Link to this post

    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?
  7. Ady
    Admin
    Ady avatar
    589 posts

    Posted 15 Feb 2012 Link to this post

    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 >>
  8. Bernd
    Bernd avatar
    53 posts
    Member since:
    Feb 2013

    Posted 17 Oct 2013 Link to this post

    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
  9. Ady
    Admin
    Ady avatar
    589 posts

    Posted 21 Oct 2013 Link to this post

    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 >>
Back to Top
DevCraft banner