Replies: 1 comment 2 replies
-
You're handling it correctly in that you treat it as a byte array. But its not a value you'd ever show to the user. What you normally do is when you fetch an existing record you put it in your BO, then in your data portal update you do the normal update SQL, but you add WHERE TimeStamp = @timestamp. If the records current Timestamp value is different than yours, you (purposefully) don't update the record, because someone else already has and you let the user know they have stale data. If your update is successful though, you read the records new value and put that back into your BO. The SQL timestamp is for collision detection, not a last changed date. sorry if that is already your understanding of things, I just thought it odd to have it displayed to the user and labled "Last Changed" |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
I'm using a sql timestamp field to control concurrency. I don't think I'm handling correctly on the c# side. Could someone take a peak at code below and verify it's correct. Thank You!
I'm using this to load it via a DataReader
LoadProperty(LastChangedProperty, dr.GetValue("LastChanged") as Byte[]);
and this to pass it back to sql.
cmd.Parameters.AddWithValue("@LastChanged", ReadProperty(LastChangedProperty)).DbType = DbType.Binary;
cmd.Parameters.AddWithValue("@LastChanged", SqlDbType.Timestamp).Direction = ParameterDirection.InputOutput;
and finally this to read the return value on an update.
LoadProperty(LastChangedProperty, cmd.Parameters["@LastChanged"].Value as Byte[]);
The property declaration is below just in case.
public static readonly PropertyInfo<Byte[]> LastChangedProperty = RegisterProperty<Byte[]>(p => p.LastChanged, "Last Changed");
[Display(Name = "Last Changed")]
public Byte[] LastChanged
{
get { return GetProperty(LastChangedProperty); }
set { SetProperty(LastChangedProperty,value); }
}
Beta Was this translation helpful? Give feedback.
All reactions