Reputation: 65
We have a recordversion column (Something like 0x00000000006EC935) of type timestamp in SQL. Want to have it as a string in c# code. What is equivalent type? How to convert?
Upvotes: 4
Views: 3292
Reputation: 99
You can map Timestamp type in sql to Byte[] in .net.
you can convert string rowVersion to byte[] and vise versa like this:
// string rowVersion To Byte[]
byte[] byt = System.Text.Encoding.UTF8.GetBytes(strOriginal);
// Byte[] rowVersion to string
strModified = Convert.ToBase64String(byt);
Upvotes: 4
Reputation: 4421
There is none, timestamp in SQL server is a row version and has nothing to do with time. The closest you get to it is a byte[8] array
The problem is that you need to generate a unique number. You can create a threadsave counter that you increment and convert, however you could do that without bothering the to convert it to a byte array.
You can best leave it as a byte[]. the current framework & EF maintain it like this to track concurrency.
Upvotes: 0