Timespan not storing correctly?

Apr 19, 2011 at 6:15 AM

First thanks for the DB-- makes it really easy to use.

I'm not sure if this is a bug, but is anyone able to store timespans in the database?  When i do it they all seem to be reset to 0 for all values no matter what.  I've got no issues if I store everything as doubles/strings/ints ect, but if i try to store anything as a timespan it doesn't work.

 

Thanks!

-Zach

Apr 20, 2011 at 1:57 AM

This is a know issue with Xml Serializer which is used under the covers in the database project. You have to use different type to maintain your time span data. In my project I have published on the app marketplace, I use double and store total milliseconds of the time span object. Here is some sample code for you. You can always just not use time span at all. I added it to show how to use XmlIgnore attribute to keep properties from being stored.

 

public class History : BaseDataItem 
    {

 

 

        [XmlIgnore]

        public TimeSpan TotalTime

        {

            get { return TimeSpan.FromMilliseconds(TotalTimeInMilliseconds); }

        }

 

        double totalTimeInMilliseconds;

        public double TotalTimeInMilliseconds

        {

            get { return totalTimeInMilliseconds; }

            set { totalTimeInMilliseconds = value; OnPropertyChanged("TotalTimeInMilliseconds"); }

        }

 

history.TotalTimeInMilliseconds = totalTime.Value.TotalMilliseconds;

 

Thanks

Sergey