Changing Timestamp Column from Read-Only

Posts   
 
    
alexk
User
Posts: 19
Joined: 14-Sep-2005
# Posted on: 02-Nov-2005 21:30:38   

In the designer, my Sql Server 2000 timestamp column has "Is readonly" checked. I can't uncheck this because it is disabled. I need to be able to set the value to a previously saved value. The context is a webpage where the entire read entity is not persisted to viewstate, but its current timestamp value. Later, the entity is reconstructed and the timestamp property needs to be set to the saved value. Is there a way in the designer to undo the read-only?

Thanks!

bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 03-Nov-2005 02:29:33   

I don't believe you can set a timestamp value. What you may want to do is set the column to be a datetime. If you would like the value to record a time if you perform an insert and don't define a value then give it a default value of getdate().

alexk
User
Posts: 19
Joined: 14-Sep-2005
# Posted on: 03-Nov-2005 03:05:23   

You are right that a timestamp column cannot be updated. I just needed to update the entity property because my implementation of IConcurrencyPredicateFactory uses it. I didn't want to actually update that database column. I guess I'll use the "updateRestriction" parameter of SaveEntity() instead. That's clearer anyway.

Thanks for your help.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39826
Joined: 17-Aug-2003
# Posted on: 03-Nov-2005 11:43:19   

alexk wrote:

You are right that a timestamp column cannot be updated. I just needed to update the entity property because my implementation of IConcurrencyPredicateFactory uses it. I didn't want to actually update that database column. I guess I'll use the "updateRestriction" parameter of SaveEntity() instead. That's clearer anyway.

Thanks for your help.

You shouldn't have to have to update the that field, as you'd create a predicate which compares the timestamp field with the timestamp field's DbValue: PredicateFactory.CompareValue(MyEntityFieldIndex.MyTimestampField, ComparisonOperator.Equal, entityPassedIn.Fields[(int)MyEntityFieldIndex.MyTimestampField].DbValue);

Frans Bouma | Lead developer LLBLGen Pro
alexk
User
Posts: 19
Joined: 14-Sep-2005
# Posted on: 03-Nov-2005 17:28:41   

I only need to update the timestamp property with a previously saved value because the entity is being recreated. This is an edit type webform where the entity is read and its field values displayed in controls. After the end user updates the control values, the entity is recreated from those values before the save. e.g.,

SomeEntity entity = new SomeEntity(); entity.IsNew = false; entity.ConcurrencyPredicateFactoryToUse = TimestampPredicateFactory.Instance; entity.Timestamp = (byte[]) ViewState["Timestamp"]; entity.ObjectID = (int) ViewState["ObjectID"]; entity.Description = txtDesc.Text; entity.IsActive = chkActive.Checked; ...

Of course, the entire entity object and not just a few properties could've been saved in ViewState or wherever, but that would've taken much more space.

To solve this, the Timestamp property would have to be not read-only and also not be included in insert & updates statements. No big deal, I'll just use the SaveEntity overload instead.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39826
Joined: 17-Aug-2003
# Posted on: 03-Nov-2005 18:44:06   

do: entity.Fields["Timestamp"].ForcedCurrentValueWrite((byte[]) ViewState["Timestamp"]);

Frans Bouma | Lead developer LLBLGen Pro