Handling TimeStamp Columns in SL

Handling TimeStamp Columns in SL

Old forum URL: forums.lhotka.net/forums/t/8714.aspx


Jav posted on Wednesday, March 24, 2010

I have tried :

        private static PropertyInfo<byte[]> lastmodifProperty = RegisterProperty<byte[]>(c => c.lastmodif);
        public byte[] lastmodif
        {
            get { return GetProperty(lastmodifProperty); }
            set { SetProperty(lastmodifProperty, value); }
        }


and in Fetch method:

LoadProperty(lastmodifProperty, dr.GetBytes("lastmodif", 0, lastmodif, 0, 8));

This  causes the following error on execution:

{"Invalid cast from 'System.Int64' to 'System.Byte[]'."} System.InvalidCastException

If I declare the TimeStamp property Int64, I get the opposite error.

I can do this:

        private byte[] _lastmodif = new byteMusic { 0, 0, 0, 0, 0, 0, 0, 0 };
        public byte[] Lastmodif
        {
            get { return _lastmodif; }
        }

And this
       dr.GetBytes("lastmodif", 0, _lastmodif, 0, 8);
But then the _lastmodif never makes it back to the DB in the Save operation because it is not serialized, I suppose - and hence nothing gets updated.

Would appreciate a hint or two.

Jav

Jav replied on Wednesday, March 24, 2010

Okay.  I can't say that this is the best or the only way to do it, but this will work: (dr is the SafeDataReader)

byte[] _lastmodif = new byteMusic { 0, 0, 0, 0, 0, 0, 0, 0 };
dr.GetBytes("lastmodif", 0, _lastmodif, 0, 8);
LoadProperty(lastmodifProperty, _lastmodif);

Jav

xAvailx replied on Wednesday, March 24, 2010

FYI, you can declare byte = new byteMusic; may make it easier than keep count of the number of 0's

Russ replied on Thursday, March 25, 2010

I have found it easier to initialize the byte array by setting the default value when registering the property.

private static PropertyInfo<byte[]> TimeStampProperty = RegisterProperty<byte[]>(c => c.TimeStamp, "TimeStamp", new byteMusic);
public byte[] TimeStamp
{
   get { return GetProperty(TimeStampProperty); }
   private set { SetProperty(TimeStampProperty, value); }
}

Jav replied on Thursday, March 25, 2010

Thank you xAvailx and Russ for your suggestions.

Jav

Copyright (c) Marimer LLC