Mapping Existing Code Functionality to a Database Approach

3 posts, 0 answers
  1. Mike
    Mike avatar
    28 posts
    Member since:
    Apr 2013

    Posted 02 May 2014 Link to this post

    Hi

    I have an existing project that I am trying to convert to a database (SQLite). I'm struggling conceptually on how I would approach a particular configuration I have currently. 
    When I read the data from the current source (serial data) I perform a conversion on some elements based on the configuration of the app. In this instance I'm reading speed as meters/sec and do a conversion in the class. This is the code I have currently:
                public float telSpeed
                {
                    //value in m/s
                    get { return telspeed; } 
                    set
                    {
                        if (telspeed == value) 
                            return; 
                        
                        telSpeedAdjusted = value;
                        SetProperty(ref telspeed, value);
                    }
                }

                public float telSpeedAdjusted
                {
                    get { return telspeedadjusted; }
                    set
                    {
                        if (telspeedadjusted == value)
                            return;

                        switch (SPEED_DISPLAY)
                        {
                            case eSpeedDisplay.Speed_MPH:
                                value = (float)(Math.Round(value * 2.24, 0)); //convert to MPH
                                break;
                            case eSpeedDisplay.Speed_KPH:
                                value = (float)(Math.Round(value * 3.6, 0)); //convert to KPH
                                break;
                            case eSpeedDisplay.Speed_MPS:
                                //don't convert from m/s this is what the data is in
                                break;

                            default:
                                break;
                        }

                        SetProperty(ref telspeedadjusted, value);
                    }
                }

    In my WPF I bind to the telSpeedAdjusted property. If I convert this class over to a SQLite DB and get autogenerated properties, how can I perform the same conversion? 
    I appreciate it could be done as a valueconverter, but I don't really want to do this. There are other properties that are referenced in the WPF multiple times and it does impact performance. I'm not that experienced with C# and even less with database design and am really struggling conceptually to figure a way around this.

    Can anyone assist a flailing noob?

  2. Jan Blessenohl
    Admin
    Jan Blessenohl avatar
    707 posts

    Posted 05 May 2014 Link to this post

    Hi Mike,

    I would use the Telerik Data Access fluent mapping approach as described here. You can either reuse your existing classes and just add the mapping or you define a new set of classes with a copy ctor.


    Regards,
    Jan Blessenohl
    Telerik
     
    OpenAccess ORM is now Telerik Data Access. For more information on the new names, please, check out the Telerik Product Map.
     
  3. DevCraft banner
  4. Mike
    Mike avatar
    28 posts
    Member since:
    Apr 2013

    Posted 07 May 2014 in reply to Jan Blessenohl Link to this post

    Thanks, I'll have a dig into the Fluent stuff over the weekend...
Back to Top