Melinda Gates
Melinda Gates

Reputation: 21

Why are these Binary/RowVersion not match?

I have a table like

                Thingy 
=======================================
| ... |        RowVersion     | ... |
=======================================

and another like

                Result 
=======================================
| ... |     ThingyRowVersion     | ... |
=======================================

In SQL Server the columns are of type timestamp and in C# they are of type Binary. What I'm seeing is a problem when I try to create a result with the same row version as a thingy, like

Result r = new Result()
{
    ThingyRowVersion = (from t in Context.Thingies where t.Id == id select t.RowVersion).Single()
}  
Context.InsertOnSubmit(r);
Context.SubmitChanges();

the row versions will not be equal right after the changes are submitted.

In C# land they appear to be equal right before I submit, but when I submit I see a mismatch like

0x0000000000002787 / 0x0000000000002782

Any idea what's going on here?

Upvotes: 0

Views: 106

Answers (1)

Fabulous
Fabulous

Reputation: 2423

A timestamp is automatically updated whenever a row is inserted or changed and isn't normally manipulated by the user. The most common operation with them is to use as a check when using optimistic concurrency to see if the row has been updated since the last time you read it. You may want to use something else like UniqueIdentifier to do what you want.

Upvotes: 1

Related Questions